TYPO3 CMS  TYPO3_8-7
SchemaColumnDefinitionListenerTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 /*
7  * This file is part of the TYPO3 CMS project.
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
29 
33 class SchemaColumnDefinitionListenerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
34 {
38  protected $subject;
39 
43  protected $connectionProphet;
44 
48  protected function setUp()
49  {
50  parent::setUp();
51  $this->subject = GeneralUtility::makeInstance(SchemaColumnDefinitionListener::class);
52  $this->connectionProphet = $this->prophesize(Connection::class);
53  }
54 
59  {
60  $event = new SchemaColumnDefinitionEventArgs(
61  ['Type' => 'int(11)'],
62  'aTestTable',
63  'aTestDatabase',
64  $this->connectionProphet->reveal()
65  );
66 
67  $this->subject->onSchemaColumnDefinition($event);
68  $this->assertNotTrue($event->isDefaultPrevented());
69  $this->assertNull($event->getColumn());
70  }
71 
75  public function buildsColumnForEnumDataType()
76  {
77  if (Type::hasType('enum')) {
78  Type::overrideType('enum', EnumType::class);
79  } else {
80  Type::addType('enum', EnumType::class);
81  }
82  $databasePlatformProphet = $this->prophesize(AbstractPlatform::class);
83  $databasePlatformProphet->getDoctrineTypeMapping('enum')->willReturn('enum');
84  $this->connectionProphet->getDatabasePlatform()->willReturn($databasePlatformProphet->reveal());
85 
86  $event = new SchemaColumnDefinitionEventArgs(
87  ['Type' => "enum('value1', 'value2','value3')"],
88  'aTestTable',
89  'aTestDatabase',
90  $this->connectionProphet->reveal()
91  );
92 
93  $this->subject->onSchemaColumnDefinition($event);
94  $this->assertTrue($event->isDefaultPrevented());
95  $this->assertInstanceOf(Column::class, $event->getColumn());
96  $this->assertInstanceOf(EnumType::class, $event->getColumn()->getType());
97  $this->assertSame(['value1', 'value2', 'value3'], $event->getColumn()->getPlatformOption('unquotedValues'));
98  }
99 
103  public function buildsColumnForSetDataType()
104  {
105  if (Type::hasType('set')) {
106  Type::overrideType('set', SetType::class);
107  } else {
108  Type::addType('set', SetType::class);
109  }
110  $databasePlatformProphet = $this->prophesize(AbstractPlatform::class);
111  $databasePlatformProphet->getDoctrineTypeMapping('set')->willReturn('set');
112  $this->connectionProphet->getDatabasePlatform()->willReturn($databasePlatformProphet->reveal());
113 
114  $event = new SchemaColumnDefinitionEventArgs(
115  ['Type' => "set('value1', 'value3')"],
116  'aTestTable',
117  'aTestDatabase',
118  $this->connectionProphet->reveal()
119  );
120 
121  $this->subject->onSchemaColumnDefinition($event);
122  $this->assertTrue($event->isDefaultPrevented());
123  $this->assertInstanceOf(Column::class, $event->getColumn());
124  $this->assertInstanceOf(SetType::class, $event->getColumn()->getType());
125  $this->assertSame(['value1', 'value3'], $event->getColumn()->getPlatformOption('unquotedValues'));
126  }
127 }
static makeInstance($className,... $constructorArguments)