From d0503e8bd56f5c4b379e930f51f499d0a04d07c1 Mon Sep 17 00:00:00 2001 From: Niels Keurentjes Date: Tue, 5 Dec 2023 09:18:04 +0100 Subject: [PATCH] Release 0.8.0 --- CHANGELOG.md | 7 ++++--- src/Column/DateTimeColumn.php | 6 ++---- src/Exporter/Csv/CsvExporter.php | 2 +- tests/Unit/Adapter/ORMAdapterTest.php | 9 +++++++++ tests/Unit/ColumnTest.php | 3 +++ tests/Unit/DependencyInjectionTest.php | 12 ++++++++++++ 6 files changed, 31 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eab7357f..b0310f11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] Nothing yet. -## 0.8.0 - in RC +## [0.8.0] - 2023-12-05 ### Breaking - All interfaces and classes are now fully typed, this will likely require modifications in any custom extensions - Removed `DataTablesTrait` for use in controllers @@ -17,7 +17,7 @@ Nothing yet. ### Changed - Fix deprecations - - Add parameter and return types all over for static analysis purposes + - Add parameter and return types to all code - Codebase is now at PHPstan level 8 ## [0.7.2] - 2023-04-24 @@ -180,7 +180,8 @@ or break any applications. ### Added - Basic functionality -[Unreleased]: https://github.com/omines/datatables-bundle/compare/0.7.2...master +[Unreleased]: https://github.com/omines/datatables-bundle/compare/0.8.0...master +[0.8.0]: https://github.com/omines/datatables-bundle/compare/0.7.2...0.8.0 [0.7.2]: https://github.com/omines/datatables-bundle/compare/0.7.1...0.7.2 [0.7.1]: https://github.com/omines/datatables-bundle/compare/0.7.0...0.7.1 [0.7.0]: https://github.com/omines/datatables-bundle/compare/0.6.0...0.7.0 diff --git a/src/Column/DateTimeColumn.php b/src/Column/DateTimeColumn.php index aa839c11..4243abb9 100644 --- a/src/Column/DateTimeColumn.php +++ b/src/Column/DateTimeColumn.php @@ -31,10 +31,8 @@ public function normalize(mixed $value): mixed if (!empty($this->options['createFromFormat'])) { $value = \DateTime::createFromFormat($this->options['createFromFormat'], (string) $value); if (false === $value) { - if (false === ($errors = \DateTime::getLastErrors())) { - throw new \LogicException('DateTime conversion failed for unknown reasons'); - } - throw new \RuntimeException(implode(', ', $errors['errors'] ?: $errors['warnings'])); + $errors = \DateTime::getLastErrors(); + throw new \RuntimeException($errors ? implode(', ', $errors['errors'] ?: $errors['warnings']) : 'DateTime conversion failed for unknown reasons'); } } else { $value = new \DateTime((string) $value); diff --git a/src/Exporter/Csv/CsvExporter.php b/src/Exporter/Csv/CsvExporter.php index 828e89a7..dffad468 100644 --- a/src/Exporter/Csv/CsvExporter.php +++ b/src/Exporter/Csv/CsvExporter.php @@ -26,7 +26,7 @@ public function export(array $columnNames, \Iterator $data): \SplFileInfo $filePath = sys_get_temp_dir() . '/' . uniqid('dt') . '.csv'; if (false === ($file = fopen($filePath, 'w'))) { - throw new \RuntimeException('Failed to create temporary file at ' . $filePath); + throw new \RuntimeException('Failed to create temporary file at ' . $filePath); // @codeCoverageIgnore } fputcsv($file, $columnNames); diff --git a/tests/Unit/Adapter/ORMAdapterTest.php b/tests/Unit/Adapter/ORMAdapterTest.php index cc25498d..d9147a9f 100644 --- a/tests/Unit/Adapter/ORMAdapterTest.php +++ b/tests/Unit/Adapter/ORMAdapterTest.php @@ -12,7 +12,9 @@ namespace Tests\Unit\Adapter; +use Doctrine\ORM\Query; use Doctrine\ORM\Query\QueryException; +use Omines\DataTablesBundle\Adapter\Doctrine\Event\ORMAdapterQueryEvent; use Omines\DataTablesBundle\Adapter\Doctrine\ORMAdapter; use Omines\DataTablesBundle\DataTableFactory; use Omines\DataTablesBundle\DataTableState; @@ -40,4 +42,11 @@ public function testCountGroupedDataTable(): void $adapter = $datatable->getAdapter(); $data = $adapter->getData(new DataTableState($datatable)); } + + public function testORMAdapterQueryEvent(): void + { + $query = $this->createMock(Query::class); + $event = new ORMAdapterQueryEvent($query); + $this->assertSame($query, $event->getQuery()); + } } diff --git a/tests/Unit/ColumnTest.php b/tests/Unit/ColumnTest.php index 43ba5157..ccf3e210 100644 --- a/tests/Unit/ColumnTest.php +++ b/tests/Unit/ColumnTest.php @@ -62,6 +62,9 @@ public function testDateTimeColumnWithCreateFromFormat(): void ], $this->createDataTable()->setName('foo')); $this->assertSame('19.02.2020 22:30:34', $column->transform('2020-02-19T22:30:34+00:00')); + + $this->expectExceptionMessage('four digit year'); + $column->transform('foo.bar'); } public function testTextColumn(): void diff --git a/tests/Unit/DependencyInjectionTest.php b/tests/Unit/DependencyInjectionTest.php index d9a31718..461c6809 100644 --- a/tests/Unit/DependencyInjectionTest.php +++ b/tests/Unit/DependencyInjectionTest.php @@ -12,8 +12,11 @@ namespace Tests\Unit; +use Omines\DataTablesBundle\Adapter\AdapterInterface; use Omines\DataTablesBundle\DataTablesBundle; use Omines\DataTablesBundle\DependencyInjection\Configuration; +use Omines\DataTablesBundle\DependencyInjection\Instantiator; +use Omines\DataTablesBundle\Exception\InvalidArgumentException; use PHPUnit\Framework\TestCase; use Symfony\Component\Config\Definition\ArrayNode; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -47,4 +50,13 @@ public function testExtension(): void $this->assertTrue($config['language_from_cdn']); $this->assertEmpty($config['options']); } + + public function testInstantiatorTypeChecks(): void + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('must implement/extend ' . AdapterInterface::class); + + $instantiator = new Instantiator(); + $instantiator->getAdapter(\DateTimeImmutable::class); + } }