[FEATURE] Doctrine: Implement SchemaMigrationService
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Database / Schema / Parser / DataTypes / FixedPointTypesTest.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\DecimalDataType;
20 use TYPO3\CMS\Core\Database\Schema\Parser\AST\DataType\NumericDataType;
21 use TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\AbstractDataTypeBaseTestCase;
22
23 /**
24 * Tests for parsing DECIMAL/NUMERIC SQL data types
25 */
26 class FixedPointTypesTest extends AbstractDataTypeBaseTestCase
27 {
28 /**
29 * Data provider for canParseFixedPointTypes()
30 *
31 * @return array
32 */
33 public function canParseFixedPointTypesProvider(): array
34 {
35 return [
36 'DECIMAL without precision and scale' => [
37 'DECIMAL',
38 DecimalDataType::class,
39 -1,
40 -1,
41 ],
42 'DECIMAL with precision' => [
43 'DECIMAL(5)',
44 DecimalDataType::class,
45 5,
46 -1,
47 ],
48 'DECIMAL with precision and scale' => [
49 'DECIMAL(5,2)',
50 DecimalDataType::class,
51 5,
52 2,
53 ],
54 'NUMERIC without length' => [
55 'NUMERIC',
56 NumericDataType::class,
57 -1,
58 -1,
59 ],
60 'NUMERIC with length' => [
61 'NUMERIC(5)',
62 NumericDataType::class,
63 5,
64 -1,
65 ],
66 'NUMERIC with length and precision' => [
67 'NUMERIC(5,2)',
68 NumericDataType::class,
69 5,
70 2,
71 ],
72 ];
73 }
74
75 /**
76 * @test
77 * @dataProvider canParseFixedPointTypesProvider
78 * @param string $columnDefinition
79 * @param string $className
80 * @param int $precision
81 * @param int $scale
82 */
83 public function canParseDataType(
84 string $columnDefinition,
85 string $className,
86 int $precision = null,
87 int $scale = null
88 ) {
89 $subject = $this->createSubject($columnDefinition);
90
91 $this->assertInstanceOf($className, $subject->dataType);
92 $this->assertSame($precision, $subject->dataType->getPrecision());
93 $this->assertSame($scale, $subject->dataType->getScale());
94 }
95 }