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