From 516d288e4e6d0b7396361022a6fd8f985061ab10 Mon Sep 17 00:00:00 2001 From: Wout Gevaert Date: Sun, 6 Oct 2019 23:03:19 +0200 Subject: [PATCH] Make test to test abstract dataproviders and dataproviders in abstract classes --- ...bstractVariousIterableDataProviderTest.php | 56 +++++++++++++++++++ .../VariousIterableDataProviderTest.php | 8 +-- tests/unit/Util/TestTest.php | 27 +++++++++ 3 files changed, 87 insertions(+), 4 deletions(-) create mode 100644 tests/_files/AbstractVariousIterableDataProviderTest.php diff --git a/tests/_files/AbstractVariousIterableDataProviderTest.php b/tests/_files/AbstractVariousIterableDataProviderTest.php new file mode 100644 index 00000000000..776e8bf840a --- /dev/null +++ b/tests/_files/AbstractVariousIterableDataProviderTest.php @@ -0,0 +1,56 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +abstract class AbstractVariousIterableDataProviderTest +{ + abstract public function asArrayProvider(); + + abstract public function asIteratorProvider(); + + abstract public function asTraversableProvider(); + + public function asArrayProviderInParent() + { + return [ + ['J'], + ['K'], + ['L'], + ]; + } + + public function asIteratorProviderInParent() + { + yield ['M']; + + yield ['N']; + + yield ['O']; + } + + public function asTraversableProviderInParent() + { + return new WrapperIteratorAggregate([ + ['P'], + ['Q'], + ['R'], + ]); + } + + /** + * @dataProvider asArrayProvider + * @dataProvider asIteratorProvider + * @dataProvider asTraversableProvider + * @dataProvider asArrayProviderInParent + * @dataProvider asIteratorProviderInParent + * @dataProvider asTraversableProviderInParent + */ + public function testAbstract(): void + { + } +} diff --git a/tests/_files/VariousIterableDataProviderTest.php b/tests/_files/VariousIterableDataProviderTest.php index b84e0ccc387..a5a95b2eea9 100644 --- a/tests/_files/VariousIterableDataProviderTest.php +++ b/tests/_files/VariousIterableDataProviderTest.php @@ -7,9 +7,9 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class VariousIterableDataProviderTest +class VariousIterableDataProviderTest extends AbstractVariousIterableDataProviderTest { - public static function asArrayProvider() + public function asArrayProvider() { return [ ['A'], @@ -18,7 +18,7 @@ public static function asArrayProvider() ]; } - public static function asIteratorProvider() + public function asIteratorProvider() { yield ['D']; @@ -27,7 +27,7 @@ public static function asIteratorProvider() yield ['F']; } - public static function asTraversableProvider() + public function asTraversableProvider() { return new WrapperIteratorAggregate([ ['G'], diff --git a/tests/unit/Util/TestTest.php b/tests/unit/Util/TestTest.php index 27202ead191..a19c4d8f81f 100644 --- a/tests/unit/Util/TestTest.php +++ b/tests/unit/Util/TestTest.php @@ -911,6 +911,33 @@ public function testMultipleYieldIteratorDataProviders(): void $this->assertEquals(3, $cCount); } + public function testWithAbstractVariousIterableDataProviders(): void + { + $dataSets = Test::getProvidedData(\VariousIterableDataProviderTest::class, 'testAbstract'); + + $this->assertEquals([ + ['A'], + ['B'], + ['C'], + ['D'], + ['E'], + ['F'], + ['G'], + ['H'], + ['I'], + ['J'], + ['K'], + ['L'], + ['M'], + ['N'], + ['O'], + ['P'], + ['Q'], + ['R'], + + ], $dataSets); + } + public function testWithVariousIterableDataProviders(): void { $dataSets = Test::getProvidedData(\VariousIterableDataProviderTest::class, 'test');