‪TYPO3CMS  9.5
SchemaColumnDefinitionListenerTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
18 use Doctrine\DBAL\Event\SchemaColumnDefinitionEventArgs;
19 use Doctrine\DBAL\Platforms\AbstractPlatform;
20 use Doctrine\DBAL\Schema\Column;
21 use Doctrine\DBAL\Types\Type;
22 use Prophecy\Prophecy\ObjectProphecy;
28 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
29 
33 class ‪SchemaColumnDefinitionListenerTest extends UnitTestCase
34 {
38  protected ‪$subject;
39 
43  protected ‪$connectionProphet;
44 
48  protected function ‪setUp(): void
49  {
50  parent::setUp();
51  $this->subject = GeneralUtility::makeInstance(SchemaColumnDefinitionListener::class);
52  $this->connectionProphet = $this->prophesize(Connection::class);
53  }
54 
58  public function ‪isInactiveForStandardColumnTypes(): void
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(): void
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(): void
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 }
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\EventListener
Definition: SchemaColumnDefinitionListenerTest.php:3
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\EventListener\SchemaColumnDefinitionListenerTest\setUp
‪setUp()
Definition: SchemaColumnDefinitionListenerTest.php:46
‪TYPO3\CMS\Core\Database\Schema\Types\SetType
Definition: SetType.php:25
‪TYPO3\CMS\Core\Database\Schema\Types\EnumType
Definition: EnumType.php:25
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\EventListener\SchemaColumnDefinitionListenerTest\buildsColumnForSetDataType
‪buildsColumnForSetDataType()
Definition: SchemaColumnDefinitionListenerTest.php:101
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\EventListener\SchemaColumnDefinitionListenerTest
Definition: SchemaColumnDefinitionListenerTest.php:34
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\EventListener\SchemaColumnDefinitionListenerTest\isInactiveForStandardColumnTypes
‪isInactiveForStandardColumnTypes()
Definition: SchemaColumnDefinitionListenerTest.php:56
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\EventListener\SchemaColumnDefinitionListenerTest\buildsColumnForEnumDataType
‪buildsColumnForEnumDataType()
Definition: SchemaColumnDefinitionListenerTest.php:73
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:31
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\EventListener\SchemaColumnDefinitionListenerTest\$subject
‪SchemaColumnDefinitionListener $subject
Definition: SchemaColumnDefinitionListenerTest.php:37
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\EventListener\SchemaColumnDefinitionListenerTest\$connectionProphet
‪Connection ObjectProphecy $connectionProphet
Definition: SchemaColumnDefinitionListenerTest.php:41
‪TYPO3\CMS\Core\Database\Schema\EventListener\SchemaColumnDefinitionListener
Definition: SchemaColumnDefinitionListener.php:29