‪TYPO3CMS  10.4
DateTimeTypesTest.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 
27 
32 {
38  public function ‪canParseDateTimeTypeProvider(): array
39  {
40  return [
41  'DATE' => [
42  'DATE',
43  DateDataType::class,
44  null,
45  ],
46  'YEAR' => [
47  'YEAR',
48  YearDataType::class,
49  null,
50  ],
51  'TIME' => [
52  'TIME',
53  TimeDataType::class,
54  0,
55  ],
56  'TIME with fractional second part' => [
57  'TIME(3)',
58  TimeDataType::class,
59  3,
60  ],
61  'TIMESTAMP' => [
62  'TIMESTAMP',
63  TimestampDataType::class,
64  0,
65  ],
66  'TIMESTAMP with fractional second part' => [
67  'TIMESTAMP(3)',
68  TimestampDataType::class,
69  3,
70  ],
71  'DATETIME' => [
72  'DATETIME',
73  DateTimeDataType::class,
74  0,
75  ],
76  'DATETIME with fractional second part' => [
77  'DATETIME(3)',
78  DateTimeDataType::class,
79  3,
80  ],
81  ];
82  }
83 
91  public function ‪canParseDataType(string $columnDefinition, string $className, int $length = null)
92  {
93  $subject = $this->‪createSubject($columnDefinition);
94 
95  self::assertInstanceOf($className, $subject->dataType);
96 
97  // DATE & YEAR don't support fractional second parts
98  if ($length !== null) {
99  self::assertSame($length, $subject->dataType->getLength());
100  }
101  }
102 
107  {
108  $this->expectException(StatementException::class);
109  $this->expectDeprecationMessageMatches(
110  '@Error: the fractional seconds part for TIME, DATETIME or TIMESTAMP columns must >= 0@'
111  );
112  $this->‪createSubject('TIME(-1)');
113  }
114 
119  {
120  $this->expectException(StatementException::class);
121  $this->expectDeprecationMessageMatches(
122  '@Error: the fractional seconds part for TIME, DATETIME or TIMESTAMP columns must <= 6@'
123  );
124  $this->‪createSubject('TIME(7)');
125  }
126 }
‪TYPO3\CMS\Core\Database\Schema\Parser\AST\DataType\TimeDataType
Definition: TimeDataType.php:24
‪TYPO3\CMS\Core\Database\Schema\Parser\AST\DataType\DateTimeDataType
Definition: DateTimeDataType.php:24
‪TYPO3\CMS\Core\Database\Schema\Exception\StatementException
Definition: StatementException.php:24
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\AbstractDataTypeBaseTestCase\createSubject
‪TYPO3 CMS Core Database Schema Parser AST CreateColumnDefinitionItem createSubject(string $statement)
Definition: AbstractDataTypeBaseTestCase.php:52
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\DataTypes\DateTimeTypesTest\parseDateTimeTypeWithInvalidLowerBound
‪parseDateTimeTypeWithInvalidLowerBound()
Definition: DateTimeTypesTest.php:106
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\DataTypes\DateTimeTypesTest
Definition: DateTimeTypesTest.php:32
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\DataTypes\DateTimeTypesTest\parseDateTimeTypeWithInvalidUpperBound
‪parseDateTimeTypeWithInvalidUpperBound()
Definition: DateTimeTypesTest.php:118
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\AbstractDataTypeBaseTestCase
Definition: AbstractDataTypeBaseTestCase.php:29
‪TYPO3\CMS\Core\Database\Schema\Parser\AST\DataType\DateDataType
Definition: DateDataType.php:24
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\DataTypes
Definition: BinaryDataTypeTest.php:18
‪TYPO3\CMS\Core\Database\Schema\Parser\AST\DataType\YearDataType
Definition: YearDataType.php:24
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\DataTypes\DateTimeTypesTest\canParseDataType
‪canParseDataType(string $columnDefinition, string $className, int $length=null)
Definition: DateTimeTypesTest.php:91
‪TYPO3\CMS\Core\Database\Schema\Parser\AST\DataType\TimestampDataType
Definition: TimestampDataType.php:24
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\DataTypes\DateTimeTypesTest\canParseDateTimeTypeProvider
‪array canParseDateTimeTypeProvider()
Definition: DateTimeTypesTest.php:38