‪TYPO3CMS  ‪main
EnumTypeTest.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\Platforms\AbstractPlatform;
21 use Doctrine\DBAL\Types\Type;
22 use PHPUnit\Framework\Attributes\Test;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
26 final class ‪EnumTypeTest extends UnitTestCase
27 {
28  protected function ‪setUp(): void
29  {
30  parent::setUp();
31  if (!Type::hasType(‪EnumType::TYPE)) {
32  Type::addType(‪EnumType::TYPE, EnumType::class);
33  }
34  }
35 
36  #[Test]
37  public function ‪getSQLDeclaration(): void
38  {
39  $fieldDeclaration = [
40  'unquotedValues' => ['aValue', 'anotherValue'],
41  ];
42 
43  $databaseMock = $this->createMock(AbstractPlatform::class);
44  $databaseMock->method('quoteStringLiteral')->willReturnCallback(
45  static function (string $str): string {
46  return "'" . $str . "'";
47  }
48  );
49 
50  $subject = Type::getType(‪EnumType::TYPE);
51  self::assertSame(
52  "ENUM('aValue', 'anotherValue')",
53  $subject->getSQLDeclaration($fieldDeclaration, $databaseMock)
54  );
55  }
56 }
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Types\EnumTypeTest\setUp
‪setUp()
Definition: EnumTypeTest.php:28
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Types
Definition: EnumTypeTest.php:18
‪TYPO3\CMS\Core\Database\Schema\Types\EnumType
Definition: EnumType.php:29
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Types\EnumTypeTest
Definition: EnumTypeTest.php:27
‪TYPO3\CMS\Core\Database\Schema\Types\EnumType\TYPE
‪const TYPE
Definition: EnumType.php:30
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Types\EnumTypeTest\getSQLDeclaration
‪getSQLDeclaration()
Definition: EnumTypeTest.php:37