‪TYPO3CMS  11.5
SchemaColumnDefinitionListenerTest.php
Go to the documentation of this file.
1 <?php
2 
3 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 
19 
20 use Doctrine\DBAL\Event\SchemaColumnDefinitionEventArgs;
21 use Doctrine\DBAL\Platforms\AbstractPlatform;
22 use Doctrine\DBAL\Schema\Column;
23 use Doctrine\DBAL\Types\Type;
24 use Prophecy\PhpUnit\ProphecyTrait;
25 use Prophecy\Prophecy\ObjectProphecy;
31 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
32 
36 class ‪SchemaColumnDefinitionListenerTest extends UnitTestCase
37 {
38  use ProphecyTrait;
39 
43  protected ‪$subject;
44 
46  protected ObjectProphecy ‪$connectionProphecy;
47 
51  protected function ‪setUp(): void
52  {
53  parent::setUp();
54  $this->subject = GeneralUtility::makeInstance(SchemaColumnDefinitionListener::class);
55  $this->connectionProphecy = $this->prophesize(Connection::class);
56  }
57 
61  public function ‪isInactiveForStandardColumnTypes(): void
62  {
63  $event = new SchemaColumnDefinitionEventArgs(
64  ['Type' => 'int(11)'],
65  'aTestTable',
66  'aTestDatabase',
67  $this->connectionProphecy->reveal()
68  );
69 
70  $this->subject->onSchemaColumnDefinition($event);
71  self::assertNotTrue($event->isDefaultPrevented());
72  self::assertNull($event->getColumn());
73  }
74 
78  public function ‪buildsColumnForEnumDataType(): void
79  {
80  if (Type::hasType('enum')) {
81  Type::overrideType('enum', EnumType::class);
82  } else {
83  Type::addType('enum', EnumType::class);
84  }
85  $databasePlatformProphet = $this->prophesize(AbstractPlatform::class);
86  $databasePlatformProphet->getDoctrineTypeMapping('enum')->willReturn('enum');
87  $this->connectionProphecy->getDatabasePlatform()->willReturn($databasePlatformProphet->reveal());
88 
89  $event = new SchemaColumnDefinitionEventArgs(
90  ['Type' => "enum('value1', 'value2','value3')"],
91  'aTestTable',
92  'aTestDatabase',
93  $this->connectionProphecy->reveal()
94  );
95 
96  $this->subject->onSchemaColumnDefinition($event);
97  self::assertTrue($event->isDefaultPrevented());
98  self::assertInstanceOf(Column::class, $event->getColumn());
99  self::assertInstanceOf(EnumType::class, $event->getColumn()->getType());
100  self::assertSame(['value1', 'value2', 'value3'], $event->getColumn()->getPlatformOption('unquotedValues'));
101  }
102 
106  public function ‪buildsColumnForSetDataType(): void
107  {
108  if (Type::hasType('set')) {
109  Type::overrideType('set', SetType::class);
110  } else {
111  Type::addType('set', SetType::class);
112  }
113  $databasePlatformProphet = $this->prophesize(AbstractPlatform::class);
114  $databasePlatformProphet->getDoctrineTypeMapping('set')->willReturn('set');
115  $this->connectionProphecy->getDatabasePlatform()->willReturn($databasePlatformProphet->reveal());
116 
117  $event = new SchemaColumnDefinitionEventArgs(
118  ['Type' => "set('value1', 'value3')"],
119  'aTestTable',
120  'aTestDatabase',
121  $this->connectionProphecy->reveal()
122  );
123 
124  $this->subject->onSchemaColumnDefinition($event);
125  self::assertTrue($event->isDefaultPrevented());
126  self::assertInstanceOf(Column::class, $event->getColumn());
127  self::assertInstanceOf(SetType::class, $event->getColumn()->getType());
128  self::assertSame(['value1', 'value3'], $event->getColumn()->getPlatformOption('unquotedValues'));
129  }
130 }
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\EventListener
Definition: SchemaColumnDefinitionListenerTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\EventListener\SchemaColumnDefinitionListenerTest\setUp
‪setUp()
Definition: SchemaColumnDefinitionListenerTest.php:49
‪TYPO3\CMS\Core\Database\Schema\Types\SetType
Definition: SetType.php:27
‪TYPO3\CMS\Core\Database\Schema\Types\EnumType
Definition: EnumType.php:27
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\EventListener\SchemaColumnDefinitionListenerTest\buildsColumnForSetDataType
‪buildsColumnForSetDataType()
Definition: SchemaColumnDefinitionListenerTest.php:104
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\EventListener\SchemaColumnDefinitionListenerTest\$connectionProphecy
‪ObjectProphecy $connectionProphecy
Definition: SchemaColumnDefinitionListenerTest.php:44
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\EventListener\SchemaColumnDefinitionListenerTest
Definition: SchemaColumnDefinitionListenerTest.php:37
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\EventListener\SchemaColumnDefinitionListenerTest\isInactiveForStandardColumnTypes
‪isInactiveForStandardColumnTypes()
Definition: SchemaColumnDefinitionListenerTest.php:59
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\EventListener\SchemaColumnDefinitionListenerTest\buildsColumnForEnumDataType
‪buildsColumnForEnumDataType()
Definition: SchemaColumnDefinitionListenerTest.php:76
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:38
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\EventListener\SchemaColumnDefinitionListenerTest\$subject
‪SchemaColumnDefinitionListener $subject
Definition: SchemaColumnDefinitionListenerTest.php:41
‪TYPO3\CMS\Core\Database\Schema\EventListener\SchemaColumnDefinitionListener
Definition: SchemaColumnDefinitionListener.php:30