Skip to content
This repository was archived by the owner on Jan 4, 2022. It is now read-only.

Commit 9dccc61

Browse files
committed
Enhancement: Implement DataProvider\ResourceProvider
1 parent 2c263dc commit 9dccc61

File tree

6 files changed

+223
-4
lines changed

6 files changed

+223
-4
lines changed

CHANGELOG.md

+12-4
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

77
## Unreleased
88

9-
For a full diff see [`1.2.0...main`][1.2.0...main].
9+
For a full diff see [`1.3.0...main`][1.3.0...main].
10+
11+
## [`1.3.0`][1.3.0]
12+
13+
For a full diff see [`1.2.0...1.3.0`][1.2.0...1.3.0].
1014

1115
### Added
1216

1317
* Added `DataProvider\ObjectProvider` ([#343]), by [@localheinz]
14-
*
18+
* Added `DataProvider\ResourceProvider` ([#344]), by [@localheinz]
19+
1520
## [`1.2.0`][1.2.0]
1621

1722
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].
2328
* Added `DataProvider\StringProvider` ([#328]), by [@localheinz]
2429
* Added `DataProvider\IntProvider` ([#335]), by [@localheinz]
2530
* Added `DataProvider\FloatProvider` ([#341]), by [@localheinz]
26-
*
31+
2732
### Changed
2833

2934
* 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].
112117
[1.0.1]: https://github.com/ergebnis/test-util/releases/tag/1.0.1
113118
[1.1.0]: https://github.com/ergebnis/test-util/releases/tag/1.1.0
114119
[1.2.0]: https://github.com/ergebnis/test-util/releases/tag/1.2.0
120+
[1.3.0]: https://github.com/ergebnis/test-util/releases/tag/1.3.0
115121

116122
[0.7.0...0.8.0]: https://github.com/ergebnis/test-util/compare/0.7.0...0.8.0
117123
[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].
120126
[1.0.0...1.0.1]: https://github.com/ergebnis/test-util/compare/1.0.0...1.0.1
121127
[1.0.1...1.1.0]: https://github.com/ergebnis/test-util/compare/1.0.1...1.1.0
122128
[1.1.0...1.2.0]: https://github.com/ergebnis/test-util/compare/1.1.0...1.2.0
123-
[1.2.0...main]: https://github.com/ergebnis/test-util/compare/1.2.0...main
129+
[1.2.0...1.3.0]: https://github.com/ergebnis/test-util/compare/1.2.0...1.3.0
130+
[1.3.0...main]: https://github.com/ergebnis/test-util/compare/1.3.0...main
124131

125132
[#118]: https://github.com/ergebnis/test-util/pull/118
126133
[#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].
137144
[#335]: https://github.com/ergebnis/test-util/pull/335
138145
[#341]: https://github.com/ergebnis/test-util/pull/341
139146
[#343]: https://github.com/ergebnis/test-util/pull/343
147+
[#344]: https://github.com/ergebnis/test-util/pull/344
140148

141149
[@ergebnis]: https://github.com/ergebnis
142150
[@localheinz]: https://github.com/localheinz

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ This package provides the following generic data providers:
106106
* [`Ergebnis\Test\Util\DataProvider\IntProvider`](https://github.com/ergebnis/test-util#dataproviderintprovider)
107107
* [`Ergebnis\Test\Util\DataProvider\NullProvider`](https://github.com/ergebnis/test-util#dataprovidernullprovider)
108108
* [`Ergebnis\Test\Util\DataProvider\ObjectProvider`](https://github.com/ergebnis/test-util#dataproviderobjectprovider)
109+
* [`Ergebnis\Test\Util\DataProvider\ResourceProvider`](https://github.com/ergebnis/test-util#dataproviderresourceprovider)
109110
* [`Ergebnis\Test\Util\DataProvider\StringProvider`](https://github.com/ergebnis/test-util#dataproviderstringprovider)
110111

111112
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`]
181182

182183
For examples, see [`Ergebnis\Test\Util\Test\Unit\DataProvider\ObjectProviderTest`](test/Unit/DataProvider/ObjectProviderTest.php).
183184

185+
#### `DataProvider\ResourceProvider`
186+
187+
* `resource()` provides a `resource`
188+
189+
For examples, see [`Ergebnis\Test\Util\Test\Unit\DataProvider\ResourceProviderTest`](test/Unit/DataProvider/ResourceProviderTest.php).
190+
184191
#### `DataProvider\StringProvider`
185192

186193
* `arbitrary()` provides arbitrary `string`s

phpstan-baseline.neon

+115
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,121 @@ parameters:
575575
count: 1
576576
path: src/DataProvider/ObjectProvider.php
577577

578+
-
579+
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:faker\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
580+
count: 1
581+
path: src/DataProvider/ResourceProvider.php
582+
583+
-
584+
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:assertClassesAreAbstractOrFinal\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
585+
count: 1
586+
path: src/DataProvider/ResourceProvider.php
587+
588+
-
589+
message: "#^Parameter \\#1 \\$argument of class ReflectionClass constructor expects class\\-string\\<T of object\\>\\|T of object, string given\\.$#"
590+
count: 2
591+
path: src/DataProvider/ResourceProvider.php
592+
593+
-
594+
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:assertClassesHaveTests\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
595+
count: 1
596+
path: src/DataProvider/ResourceProvider.php
597+
598+
-
599+
message: "#^Call to an undefined static method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:assertEmpty\\(\\)\\.$#"
600+
count: 2
601+
path: src/DataProvider/ResourceProvider.php
602+
603+
-
604+
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:assertClassyConstructsSatisfySpecification\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
605+
count: 1
606+
path: src/DataProvider/ResourceProvider.php
607+
608+
-
609+
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:assertClassExists\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
610+
count: 1
611+
path: src/DataProvider/ResourceProvider.php
612+
613+
-
614+
message: "#^Call to an undefined static method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:assertTrue\\(\\)\\.$#"
615+
count: 11
616+
path: src/DataProvider/ResourceProvider.php
617+
618+
-
619+
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:assertClassExtends\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
620+
count: 1
621+
path: src/DataProvider/ResourceProvider.php
622+
623+
-
624+
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:assertClassImplementsInterface\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
625+
count: 1
626+
path: src/DataProvider/ResourceProvider.php
627+
628+
-
629+
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:assertClassIsAbstract\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
630+
count: 1
631+
path: src/DataProvider/ResourceProvider.php
632+
633+
-
634+
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:assertClassIsFinal\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
635+
count: 1
636+
path: src/DataProvider/ResourceProvider.php
637+
638+
-
639+
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:assertClassSatisfiesSpecification\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
640+
count: 1
641+
path: src/DataProvider/ResourceProvider.php
642+
643+
-
644+
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:assertClassUsesTrait\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
645+
count: 1
646+
path: src/DataProvider/ResourceProvider.php
647+
648+
-
649+
message: "#^Call to an undefined static method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:assertContains\\(\\)\\.$#"
650+
count: 1
651+
path: src/DataProvider/ResourceProvider.php
652+
653+
-
654+
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:assertInterfaceExists\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
655+
count: 1
656+
path: src/DataProvider/ResourceProvider.php
657+
658+
-
659+
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:assertInterfaceExtends\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
660+
count: 1
661+
path: src/DataProvider/ResourceProvider.php
662+
663+
-
664+
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:assertInterfaceSatisfiesSpecification\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
665+
count: 1
666+
path: src/DataProvider/ResourceProvider.php
667+
668+
-
669+
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:assertTraitExists\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
670+
count: 1
671+
path: src/DataProvider/ResourceProvider.php
672+
673+
-
674+
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:assertTraitSatisfiesSpecification\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
675+
count: 1
676+
path: src/DataProvider/ResourceProvider.php
677+
678+
-
679+
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:provideDataForValues\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
680+
count: 1
681+
path: src/DataProvider/ResourceProvider.php
682+
683+
-
684+
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:provideDataForValuesWhere\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
685+
count: 1
686+
path: src/DataProvider/ResourceProvider.php
687+
688+
-
689+
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\ResourceProvider\\:\\:provideDataForValuesWhereNot\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
690+
count: 1
691+
path: src/DataProvider/ResourceProvider.php
692+
578693
-
579694
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\DataProvider\\\\StringProvider\\:\\:faker\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
580695
count: 1

psalm-baseline.xml

+10
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@
4242
<code>\Generator&lt;string, array{0: bool}&gt;</code>
4343
</MoreSpecificReturnType>
4444
</file>
45+
<file src="src/DataProvider/ResourceProvider.php">
46+
<MoreSpecificReturnType occurrences="1">
47+
<code>\Generator&lt;string, array{0: resource}&gt;</code>
48+
</MoreSpecificReturnType>
49+
</file>
4550
<file src="src/DataProvider/StringProvider.php">
4651
<MixedArgumentTypeCoercion occurrences="2"/>
4752
<MoreSpecificReturnType occurrences="5">
@@ -82,6 +87,11 @@
8287
<code>Util\Test\Util\DataProvider\Specification\Specification</code>
8388
</UnnecessaryVarAnnotation>
8489
</file>
90+
<file src="test/Unit/DataProvider/ResourceProviderTest.php">
91+
<MissingClosureParamType occurrences="1">
92+
<code>$value</code>
93+
</MissingClosureParamType>
94+
</file>
8595
<file src="test/Unit/Exception/InvalidExcludeClassNameTest.php">
8696
<MixedInferredReturnType occurrences="1">
8797
<code>\Generator&lt;array&lt;null|array|bool|float|int|resource|\stdClass&gt;&gt;</code>

src/DataProvider/ResourceProvider.php

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* Copyright (c) 2017-2020 Andreas Möller
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE.md file that was distributed with this source code.
10+
*
11+
* @see https://github.com/ergebnis/test-util
12+
*/
13+
14+
namespace Ergebnis\Test\Util\DataProvider;
15+
16+
use Ergebnis\Test\Util;
17+
18+
final class ResourceProvider
19+
{
20+
use Util\Helper;
21+
22+
/**
23+
* @return \Generator<string, array{0: resource}>
24+
*/
25+
public static function resource(): \Generator
26+
{
27+
yield from self::provideDataForValues([
28+
'resource' => \fopen(__FILE__, 'rb'),
29+
]);
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* Copyright (c) 2017-2020 Andreas Möller
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE.md file that was distributed with this source code.
10+
*
11+
* @see https://github.com/ergebnis/test-util
12+
*/
13+
14+
namespace Ergebnis\Test\Util\Test\Unit\DataProvider;
15+
16+
use Ergebnis\Test\Util\DataProvider\ResourceProvider;
17+
use Ergebnis\Test\Util\Test\Util;
18+
19+
/**
20+
* @internal
21+
*
22+
* @covers \Ergebnis\Test\Util\DataProvider\ResourceProvider
23+
*/
24+
final class ResourceProviderTest extends AbstractProviderTestCase
25+
{
26+
/**
27+
* @dataProvider \Ergebnis\Test\Util\DataProvider\ResourceProvider::resource()
28+
*
29+
* @param mixed $value
30+
*/
31+
public function testResourceProvidesResource($value): void
32+
{
33+
self::assertIsResource($value);
34+
}
35+
36+
public function testResourceReturnsGeneratorThatProvidesResource(): void
37+
{
38+
$specifications = [
39+
'resource' => Util\DataProvider\Specification\Closure::create(static function ($value): bool {
40+
return \is_resource($value);
41+
}),
42+
];
43+
44+
$provider = ResourceProvider::resource();
45+
46+
self::assertProvidesDataSetsForValuesSatisfyingSpecifications($specifications, $provider);
47+
}
48+
}

0 commit comments

Comments
 (0)