|
| 1 | +<?php declare(strict_types=1); |
| 2 | + |
| 3 | +namespace MalteHuebner\DataQueryBundle\Tests\Attribute\EntityAttribute; |
| 4 | + |
| 5 | +use MalteHuebner\DataQueryBundle\Attribute\EntityAttribute\DateTimeQueryable; |
| 6 | +use MalteHuebner\DataQueryBundle\Attribute\EntityAttribute\EntityAttributeInterface; |
| 7 | +use MalteHuebner\DataQueryBundle\Attribute\EntityAttribute\Queryable; |
| 8 | +use PHPUnit\Framework\TestCase; |
| 9 | + |
| 10 | +class DateTimeQueryableTest extends TestCase |
| 11 | +{ |
| 12 | + public function testExtendsQueryable(): void |
| 13 | + { |
| 14 | + $attr = new DateTimeQueryable(); |
| 15 | + |
| 16 | + $this->assertInstanceOf(Queryable::class, $attr); |
| 17 | + } |
| 18 | + |
| 19 | + public function testImplementsEntityAttributeInterface(): void |
| 20 | + { |
| 21 | + $attr = new DateTimeQueryable(); |
| 22 | + |
| 23 | + $this->assertInstanceOf(EntityAttributeInterface::class, $attr); |
| 24 | + } |
| 25 | + |
| 26 | + public function testGetFormat(): void |
| 27 | + { |
| 28 | + $attr = new DateTimeQueryable(format: 'yyyy-MM-dd'); |
| 29 | + |
| 30 | + $this->assertSame('yyyy-MM-dd', $attr->getFormat()); |
| 31 | + } |
| 32 | + |
| 33 | + public function testGetPattern(): void |
| 34 | + { |
| 35 | + $attr = new DateTimeQueryable(pattern: 'Y-m-d'); |
| 36 | + |
| 37 | + $this->assertSame('Y-m-d', $attr->getPattern()); |
| 38 | + } |
| 39 | + |
| 40 | + public function testGetAccepts(): void |
| 41 | + { |
| 42 | + $attr = new DateTimeQueryable(accepts: ['year', 'month', 'day']); |
| 43 | + |
| 44 | + $this->assertSame(['year', 'month', 'day'], $attr->getAccepts()); |
| 45 | + } |
| 46 | + |
| 47 | + public function testDefaultValues(): void |
| 48 | + { |
| 49 | + $attr = new DateTimeQueryable(); |
| 50 | + |
| 51 | + $this->assertSame([], $attr->getAccepts()); |
| 52 | + $this->assertNull($attr->getFormat()); |
| 53 | + $this->assertNull($attr->getPattern()); |
| 54 | + } |
| 55 | + |
| 56 | + public function testAllParameters(): void |
| 57 | + { |
| 58 | + $attr = new DateTimeQueryable( |
| 59 | + accepts: ['year'], |
| 60 | + format: 'yyyy-MM-dd', |
| 61 | + pattern: 'Y-m-d' |
| 62 | + ); |
| 63 | + |
| 64 | + $this->assertSame(['year'], $attr->getAccepts()); |
| 65 | + $this->assertSame('yyyy-MM-dd', $attr->getFormat()); |
| 66 | + $this->assertSame('Y-m-d', $attr->getPattern()); |
| 67 | + } |
| 68 | +} |
0 commit comments