From 9dccc61d1c1ef8a6a4e100a12a43f1f15894fe89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Mo=CC=88ller?= Date: Mon, 5 Oct 2020 14:11:56 +0200 Subject: [PATCH] Enhancement: Implement DataProvider\ResourceProvider --- CHANGELOG.md | 16 ++- README.md | 7 ++ phpstan-baseline.neon | 115 ++++++++++++++++++ psalm-baseline.xml | 10 ++ src/DataProvider/ResourceProvider.php | 31 +++++ .../DataProvider/ResourceProviderTest.php | 48 ++++++++ 6 files changed, 223 insertions(+), 4 deletions(-) create mode 100644 src/DataProvider/ResourceProvider.php create mode 100644 test/Unit/DataProvider/ResourceProviderTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 18d3c1ca..e352d636 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,12 +6,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## Unreleased -For a full diff see [`1.2.0...main`][1.2.0...main]. +For a full diff see [`1.3.0...main`][1.3.0...main]. + +## [`1.3.0`][1.3.0] + +For a full diff see [`1.2.0...1.3.0`][1.2.0...1.3.0]. ### Added * Added `DataProvider\ObjectProvider` ([#343]), by [@localheinz] -* +* Added `DataProvider\ResourceProvider` ([#344]), by [@localheinz] + ## [`1.2.0`][1.2.0] For a full diff see [`1.1.0...1.2.0`][1.1.0...1.2.0]. @@ -23,7 +28,7 @@ For a full diff see [`1.1.0...1.2.0`][1.1.0...1.2.0]. * Added `DataProvider\StringProvider` ([#328]), by [@localheinz] * Added `DataProvider\IntProvider` ([#335]), by [@localheinz] * Added `DataProvider\FloatProvider` ([#341]), by [@localheinz] -* + ### Changed * Renamed `DataProvider\BooleanProvider` to `DataProvider\BoolProvider` ([#334]), by [@localheinz] @@ -112,6 +117,7 @@ For a full diff see [`0.7.0...0.8.0`][0.7.0...0.8.0]. [1.0.1]: https://github.com/ergebnis/test-util/releases/tag/1.0.1 [1.1.0]: https://github.com/ergebnis/test-util/releases/tag/1.1.0 [1.2.0]: https://github.com/ergebnis/test-util/releases/tag/1.2.0 +[1.3.0]: https://github.com/ergebnis/test-util/releases/tag/1.3.0 [0.7.0...0.8.0]: https://github.com/ergebnis/test-util/compare/0.7.0...0.8.0 [0.8.0...0.9.0]: https://github.com/ergebnis/test-util/compare/0.8.0...0.9.0 @@ -120,7 +126,8 @@ For a full diff see [`0.7.0...0.8.0`][0.7.0...0.8.0]. [1.0.0...1.0.1]: https://github.com/ergebnis/test-util/compare/1.0.0...1.0.1 [1.0.1...1.1.0]: https://github.com/ergebnis/test-util/compare/1.0.1...1.1.0 [1.1.0...1.2.0]: https://github.com/ergebnis/test-util/compare/1.1.0...1.2.0 -[1.2.0...main]: https://github.com/ergebnis/test-util/compare/1.2.0...main +[1.2.0...1.3.0]: https://github.com/ergebnis/test-util/compare/1.2.0...1.3.0 +[1.3.0...main]: https://github.com/ergebnis/test-util/compare/1.3.0...main [#118]: https://github.com/ergebnis/test-util/pull/118 [#119]: https://github.com/ergebnis/test-util/pull/119 @@ -137,6 +144,7 @@ For a full diff see [`0.7.0...0.8.0`][0.7.0...0.8.0]. [#335]: https://github.com/ergebnis/test-util/pull/335 [#341]: https://github.com/ergebnis/test-util/pull/341 [#343]: https://github.com/ergebnis/test-util/pull/343 +[#344]: https://github.com/ergebnis/test-util/pull/344 [@ergebnis]: https://github.com/ergebnis [@localheinz]: https://github.com/localheinz diff --git a/README.md b/README.md index 301b7dbd..adcbaee6 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,7 @@ This package provides the following generic data providers: * [`Ergebnis\Test\Util\DataProvider\IntProvider`](https://github.com/ergebnis/test-util#dataproviderintprovider) * [`Ergebnis\Test\Util\DataProvider\NullProvider`](https://github.com/ergebnis/test-util#dataprovidernullprovider) * [`Ergebnis\Test\Util\DataProvider\ObjectProvider`](https://github.com/ergebnis/test-util#dataproviderobjectprovider) +* [`Ergebnis\Test\Util\DataProvider\ResourceProvider`](https://github.com/ergebnis/test-util#dataproviderresourceprovider) * [`Ergebnis\Test\Util\DataProvider\StringProvider`](https://github.com/ergebnis/test-util#dataproviderstringprovider) Since it is possible to use multiple `@dataProvider` annotations for test methods, these generic data providers allow for reuse and composition of data providers: @@ -181,6 +182,12 @@ For examples, see [`Ergebnis\Test\Util\Test\Unit\DataProvider\NullProviderTest`] For examples, see [`Ergebnis\Test\Util\Test\Unit\DataProvider\ObjectProviderTest`](test/Unit/DataProvider/ObjectProviderTest.php). +#### `DataProvider\ResourceProvider` + +* `resource()` provides a `resource` + +For examples, see [`Ergebnis\Test\Util\Test\Unit\DataProvider\ResourceProviderTest`](test/Unit/DataProvider/ResourceProviderTest.php). + #### `DataProvider\StringProvider` * `arbitrary()` provides arbitrary `string`s diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 3b6b2fbf..e4177347 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -575,6 +575,121 @@ parameters: count: 1 path: src/DataProvider/ObjectProvider.php + - + message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:faker\\(\\) is protected, but since the containing class is final, it can be private\\.$#" + count: 1 + path: src/DataProvider/ResourceProvider.php + + - + message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:assertClassesAreAbstractOrFinal\\(\\) is protected, but since the containing class is final, it can be private\\.$#" + count: 1 + path: src/DataProvider/ResourceProvider.php + + - + message: "#^Parameter \\#1 \\$argument of class ReflectionClass constructor expects class\\-string\\\\|T of object, string given\\.$#" + count: 2 + path: src/DataProvider/ResourceProvider.php + + - + message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:assertClassesHaveTests\\(\\) is protected, but since the containing class is final, it can be private\\.$#" + count: 1 + path: src/DataProvider/ResourceProvider.php + + - + message: "#^Call to an undefined static method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:assertEmpty\\(\\)\\.$#" + count: 2 + path: src/DataProvider/ResourceProvider.php + + - + message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:assertClassyConstructsSatisfySpecification\\(\\) is protected, but since the containing class is final, it can be private\\.$#" + count: 1 + path: src/DataProvider/ResourceProvider.php + + - + message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:assertClassExists\\(\\) is protected, but since the containing class is final, it can be private\\.$#" + count: 1 + path: src/DataProvider/ResourceProvider.php + + - + message: "#^Call to an undefined static method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:assertTrue\\(\\)\\.$#" + count: 11 + path: src/DataProvider/ResourceProvider.php + + - + message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:assertClassExtends\\(\\) is protected, but since the containing class is final, it can be private\\.$#" + count: 1 + path: src/DataProvider/ResourceProvider.php + + - + message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:assertClassImplementsInterface\\(\\) is protected, but since the containing class is final, it can be private\\.$#" + count: 1 + path: src/DataProvider/ResourceProvider.php + + - + message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:assertClassIsAbstract\\(\\) is protected, but since the containing class is final, it can be private\\.$#" + count: 1 + path: src/DataProvider/ResourceProvider.php + + - + message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:assertClassIsFinal\\(\\) is protected, but since the containing class is final, it can be private\\.$#" + count: 1 + path: src/DataProvider/ResourceProvider.php + + - + message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:assertClassSatisfiesSpecification\\(\\) is protected, but since the containing class is final, it can be private\\.$#" + count: 1 + path: src/DataProvider/ResourceProvider.php + + - + message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:assertClassUsesTrait\\(\\) is protected, but since the containing class is final, it can be private\\.$#" + count: 1 + path: src/DataProvider/ResourceProvider.php + + - + message: "#^Call to an undefined static method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:assertContains\\(\\)\\.$#" + count: 1 + path: src/DataProvider/ResourceProvider.php + + - + message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:assertInterfaceExists\\(\\) is protected, but since the containing class is final, it can be private\\.$#" + count: 1 + path: src/DataProvider/ResourceProvider.php + + - + message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:assertInterfaceExtends\\(\\) is protected, but since the containing class is final, it can be private\\.$#" + count: 1 + path: src/DataProvider/ResourceProvider.php + + - + message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:assertInterfaceSatisfiesSpecification\\(\\) is protected, but since the containing class is final, it can be private\\.$#" + count: 1 + path: src/DataProvider/ResourceProvider.php + + - + message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:assertTraitExists\\(\\) is protected, but since the containing class is final, it can be private\\.$#" + count: 1 + path: src/DataProvider/ResourceProvider.php + + - + message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:assertTraitSatisfiesSpecification\\(\\) is protected, but since the containing class is final, it can be private\\.$#" + count: 1 + path: src/DataProvider/ResourceProvider.php + + - + message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:provideDataForValues\\(\\) is protected, but since the containing class is final, it can be private\\.$#" + count: 1 + path: src/DataProvider/ResourceProvider.php + + - + message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:provideDataForValuesWhere\\(\\) is protected, but since the containing class is final, it can be private\\.$#" + count: 1 + path: src/DataProvider/ResourceProvider.php + + - + message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:provideDataForValuesWhereNot\\(\\) is protected, but since the containing class is final, it can be private\\.$#" + count: 1 + path: src/DataProvider/ResourceProvider.php + - message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\StringProvider\\:\\:faker\\(\\) is protected, but since the containing class is final, it can be private\\.$#" count: 1 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index ca023e38..991d6158 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -42,6 +42,11 @@ \Generator<string, array{0: bool}> + + + \Generator<string, array{0: resource}> + + @@ -82,6 +87,11 @@ Util\Test\Util\DataProvider\Specification\Specification + + + $value + + \Generator<array<null|array|bool|float|int|resource|\stdClass>> diff --git a/src/DataProvider/ResourceProvider.php b/src/DataProvider/ResourceProvider.php new file mode 100644 index 00000000..86aa59d5 --- /dev/null +++ b/src/DataProvider/ResourceProvider.php @@ -0,0 +1,31 @@ + + */ + public static function resource(): \Generator + { + yield from self::provideDataForValues([ + 'resource' => \fopen(__FILE__, 'rb'), + ]); + } +} diff --git a/test/Unit/DataProvider/ResourceProviderTest.php b/test/Unit/DataProvider/ResourceProviderTest.php new file mode 100644 index 00000000..5f114738 --- /dev/null +++ b/test/Unit/DataProvider/ResourceProviderTest.php @@ -0,0 +1,48 @@ + Util\DataProvider\Specification\Closure::create(static function ($value): bool { + return \is_resource($value); + }), + ]; + + $provider = ResourceProvider::resource(); + + self::assertProvidesDataSetsForValuesSatisfyingSpecifications($specifications, $provider); + } +}