‪TYPO3CMS  9.5
DateTimeTypesTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
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 
26 
31 {
37  public function ‪canParseDateTimeTypeProvider(): array
38  {
39  return [
40  'DATE' => [
41  'DATE',
42  DateDataType::class,
43  null,
44  ],
45  'YEAR' => [
46  'YEAR',
47  YearDataType::class,
48  null,
49  ],
50  'TIME' => [
51  'TIME',
52  TimeDataType::class,
53  0,
54  ],
55  'TIME with fractional second part' => [
56  'TIME(3)',
57  TimeDataType::class,
58  3,
59  ],
60  'TIMESTAMP' => [
61  'TIMESTAMP',
62  TimestampDataType::class,
63  0,
64  ],
65  'TIMESTAMP with fractional second part' => [
66  'TIMESTAMP(3)',
67  TimestampDataType::class,
68  3,
69  ],
70  'DATETIME' => [
71  'DATETIME',
72  DateTimeDataType::class,
73  0,
74  ],
75  'DATETIME with fractional second part' => [
76  'DATETIME(3)',
77  DateTimeDataType::class,
78  3,
79  ],
80  ];
81  }
82 
90  public function ‪canParseDataType(string $columnDefinition, string $className, int $length = null)
91  {
92  $subject = $this->‪createSubject($columnDefinition);
93 
94  $this->assertInstanceOf($className, $subject->dataType);
95 
96  // DATE & YEAR don't support fractional second parts
97  if ($length !== null) {
98  $this->assertSame($length, $subject->dataType->getLength());
99  }
100  }
101 
106  {
107  $this->expectException(StatementException::class);
108  if (method_exists($this, 'expectDeprecationMessageMatches')) {
109  $this->expectDeprecationMessageMatches(
110  '@Error: the fractional seconds part for TIME, DATETIME or TIMESTAMP columns must >= 0@'
111  );
112  } else {
113  $this->expectExceptionMessageRegExp(
114  '@Error: the fractional seconds part for TIME, DATETIME or TIMESTAMP columns must >= 0@'
115  );
116  }
117  $this->‪createSubject('TIME(-1)');
118  }
119 
124  {
125  $this->expectException(StatementException::class);
126  if (method_exists($this, 'expectDeprecationMessageMatches')) {
127  $this->expectDeprecationMessageMatches(
128  '@Error: the fractional seconds part for TIME, DATETIME or TIMESTAMP columns must <= 6@'
129  );
130  } else {
131  $this->expectExceptionMessageRegExp(
132  '@Error: the fractional seconds part for TIME, DATETIME or TIMESTAMP columns must <= 6@'
133  );
134  }
135  $this->‪createSubject('TIME(7)');
136  }
137 }
‪TYPO3\CMS\Core\Database\Schema\Parser\AST\DataType\TimeDataType
Definition: TimeDataType.php:23
‪TYPO3\CMS\Core\Database\Schema\Parser\AST\DataType\DateTimeDataType
Definition: DateTimeDataType.php:23
‪TYPO3\CMS\Core\Database\Schema\Exception\StatementException
Definition: StatementException.php:23
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\AbstractDataTypeBaseTestCase\createSubject
‪TYPO3 CMS Core Database Schema Parser AST CreateColumnDefinitionItem createSubject(string $statement)
Definition: AbstractDataTypeBaseTestCase.php:51
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\DataTypes\DateTimeTypesTest\parseDateTimeTypeWithInvalidLowerBound
‪parseDateTimeTypeWithInvalidLowerBound()
Definition: DateTimeTypesTest.php:105
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\DataTypes\DateTimeTypesTest
Definition: DateTimeTypesTest.php:31
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\DataTypes\DateTimeTypesTest\parseDateTimeTypeWithInvalidUpperBound
‪parseDateTimeTypeWithInvalidUpperBound()
Definition: DateTimeTypesTest.php:123
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\AbstractDataTypeBaseTestCase
Definition: AbstractDataTypeBaseTestCase.php:28
‪TYPO3\CMS\Core\Database\Schema\Parser\AST\DataType\DateDataType
Definition: DateDataType.php:23
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\DataTypes
Definition: BinaryDataTypeTest.php:4
‪TYPO3\CMS\Core\Database\Schema\Parser\AST\DataType\YearDataType
Definition: YearDataType.php:23
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\DataTypes\DateTimeTypesTest\canParseDataType
‪canParseDataType(string $columnDefinition, string $className, int $length=null)
Definition: DateTimeTypesTest.php:90
‪TYPO3\CMS\Core\Database\Schema\Parser\AST\DataType\TimestampDataType
Definition: TimestampDataType.php:23
‪TYPO3\CMS\Core\Tests\Unit\Database\Schema\Parser\DataTypes\DateTimeTypesTest\canParseDateTimeTypeProvider
‪array canParseDateTimeTypeProvider()
Definition: DateTimeTypesTest.php:37