|
6 | 6 |
|
7 | 7 | use KaririCode\Transformer\Contract\TransformationContext; |
8 | 8 | use KaririCode\Transformer\Core\TransformationContextImpl; |
9 | | -use KaririCode\Transformer\Rule\Date\{AgeRule, DateToIso8601Rule, DateToTimestampRule, RelativeDateRule}; |
| 9 | +use KaririCode\Transformer\Rule\Date\{DateToIso8601Rule, RelativeDateRule}; |
10 | 10 | use PHPUnit\Framework\Attributes\CoversClass; |
11 | 11 | use PHPUnit\Framework\Attributes\Test; |
12 | 12 | use PHPUnit\Framework\TestCase; |
13 | 13 |
|
14 | 14 | #[CoversClass(DateToIso8601Rule::class)] |
15 | | -#[CoversClass(DateToTimestampRule::class)] |
16 | 15 | #[CoversClass(RelativeDateRule::class)] |
17 | | -#[CoversClass(AgeRule::class)] |
18 | 16 | final class DateRulesTest extends TestCase |
19 | 17 | { |
20 | 18 | private function ctx(array $params = []): TransformationContext |
21 | 19 | { |
22 | 20 | return TransformationContextImpl::create([])->withField('test')->withParameters($params); |
23 | 21 | } |
24 | 22 |
|
25 | | - #[Test] |
26 | | - public function testDateToTimestamp(): void |
27 | | - { |
28 | | - $result = new DateToTimestampRule()->transform('2025-02-28', $this->ctx(['format' => 'Y-m-d'])); |
29 | | - $this->assertIsInt($result); |
30 | | - $date = new \DateTimeImmutable('@' . $result)->format('Y-m-d'); |
31 | | - $this->assertSame('2025-02-28', $date); |
32 | | - } |
33 | | - |
34 | | - #[Test] |
35 | | - public function testDateToTimestampInvalid(): void |
36 | | - { |
37 | | - $this->assertSame('invalid', new DateToTimestampRule()->transform('invalid', $this->ctx())); |
38 | | - } |
39 | | - |
40 | 23 | #[Test] |
41 | 24 | public function testDateToIso8601(): void |
42 | 25 | { |
@@ -172,32 +155,15 @@ public function testRelativeDateGetName(): void |
172 | 155 | public function testRelativeDateUsesDefaultNow(): void |
173 | 156 | { |
174 | 157 | // No 'now' param provided — uses PHP's current time |
175 | | - $recent = new \DateTimeImmutable()->modify('-2 minutes')->format('Y-m-d H:i:s'); |
| 158 | + $recent = (new \DateTimeImmutable())->modify('-2 minutes')->format('Y-m-d H:i:s'); |
176 | 159 | $result = new RelativeDateRule()->transform($recent, $this->ctx()); |
177 | 160 | $this->assertStringContainsString('minute', $result); |
178 | 161 | } |
179 | 162 |
|
180 | | - #[Test] |
181 | | - public function testAge(): void |
182 | | - { |
183 | | - // Someone born 2000-01-15 should be 25 on 2025-02-28 |
184 | | - $result = new AgeRule()->transform('2000-01-15', $this->ctx(['from' => 'Y-m-d'])); |
185 | | - $this->assertIsInt($result); |
186 | | - $this->assertGreaterThanOrEqual(25, $result); |
187 | | - } |
188 | | - |
189 | | - #[Test] |
190 | | - public function testAgeInvalid(): void |
191 | | - { |
192 | | - $this->assertSame('invalid', new AgeRule()->transform('invalid', $this->ctx())); |
193 | | - } |
194 | | - |
195 | 163 | #[Test] |
196 | 164 | public function testGetName(): void |
197 | 165 | { |
198 | | - $this->assertIsString(new \KaririCode\Transformer\Rule\Date\DateToIso8601Rule()->getName()); |
199 | | - $this->assertIsString(new \KaririCode\Transformer\Rule\Date\DateToTimestampRule()->getName()); |
200 | | - $this->assertIsString(new \KaririCode\Transformer\Rule\Date\RelativeDateRule()->getName()); |
201 | | - $this->assertIsString(new AgeRule()->getName()); |
| 166 | + $this->assertIsString((new \KaririCode\Transformer\Rule\Date\DateToIso8601Rule())->getName()); |
| 167 | + $this->assertIsString((new \KaririCode\Transformer\Rule\Date\RelativeDateRule())->getName()); |
202 | 168 | } |
203 | 169 | } |
0 commit comments