TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
SchemaColumnDefinitionListenerTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types=1);
3 
4 namespace TYPO3\CMS\Core\Tests\Unit\Database;
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 
19 use Doctrine\DBAL\Event\SchemaColumnDefinitionEventArgs;
20 use Doctrine\DBAL\Platforms\AbstractPlatform;
21 use Doctrine\DBAL\Schema\Column;
22 use Doctrine\DBAL\Types\Type;
23 use Prophecy\Prophecy\ObjectProphecy;
30 
35 {
39  protected $subject;
40 
44  protected $connectionProphet;
45 
49  protected function setUp()
50  {
51  parent::setUp();
52  $this->subject = GeneralUtility::makeInstance(SchemaColumnDefinitionListener::class);
53  $this->connectionProphet = $this->prophesize(Connection::class);
54  }
55 
60  {
61  $event = new SchemaColumnDefinitionEventArgs(
62  ['Type' => 'int(11)'],
63  'aTestTable',
64  'aTestDatabase',
65  $this->connectionProphet->reveal()
66  );
67 
68  $this->subject->onSchemaColumnDefinition($event);
69  $this->assertNotTrue($event->isDefaultPrevented());
70  $this->assertNull($event->getColumn());
71  }
72 
76  public function buildsColumnForEnumDataType()
77  {
78  if (Type::hasType('enum')) {
79  Type::overrideType('enum', EnumType::class);
80  } else {
81  Type::addType('enum', EnumType::class);
82  }
83  $databasePlatformProphet = $this->prophesize(AbstractPlatform::class);
84  $databasePlatformProphet->getDoctrineTypeMapping('enum')->willReturn('enum');
85  $this->connectionProphet->getDatabasePlatform()->willReturn($databasePlatformProphet->reveal());
86 
87  $event = new SchemaColumnDefinitionEventArgs(
88  ['Type' => "enum('value1', 'value2','value3')"],
89  'aTestTable',
90  'aTestDatabase',
91  $this->connectionProphet->reveal()
92  );
93 
94  $this->subject->onSchemaColumnDefinition($event);
95  $this->assertTrue($event->isDefaultPrevented());
96  $this->assertInstanceOf(Column::class, $event->getColumn());
97  $this->assertInstanceOf(EnumType::class, $event->getColumn()->getType());
98  $this->assertSame(['value1', 'value2', 'value3'], $event->getColumn()->getPlatformOption('unquotedValues'));
99  }
100 
104  public function buildsColumnForSetDataType()
105  {
106  if (Type::hasType('set')) {
107  Type::overrideType('set', SetType::class);
108  } else {
109  Type::addType('set', SetType::class);
110  }
111  $databasePlatformProphet = $this->prophesize(AbstractPlatform::class);
112  $databasePlatformProphet->getDoctrineTypeMapping('set')->willReturn('set');
113  $this->connectionProphet->getDatabasePlatform()->willReturn($databasePlatformProphet->reveal());
114 
115  $event = new SchemaColumnDefinitionEventArgs(
116  ['Type' => "set('value1', 'value3')"],
117  'aTestTable',
118  'aTestDatabase',
119  $this->connectionProphet->reveal()
120  );
121 
122  $this->subject->onSchemaColumnDefinition($event);
123  $this->assertTrue($event->isDefaultPrevented());
124  $this->assertInstanceOf(Column::class, $event->getColumn());
125  $this->assertInstanceOf(SetType::class, $event->getColumn()->getType());
126  $this->assertSame(['value1', 'value3'], $event->getColumn()->getPlatformOption('unquotedValues'));
127  }
128 }
static makeInstance($className,...$constructorArguments)