‪TYPO3CMS  ‪main
SetTypeTest.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 ‪SetTypeTest extends UnitTestCase
27 {
28  protected function ‪setUp(): void
29  {
30  parent::setUp();
31  if (!Type::hasType(‪SetType::TYPE)) {
32  Type::addType(‪SetType::TYPE, SetType::class);
33  }
34  }
35 
36  #[Test]
37  public function ‪getNameReturnsTypeIdentifier(): void
38  {
39  $subject = Type::getType(‪SetType::TYPE);
40  self::assertSame(‪SetType::TYPE, Type::getTypeRegistry()->lookupName($subject));
41  }
42 
43  #[Test]
44  public function ‪getSQLDeclaration(): void
45  {
46  $fieldDeclaration = [
47  'unquotedValues' => ['aValue', 'anotherValue'],
48  ];
49 
50  $databaseMock = $this->createMock(AbstractPlatform::class);
51  $databaseMock->method('quoteStringLiteral')->willReturnCallback(
52  static function (string $str): string {
53  return "'" . $str . "'";
54  }
55  );
56 
57  $subject = Type::getType(‪SetType::TYPE);
58  self::assertSame(
59  "SET('aValue', 'anotherValue')",
60  $subject->getSQLDeclaration($fieldDeclaration, $databaseMock)
61  );
62  }
63 }
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Types
Definition: EnumTypeTest.php:18
‪TYPO3\CMS\Core\Database\Schema\Types\SetType
Definition: SetType.php:29
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Types\SetTypeTest\getSQLDeclaration
‪getSQLDeclaration()
Definition: SetTypeTest.php:44
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Types\SetTypeTest\setUp
‪setUp()
Definition: SetTypeTest.php:28
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Types\SetTypeTest\getNameReturnsTypeIdentifier
‪getNameReturnsTypeIdentifier()
Definition: SetTypeTest.php:37
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Types\SetTypeTest
Definition: SetTypeTest.php:27
‪TYPO3\CMS\Core\Database\Schema\Types\SetType\TYPE
‪const TYPE
Definition: SetType.php:30