[FEATURE] Doctrine: Implement SchemaMigrationService
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Database / Schema / Parser / DataTypes / CharDataTypeTest.php
1 <?php
2 declare(strict_types=1);
3
4 namespace TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\DataTypes;
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 TYPO3\CMS\Core\Database\Schema\Parser\AST\DataType\CharDataType;
20 use TYPO3\CMS\Core\Database\Schema\Parser\AST\DataType\VarCharDataType;
21 use TYPO3\CMS\Core\Database\Schema\Parser\Parser;
22 use TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\AbstractDataTypeBaseTestCase;
23
24 /**
25 * Tests for parsing CHAR/VARCHAR SQL data types
26 */
27 class CharDataTypeTest extends AbstractDataTypeBaseTestCase
28 {
29 /**
30 * Data provider for canParseBinaryDataType()
31 *
32 * @return array
33 */
34 public function canParseBinaryDataTypeProvider(): array
35 {
36 return [
37 'CHAR without length' => [
38 'CHAR',
39 CharDataType::class,
40 0,
41 ],
42 'CHAR with length' => [
43 'CHAR(200)',
44 CharDataType::class,
45 200,
46 ],
47 'VARCHAR with length' => [
48 'VARCHAR(200)',
49 VarCharDataType::class,
50 200,
51 ],
52 ];
53 }
54
55 /**
56 * @test
57 * @dataProvider canParseBinaryDataTypeProvider
58 * @param string $columnDefinition
59 * @param string $className
60 * @param int $length
61 */
62 public function canParseDataType(string $columnDefinition, string $className, int $length)
63 {
64 $subject = $this->createSubject($columnDefinition);
65
66 $this->assertInstanceOf($className, $subject->dataType);
67 $this->assertSame($length, $subject->dataType->getLength());
68 }
69
70 /**
71 * @test
72 */
73 public function lengthIsRequiredForVarCharType()
74 {
75 $this->expectExceptionCode(1471504822);
76 $this->expectExceptionMessageRegExp('Error: The current data type requires a field length definition');
77 new Parser('CREATE TABLE `aTable`(`aField` VARCHAR);');
78 }
79 }