diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..876174e --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +/phpcs.xml.dist export-ignore diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..6dad948 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,37 @@ +name: CI + +on: + pull_request: + push: + branches: + - "master" + workflow_dispatch: + +jobs: + tests: + name: PHP ${{ matrix.php }} + runs-on: ubuntu-22.04 + strategy: + fail-fast: false + matrix: + php: + - "8.3" + - "8.4" + + steps: + - uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + env: + phpts: ${{ matrix.phpts }} + + - name: "Install dependencies with Composer" + uses: "ramsey/composer-install@v3" + with: + composer-options: "--prefer-dist" + + - name: Run PHPUnit tests + run: composer test diff --git a/.gitignore b/.gitignore index 7579f74..105fc17 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ -vendor +.phpunit.cache composer.lock +phpunit.xml +vendor diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..3c54c19 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,18 @@ + + + + + tests + + + diff --git a/tests/CollectionTest.php b/tests/CollectionTestCase.php similarity index 91% rename from tests/CollectionTest.php rename to tests/CollectionTestCase.php index 8ecb063..e81b5f9 100644 --- a/tests/CollectionTest.php +++ b/tests/CollectionTestCase.php @@ -10,7 +10,7 @@ use function strpos; use function var_dump; -abstract class CollectionTest extends TestCase +abstract class CollectionTestCase extends TestCase { /** * Sample sizes. @@ -18,10 +18,15 @@ abstract class CollectionTest extends TestCase const MANY = 65; const SOME = 17; + /** + * Create an instance of the data structure being tested. + */ + abstract public static function getInstance(array $values = []); + /** * Generic mixed value sample array. */ - public function sample() + public static function sample() { return array_merge( [[]], // empty @@ -38,23 +43,23 @@ public function sample() /** * @return array provides two equal values for each test. */ - public function basicDataProvider() + public static function basicDataProvider() { $values = [ [], ['a'], ['a', 'b'], ['a', 'b', 'c'], - $this->sample(), + self::sample(), ]; - return array_map(function($a) { return [$a, $a]; }, $values); + return array_map(fn($a) => [$a, $a], $values); } /** * @return array a data provider for Sequence and Set to test out of range. */ - public function outOfRangeDataProvider() + public static function outOfRangeDataProvider() { return [ [[ ], -1], @@ -64,7 +69,7 @@ public function outOfRangeDataProvider() ]; } - public function badIndexDataProvider() + public static function badIndexDataProvider() { return [ [[], 'a'], @@ -250,7 +255,7 @@ protected function cleanVarDump($expression) */ public function testConvertingToBoolean() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->assertTrue((bool) $instance); } } @@ -268,9 +273,9 @@ public function __construct($test) { $this->test = $test; } - public function getInstance(array $values = null) + public function getInstance(array|null $values = null) { - return $this->test->getInstance($values); + return $this->test::getInstance($values); } } diff --git a/tests/Deque/__construct.php b/tests/Deque/__construct.php index 8643abb..7b6f1b2 100644 --- a/tests/Deque/__construct.php +++ b/tests/Deque/__construct.php @@ -1,33 +1,31 @@ sample(), + self::sample(), range(1, self::MANY), ]); } - /** - * @dataProvider constructDataProvider - */ + #[DataProvider('constructDataProvider')] public function testConstruct($values, array $expected) { $this->assertToArray($expected, new Deque($values)); } - /** - * @dataProvider constructDataProvider - */ + #[DataProvider('constructDataProvider')] public function testConstructUsingNonArrayIterable(array $values, array $expected) { $this->assertToArray($expected, new Deque(new \ArrayIterator($values))); diff --git a/tests/Deque/allocate.php b/tests/Deque/allocate.php index 5aceb38..2529f47 100644 --- a/tests/Deque/allocate.php +++ b/tests/Deque/allocate.php @@ -1,9 +1,11 @@ getInstance(); + $instance = static::getInstance(); $instance->allocate($initial); $instance->allocate($allocate); diff --git a/tests/Deque/capacity.php b/tests/Deque/capacity.php index 4ba6da1..571afda 100644 --- a/tests/Deque/capacity.php +++ b/tests/Deque/capacity.php @@ -7,7 +7,7 @@ public function testCapacity() { $min = \Ds\Deque::MIN_CAPACITY; - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->assertEquals($min, $instance->capacity()); for ($i = 0; $i < $min; $i++) { @@ -42,7 +42,7 @@ public function testAutoTruncate() 0 => 8, ]; - $instance = $this->getInstance(range(1, array_keys($boundaries)[0])); + $instance = static::getInstance(range(1, array_keys($boundaries)[0])); for (;;) { if ( ! is_null(($expected = $boundaries[$instance->count()] ?? null))) { @@ -61,7 +61,7 @@ public function testClearResetsCapacity() { $min = \Ds\Deque::MIN_CAPACITY; - $instance = $this->getInstance(range(1, self::MANY)); + $instance = static::getInstance(range(1, self::MANY)); $instance->clear(); $this->assertEquals($min, $instance->capacity()); } diff --git a/tests/Deque/insert.php b/tests/Deque/insert.php index 92140b7..bf7f6f3 100644 --- a/tests/Deque/insert.php +++ b/tests/Deque/insert.php @@ -9,7 +9,7 @@ trait insert */ public function testInsertExtended() { - $instance = $this->getInstance(); + $instance = static::getInstance(); // The head of the deque will wrap around if all items are unshifted. @@ -32,7 +32,7 @@ public function testInsertExtended() public function testInsertingIntoAnIsland() { - $instance = $this->getInstance(); + $instance = static::getInstance(); // It's possible that the head of the deque comes before the tail, but // is not at zero. This could overflow the buffer. @@ -59,7 +59,7 @@ public function testInsertingIntoAnIsland() public function testInsertAtBoundaryWithMoreOnTheLeft() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $instance->push(3, 4, 5, 6); $instance->unshift(1, 2); @@ -74,7 +74,7 @@ public function testInsertAtBoundaryWithMoreOnTheLeft() public function testInsertAtBoundaryWithMoreOnTheRight() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $instance->push(5, 6); $instance->unshift(1, 2, 3, 4); @@ -89,7 +89,7 @@ public function testInsertAtBoundaryWithMoreOnTheRight() public function testInsertAtBoundaryWithEqualOnBothSides() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $instance->push(4, 5, 6); $instance->unshift(1, 2, 3); @@ -103,7 +103,7 @@ public function testInsertAtBoundaryWithEqualOnBothSides() public function testAlmostFullInsertAtZero() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $instance->push(...range(1, 6)); $instance->insert(0, 0); diff --git a/tests/Deque/remove.php b/tests/Deque/remove.php index 954f436..f33d077 100644 --- a/tests/Deque/remove.php +++ b/tests/Deque/remove.php @@ -9,7 +9,7 @@ trait remove */ public function testRemoveExtended() { - $instance = $this->getInstance(); + $instance = static::getInstance(); /* HEAD WRAPPED AROUND, TAIL = 0 */ // The head of the deque will wrap around if all items are unshifted. @@ -25,7 +25,7 @@ public function testRemoveExtended() $this->assertTrue($instance->isEmpty()); /* HEAD WRAPPED AROUND, TAIL > 0 */ - $instance = $this->getInstance(); + $instance = static::getInstance(); $instance->unshift('b'); // [_, _, ..., _, b] tail = 0, head = 3 $instance->unshift('a'); // [_, _, ..., a, b] tail = 0, head = 2 @@ -38,7 +38,7 @@ public function testRemoveExtended() $this->assertTrue($instance->isEmpty()); /* HEAD NOT WRAPPED, TAIL > 0 */ - $instance = $this->getInstance(); + $instance = static::getInstance(); $instance->push('a'); // [a, _, _, ..., _] tail = 1, head = 0 $instance->push('b'); // [a, b, _, ..., _] tail = 2, head = 0 diff --git a/tests/Deque/slice.php b/tests/Deque/slice.php index 458a3bf..47143d8 100644 --- a/tests/Deque/slice.php +++ b/tests/Deque/slice.php @@ -9,7 +9,7 @@ trait slice */ public function testSliceExtended() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $instance->unshift('c'); // [_, _, _, _, _, _, _, c] tail = 0, head = 7 $instance->unshift('b'); // [_, _, _, _, _, _, b, c] tail = 0, head = 6 @@ -30,7 +30,7 @@ public function testSliceExtended() /* If only some values have wrapped around, slice would have to copy from both the wrapped and not-wrapped values */ - $instance = $this->getInstance(); + $instance = static::getInstance(); $instance->push('b'); // [b, _, _, _, _, _, _, _] tail = 1, head = 0 $instance->push('c'); // [b, c, _, _, _, _, _, _] tail = 2, head = 1 diff --git a/tests/DequeTest.php b/tests/DequeTest.php index 11f3c19..f432578 100644 --- a/tests/DequeTest.php +++ b/tests/DequeTest.php @@ -3,7 +3,7 @@ use ArrayAccess; -class DequeTest extends CollectionTest +class DequeTest extends CollectionTestCase { use Sequence\_clone; use Sequence\_echo; @@ -54,14 +54,14 @@ class DequeTest extends CollectionTest use Sequence\toArray; use Sequence\unshift; - public function getInstance(array $values = []) + public static function getInstance(array $values = []) { return new \Ds\Deque($values); } public function testReallocatingWhenHeadNotAtZero() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $instance->push('a', 'b', 'c', 'd'); $instance->shift(); @@ -81,7 +81,7 @@ public function testReallocatingWhenHeadNotAtZero() public function testReallocatingWhenHeadHasWrapped() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $instance->push('a'); $instance->push('b'); @@ -106,7 +106,7 @@ public function testReallocatingWhenHeadHasWrapped() public function testRealignmentOfWrappedBufferWithLargeTempSpace() { - $instance = $this->getInstance(); // [_, _, _, _, _, _, _, _] + $instance = static::getInstance(); // [_, _, _, _, _, _, _, _] $instance->push('c', 'd'); $instance->unshift('a', 'b'); // [c, d, _, _, _, _, a, b] @@ -132,7 +132,7 @@ public function testRealignmentOfWrappedBufferWithLargeTempSpace() // Also test the boundary case, where the number of wrapped values // equals the amount of free space in the buffer. - $instance = $this->getInstance(); // [_, _, _, _, _, _, _, _] + $instance = static::getInstance(); // [_, _, _, _, _, _, _, _] $instance->push('c', 'd', 'e', 'f'); $instance->unshift('a', 'b'); // [c, d, e, f, _, _, a, b] @@ -149,7 +149,7 @@ public function testRealignmentOfWrappedBufferWithLargeTempSpace() //////////////////////////////////////////////////////////////// // Also test for assurance when there isn't enough space. - $instance = $this->getInstance(); // [_, _, _, _, _, _, _, _] + $instance = static::getInstance(); // [_, _, _, _, _, _, _, _] $instance->push('c', 'd', 'e', 'f', 'g'); $instance->unshift('a', 'b'); // [c, d, e, f, g, _, a, b] @@ -166,6 +166,6 @@ public function testRealignmentOfWrappedBufferWithLargeTempSpace() public function testImplementsArrayAccess() { - $this->assertInstanceOf(ArrayAccess::class, $this->getInstance()); + $this->assertInstanceOf(ArrayAccess::class, static::getInstance()); } } diff --git a/tests/Map/__construct.php b/tests/Map/__construct.php index 7a4f5db..59fb280 100644 --- a/tests/Map/__construct.php +++ b/tests/Map/__construct.php @@ -1,32 +1,30 @@ 1], ['a' => 1, 'b' => 2], ['a' => 1, 'b' => 2, 'c' => 3], - $this->sample(), + self::sample(), ]); } - /** - * @dataProvider constructDataProvider - */ + #[DataProvider('constructDataProvider')] public function testConstruct(array $values, array $expected) { $this->assertToArray($expected, new Map($values)); } - /** - * @dataProvider constructDataProvider - */ + #[DataProvider('constructDataProvider')] public function testConstructUsingNonArrayIterable(array $values, array $expected) { $this->assertToArray($expected, new Map(new \ArrayIterator($values))); diff --git a/tests/Map/_clone.php b/tests/Map/_clone.php index 58230a8..71ed9ef 100644 --- a/tests/Map/_clone.php +++ b/tests/Map/_clone.php @@ -1,19 +1,19 @@ basicDataProvider(); + return self::basicDataProvider(); } - /** - * @dataProvider cloneDataProvider - */ + #[DataProvider('cloneDataProvider')] public function testClone($values, array $expected) { - $instance = $this->getInstance($values); + $instance = static::getInstance($values); $clone = clone $instance; diff --git a/tests/Map/_echo.php b/tests/Map/_echo.php index f5ed083..2e8af6b 100644 --- a/tests/Map/_echo.php +++ b/tests/Map/_echo.php @@ -5,6 +5,6 @@ trait _echo { public function testEcho() { - $this->assertInstanceToString($this->getInstance()); + $this->assertInstanceToString(static::getInstance()); } } diff --git a/tests/Map/_empty.php b/tests/Map/_empty.php index f2351c7..d47b3ba 100644 --- a/tests/Map/_empty.php +++ b/tests/Map/_empty.php @@ -1,10 +1,12 @@ getInstance(); + $instance = static::getInstance(); foreach ($initial as $key => $value) { $instance->put($key, $value); @@ -30,12 +30,10 @@ public function testArrayAccessEmpty(array $initial, $key, bool $empty) $this->assertEquals($empty, empty($instance[$key])); } - /** - * @dataProvider emptyDataProvider - */ + #[DataProvider('emptyDataProvider')] public function testArrayAccessEmptyByReference(array $initial, $key, bool $empty) { - $instance = $this->getInstance([$initial]); + $instance = static::getInstance([$initial]); $this->assertEquals($empty, empty($instance[0][$key])); } diff --git a/tests/Map/_foreach.php b/tests/Map/_foreach.php index 73b6820..8090749 100644 --- a/tests/Map/_foreach.php +++ b/tests/Map/_foreach.php @@ -1,14 +1,14 @@ getInstance($values); + $instance = static::getInstance($values); $this->assertForEach($expected, $instance); } } diff --git a/tests/Map/_isset.php b/tests/Map/_isset.php index 045e21a..b6637ad 100644 --- a/tests/Map/_isset.php +++ b/tests/Map/_isset.php @@ -1,10 +1,12 @@ getInstance(); + $instance = static::getInstance(); foreach ($initial as $key => $value) { $instance->put($key, $value); @@ -30,12 +30,10 @@ public function testArrayAccessIsset(array $initial, $key, bool $isset) $this->assertEquals($isset, isset($instance[$key])); } - /** - * @dataProvider issetDataProvider - */ + #[DataProvider('issetDataProvider')] public function testArrayAccessIssetByMethod(array $initial, $key, bool $isset) { - $instance = $this->getInstance(); + $instance = static::getInstance(); foreach ($initial as $key => $value) { $instance->put($key, $value); @@ -44,12 +42,10 @@ public function testArrayAccessIssetByMethod(array $initial, $key, bool $isset) $this->assertEquals($isset, $instance->offsetExists($key)); } - /** - * @dataProvider issetDataProvider - */ + #[DataProvider('issetDataProvider')] public function testArrayAccessIssetByReference(array $initial, $key, bool $isset) { - $instance = $this->getInstance([$initial]); + $instance = static::getInstance([$initial]); $this->assertEquals($isset, isset($instance[0][$key])); } } diff --git a/tests/Map/_jsonEncode.php b/tests/Map/_jsonEncode.php index 668f00f..9402832 100644 --- a/tests/Map/_jsonEncode.php +++ b/tests/Map/_jsonEncode.php @@ -1,19 +1,19 @@ basicDataProvider(); + return self::basicDataProvider(); } - /** - * @dataProvider jsonEncodeDataProvider - */ + #[DataProvider('jsonEncodeDataProvider')] public function testJsonEncode(array $initial, array $expected) { - $instance = $this->getInstance($initial); + $instance = static::getInstance($initial); $this->assertEquals(json_encode((object) $expected), json_encode($instance)); } } diff --git a/tests/Map/_serialize.php b/tests/Map/_serialize.php index a5ef876..c7e5dae 100644 --- a/tests/Map/_serialize.php +++ b/tests/Map/_serialize.php @@ -1,14 +1,14 @@ getInstance($values); + $instance = static::getInstance($values); $this->assertSerialized($expected, $instance, true); } } diff --git a/tests/Map/_unset.php b/tests/Map/_unset.php index 905593f..f93b0cc 100644 --- a/tests/Map/_unset.php +++ b/tests/Map/_unset.php @@ -6,14 +6,14 @@ trait _unset public function testArrayAccessUnset() { - $instance = $this->getInstance(['a' => 1]); + $instance = static::getInstance(['a' => 1]); unset($instance['a']); $this->assertToArray([], $instance); } public function testArrayAccessUnsetByReference() { - $instance = $this->getInstance(['a' => [1]]); + $instance = static::getInstance(['a' => [1]]); unset($instance['a'][0]); $this->assertToArray(['a' => []], $instance); diff --git a/tests/Map/_var_dump.php b/tests/Map/_var_dump.php index 5f6f6a5..7a0e61c 100644 --- a/tests/Map/_var_dump.php +++ b/tests/Map/_var_dump.php @@ -1,11 +1,13 @@ getInstance($values); + $instance = static::getInstance($values); $this->assertInstanceDump($expected, $instance); } } diff --git a/tests/Map/allocate.php b/tests/Map/allocate.php index 1da4801..e75f9f8 100644 --- a/tests/Map/allocate.php +++ b/tests/Map/allocate.php @@ -1,9 +1,11 @@ getInstance(); + $instance = static::getInstance(); $instance->allocate($initial); $instance->allocate($allocate); diff --git a/tests/Map/apply.php b/tests/Map/apply.php index ff76fe3..86ed868 100644 --- a/tests/Map/apply.php +++ b/tests/Map/apply.php @@ -1,9 +1,11 @@ getInstance($values); + $instance = static::getInstance($values); $instance->apply($callback); $expected = array_map($callback, array_keys($values), $values); @@ -27,7 +27,7 @@ public function testApply(array $values, callable $callback) public function testApplyCallbackThrowsException() { - $instance = $this->getInstance([1, 2, 3]); + $instance = static::getInstance([1, 2, 3]); try { $instance->apply(function($value) { @@ -43,7 +43,7 @@ public function testApplyCallbackThrowsException() public function testApplyCallbackThrowsExceptionLaterOn() { - $instance = $this->getInstance([1, 2, 3]); + $instance = static::getInstance([1, 2, 3]); try { $instance->apply(function($key, $value) { @@ -63,7 +63,7 @@ public function testApplyCallbackThrowsExceptionLaterOn() public function testApplyDoesNotLeakWhenCallbackFails() { - $instance = $this->getInstance([ + $instance = static::getInstance([ "a" => new \stdClass(), "b" => new \stdClass(), "c" => new \stdClass(), diff --git a/tests/Map/capacity.php b/tests/Map/capacity.php index 4b3bae2..fef5f48 100644 --- a/tests/Map/capacity.php +++ b/tests/Map/capacity.php @@ -9,7 +9,7 @@ public function testCapacity() { $min = Map::MIN_CAPACITY; - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->assertEquals($min, $instance->capacity()); for ($i = 0; $i < $min; $i++) { @@ -44,7 +44,7 @@ public function testAutoTruncate() 0 => 8, ]; - $instance = $this->getInstance(range(1, array_keys($boundaries)[0])); + $instance = static::getInstance(range(1, array_keys($boundaries)[0])); for(;;) { if ( ! is_null(($expected = $boundaries[$instance->count()] ?? null))) { @@ -61,7 +61,7 @@ public function testAutoTruncate() public function testClearResetsCapacity() { - $instance = $this->getInstance(range(1, self::MANY)); + $instance = static::getInstance(range(1, self::MANY)); $instance->clear(); $this->assertEquals(Map::MIN_CAPACITY, $instance->capacity()); } diff --git a/tests/Map/clear.php b/tests/Map/clear.php index 50c975e..bc76749 100644 --- a/tests/Map/clear.php +++ b/tests/Map/clear.php @@ -5,7 +5,7 @@ trait clear { public function testClear() { - $instance = $this->getInstance($this->sample()); + $instance = static::getInstance(self::sample()); $instance->clear(); $this->assertToArray([], $instance); diff --git a/tests/Map/copy.php b/tests/Map/copy.php index 06cda7b..d2a8f77 100644 --- a/tests/Map/copy.php +++ b/tests/Map/copy.php @@ -1,14 +1,14 @@ getInstance($values); + $instance = static::getInstance($values); $copy = $instance->copy(); $this->assertEquals($instance->toArray(), $copy->toArray()); diff --git a/tests/Map/count.php b/tests/Map/count.php index 75ae53c..737ca0b 100644 --- a/tests/Map/count.php +++ b/tests/Map/count.php @@ -5,13 +5,13 @@ trait count { public function testCount() { - $instance = $this->getInstance($this->sample()); - $this->assertCount(count($this->sample()), $instance); + $instance = static::getInstance(self::sample()); + $this->assertCount(count(self::sample()), $instance); } public function testCountEmpty() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->assertCount(0, $instance); } } diff --git a/tests/Map/diff.php b/tests/Map/diff.php index 3c2d88a..23299b1 100644 --- a/tests/Map/diff.php +++ b/tests/Map/diff.php @@ -1,9 +1,11 @@ getInstance($a); - $b = $this->getInstance($b); + $a = static::getInstance($a); + $b = static::getInstance($b); $this->assertEquals($expected, $a->diff($b)->toArray()); } - /** - * @dataProvider diffDataProvider - */ + #[DataProvider('diffDataProvider')] public function testDiffWithSelf(array $a, array $b, array $expected) { - $map = $this->getInstance($a); + $map = static::getInstance($a); $this->assertEquals([], $map->diff($map)->toArray()); } diff --git a/tests/Map/filter.php b/tests/Map/filter.php index 7b7bd72..08d3b7c 100644 --- a/tests/Map/filter.php +++ b/tests/Map/filter.php @@ -1,9 +1,11 @@ getInstance($values); + $instance = static::getInstance($values); $filtered = $instance->filter($callback); @@ -35,7 +35,7 @@ public function testFilter(array $values, callable $callback, array $expected) public function testFilterCallbackThrowsException() { - $instance = $this->getInstance([1, 2, 3]); + $instance = static::getInstance([1, 2, 3]); $filtered = null; try { @@ -53,7 +53,7 @@ public function testFilterCallbackThrowsException() public function testFilterCallbackThrowsExceptionLaterOn() { - $instance = $this->getInstance([1, 2, 3]); + $instance = static::getInstance([1, 2, 3]); $filtered = null; try { @@ -73,7 +73,7 @@ public function testFilterCallbackThrowsExceptionLaterOn() public function testFilterDoesNotLeakWhenCallbackFails() { - $instance = $this->getInstance([ + $instance = static::getInstance([ "a" => new \stdClass(), "b" => new \stdClass(), "c" => new \stdClass(), @@ -99,7 +99,7 @@ public function testFilterWithoutCallable() "f" => 0, ]; - $instance = $this->getInstance($values); + $instance = static::getInstance($values); $this->assertToArray(array_filter($values), $instance->filter()); } } diff --git a/tests/Map/first.php b/tests/Map/first.php index 75cdde4..3167279 100644 --- a/tests/Map/first.php +++ b/tests/Map/first.php @@ -1,9 +1,11 @@ getInstance($initial); + $instance = static::getInstance($initial); $first = $instance->first(); $this->assertEquals($expected, [$first->key, $first->value]); @@ -26,7 +26,7 @@ public function testFirst(array $initial, $expected) public function testFirstNowAllowedWhenEmpty() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->expectEmptyNotAllowedException(); $instance->first(); } diff --git a/tests/Map/get.php b/tests/Map/get.php index b6158f3..7cf8319 100644 --- a/tests/Map/get.php +++ b/tests/Map/get.php @@ -1,9 +1,11 @@ getInstance($initial); + $instance = static::getInstance($initial); $this->assertEquals($expected, $instance->get($key)); } public function testGetDefault() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->assertEquals('a', $instance->get('?', 'a')); } public function testGetKeyNotFound() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->expectKeyNotFoundException(); $instance->get('?'); } public function testArrayAccessGet() { - $instance = $this->getInstance(['a' => 1]); + $instance = static::getInstance(['a' => 1]); $this->assertEquals(1, $instance['a']); } public function testArrayAccessGetByMethod() { - $instance = $this->getInstance(['a' => 1]); + $instance = static::getInstance(['a' => 1]); $this->assertEquals(1, $instance->offsetGet('a')); } public function testArrayAccessGetByReference() { - $instance = $this->getInstance(['a' => [1]]); + $instance = static::getInstance(['a' => [1]]); $this->assertEquals(1, $instance['a'][0]); } public function testArrayAccessGetKeyNotFound() { - $instance = $this->getInstance(['a' => 1]); + $instance = static::getInstance(['a' => 1]); $this->expectKeyNotFoundException(); $instance['b']; } public function testArrayAccessGetNullCoalesce() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $obj = new \stdClass; diff --git a/tests/Map/hasKey.php b/tests/Map/hasKey.php index 6c5eff5..9e1972b 100644 --- a/tests/Map/hasKey.php +++ b/tests/Map/hasKey.php @@ -1,9 +1,11 @@ getInstance($initial); + $instance = static::getInstance($initial); $this->assertEquals($has, $instance->hasKey($key)); } public function testHasKeyAfterRemoveAndPut() { - $instance = $this->getInstance(['a' => 1]); + $instance = static::getInstance(['a' => 1]); $this->assertTrue($instance->hasKey('a')); $instance->remove('a'); diff --git a/tests/Map/hasValue.php b/tests/Map/hasValue.php index 35ad935..39626d5 100644 --- a/tests/Map/hasValue.php +++ b/tests/Map/hasValue.php @@ -1,9 +1,11 @@ getInstance($initial); + $instance = static::getInstance($initial); $this->assertEquals($expected, $instance->hasValue($value)); } public function testHasValueAfterRemoveAndPut() { - $instance = $this->getInstance(['a' => 1]); + $instance = static::getInstance(['a' => 1]); $this->assertTrue($instance->hasValue(1)); $instance->remove('a'); diff --git a/tests/Map/intersect.php b/tests/Map/intersect.php index ad7a967..0ab3f8e 100644 --- a/tests/Map/intersect.php +++ b/tests/Map/intersect.php @@ -1,9 +1,11 @@ getInstance($a); - $b = $this->getInstance($b); + $a = static::getInstance($a); + $b = static::getInstance($b); $this->assertEquals($expected, $a->intersect($b)->toArray()); } - /** - * @dataProvider intersectDataProvider - */ + #[DataProvider('intersectDataProvider')] public function testIntersectWithSelf(array $a, array $b, array $expected) { - $map = $this->getInstance($a); + $map = static::getInstance($a); $this->assertEquals($a, $map->intersect($map)->toArray()); } diff --git a/tests/Map/isEmpty.php b/tests/Map/isEmpty.php index 93da609..d636de0 100644 --- a/tests/Map/isEmpty.php +++ b/tests/Map/isEmpty.php @@ -1,9 +1,11 @@ getInstance($values); + $instance = static::getInstance($values); $this->assertEquals($isEmpty, $instance->isEmpty()); } public function testIsNotEmptyAfterRemove() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->assertTrue($instance->isEmpty()); $instance->put('a', 1); diff --git a/tests/Map/keys.php b/tests/Map/keys.php index 8f020cb..e084c2d 100644 --- a/tests/Map/keys.php +++ b/tests/Map/keys.php @@ -1,9 +1,11 @@ getInstance($initial); + $instance = static::getInstance($initial); $keys = $instance->keys(); $this->assertInstanceOf(\Ds\Set::class, $keys); diff --git a/tests/Map/ksort.php b/tests/Map/ksort.php index 3b18817..5e78870 100644 --- a/tests/Map/ksort.php +++ b/tests/Map/ksort.php @@ -1,9 +1,11 @@ getInstance($values); + $instance = static::getInstance($values); $expected = $values; ksort($expected); @@ -38,12 +38,10 @@ public function testSortByKey(array $values) $this->assertToArray($expected, $instance); } - /** - * @dataProvider sortKeyDataProvider - */ + #[DataProvider('sortKeyDataProvider')] public function testSortByKeyUsingComparator(array $values) { - $instance = $this->getInstance($values); + $instance = static::getInstance($values); $instance->ksort(function($a, $b) { return $b <=> $a; diff --git a/tests/Map/ksorted.php b/tests/Map/ksorted.php index dc1ef42..9e14b3b 100644 --- a/tests/Map/ksorted.php +++ b/tests/Map/ksorted.php @@ -1,9 +1,11 @@ getInstance($values); + $instance = static::getInstance($values); $expected = $values; ksort($expected); @@ -38,12 +38,10 @@ public function testSortedByKey(array $values) $this->assertToArray($values, $instance); } - /** - * @dataProvider sortKeyDataProvider - */ + #[DataProvider('sortKeyDataProvider')] public function testSortedByKeyUsingComparator(array $values) { - $instance = $this->getInstance($values); + $instance = static::getInstance($values); $sorted = $instance->ksorted(function($a, $b) { return $b <=> $a; diff --git a/tests/Map/last.php b/tests/Map/last.php index aeed3bb..0283d6b 100644 --- a/tests/Map/last.php +++ b/tests/Map/last.php @@ -1,9 +1,11 @@ getInstance($initial); + $instance = static::getInstance($initial); $last = $instance->last(); $this->assertEquals($expected, [$last->key, $last->value]); @@ -26,7 +26,7 @@ public function testLast($initial, $expected) public function testLastNotAllowedWhenEmpty() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->expectEmptyNotAllowedException(); $instance->last(); } diff --git a/tests/Map/map.php b/tests/Map/map.php index 1e86cda..19fb832 100644 --- a/tests/Map/map.php +++ b/tests/Map/map.php @@ -1,9 +1,11 @@ getInstance($values); + $instance = static::getInstance($values); $mapped = $instance->map($callback); $expected = array_map($callback, array_keys($values), $values); @@ -33,7 +33,7 @@ public function testMap(array $values, callable $callback) public function testMapPreservesKeys() { - $instance = $this->getInstance(["speed" => 5]); + $instance = static::getInstance(["speed" => 5]); $mapped = $instance->map(function ($key, $value) { return $value * 2; @@ -44,7 +44,7 @@ public function testMapPreservesKeys() public function testMapCallbackThrowsException() { - $instance = $this->getInstance([1, 2, 3]); + $instance = static::getInstance([1, 2, 3]); $mapped = null; try { @@ -62,7 +62,7 @@ public function testMapCallbackThrowsException() public function testMapCallbackThrowsExceptionLaterOn() { - $instance = $this->getInstance([1, 2, 3]); + $instance = static::getInstance([1, 2, 3]); $mapped = null; try { @@ -82,7 +82,7 @@ public function testMapCallbackThrowsExceptionLaterOn() public function testMapDoesNotLeakWhenCallbackFails() { - $instance = $this->getInstance([ + $instance = static::getInstance([ "a" => new \stdClass(), "b" => new \stdClass(), "c" => new \stdClass(), diff --git a/tests/Map/merge.php b/tests/Map/merge.php index 2dae7cd..d195817 100644 --- a/tests/Map/merge.php +++ b/tests/Map/merge.php @@ -1,9 +1,11 @@ getInstance($initial); + $instance = static::getInstance($initial); $this->assertToArray($expected, $instance->merge($values)); $this->assertToArray($initial, $instance); } - /** - * @dataProvider mergeDataProvider - */ + #[DataProvider('mergeDataProvider')] public function testMergeWithSelf(array $initial, array $values, array $expected) { - $instance = $this->getInstance($initial); + $instance = static::getInstance($initial); $this->assertToArray($initial, $instance->merge($instance)); $this->assertToArray($initial, $instance); diff --git a/tests/Map/pairs.php b/tests/Map/pairs.php index 87771f0..584c5d4 100644 --- a/tests/Map/pairs.php +++ b/tests/Map/pairs.php @@ -1,11 +1,13 @@ getInstance($initial); + $instance = static::getInstance($initial); $pairs = $instance->pairs(); $this->assertInstanceOf(Vector::class, $pairs); @@ -35,7 +35,7 @@ public function testObjectsAreMutableThroughAccess() $key = new \stdClass(); $key->state = true; - $instance = $this->getInstance(); + $instance = static::getInstance(); $instance->put($key, 1); $instance->pairs()->first()->key->state = false; @@ -46,7 +46,7 @@ public function testObjectsAreMutableThroughAccess() public function testKeysAreNotMutableThroughAccess() { - $instance = $this->getInstance(['a' => 1, 'b' => 2]); + $instance = static::getInstance(['a' => 1, 'b' => 2]); $instance->pairs()->first()->key = 'c'; $this->assertEquals('a', $instance->pairs()->first()->key); diff --git a/tests/Map/put.php b/tests/Map/put.php index b6d52d6..bc81875 100644 --- a/tests/Map/put.php +++ b/tests/Map/put.php @@ -1,11 +1,13 @@ getInstance(); + $instance = static::getInstance(); foreach ($pairs as $pair) { $instance->put($pair[0], $pair[1]); @@ -75,7 +75,7 @@ public function testPut(array $pairs, array $expected) public function testPutMany() { - $instance = $this->getInstance(); + $instance = static::getInstance(); for ($i = 0; $i < self::MANY; $i++) { $instance->put(rand(), rand()); @@ -85,9 +85,7 @@ public function testPutMany() $this->assertEquals(self::MANY, count($instance->toArray())); } - /** - * @dataProvider putHashableDataProvider - */ + #[DataProvider('putHashableDataProvider')] public function testPutHashable(array $pairs, array $expected) { $this->testPut($pairs, $expected); @@ -95,21 +93,21 @@ public function testPutHashable(array $pairs, array $expected) public function testArrayAccessPut() { - $instance = $this->getInstance(['a' => 1]); + $instance = static::getInstance(['a' => 1]); $instance['a'] = 2; $this->assertToArray(['a' => 2], $instance); } public function testArrayAccessPutByMethod() { - $instance = $this->getInstance(['a' => 1]); + $instance = static::getInstance(['a' => 1]); $instance->offsetSet('a', 2); $this->assertToArray(['a' => 2], $instance); } public function testArrayAccessPutByReference() { - $instance = $this->getInstance(['a' => [1]]); + $instance = static::getInstance(['a' => [1]]); $instance['a'][0] = 2; $this->assertToArray(['a' => [2]], $instance); @@ -117,8 +115,8 @@ public function testArrayAccessPutByReference() public function testMapPutCircularReference() { - $a = $this->getInstance(); - $b = $this->getInstance(); + $a = static::getInstance(); + $b = static::getInstance(); $a->put("B", $b); $a->put("A", $a); @@ -131,7 +129,7 @@ public function testMapPutCircularReference() public function testPutKeyAsReference() { - $map = $this->getInstance(); + $map = static::getInstance(); $key = ['a']; $ref = &$key; @@ -159,7 +157,7 @@ public function testPutKeyAsReference() public function testArrayAccessPutKeyAsReference() { - $map = $this->getInstance(); + $map = static::getInstance(); $key = ['a']; $ref = &$key; diff --git a/tests/Map/putAll.php b/tests/Map/putAll.php index 5eec34d..dfc3e03 100644 --- a/tests/Map/putAll.php +++ b/tests/Map/putAll.php @@ -1,9 +1,11 @@ sample()], + [self::sample()], [range(1, self::MANY)], ]; } - /** - * @dataProvider putAllDataProvider - */ + #[DataProvider('putAllDataProvider')] public function testPutAll(array $values) { - $instance = $this->getInstance(); + $instance = static::getInstance(); $instance->putAll($values); $this->assertToArray($values, $instance); } - /** - * @dataProvider putAllDataProvider - */ + #[DataProvider('putAllDataProvider')] public function testPutAllUsingIterator(array $values) { - $instance = $this->getInstance(); + $instance = static::getInstance(); $instance->putAll(new \ArrayIterator($values)); $this->assertToArray($values, $instance); } - /** - * @dataProvider putAllDataProvider - */ + #[DataProvider('putAllDataProvider')] public function testPutAllFromSet(array $values) { - $instance = $this->getInstance(); + $instance = static::getInstance(); $set = new \Ds\Set($values); $instance->putAll($set); $this->assertToArray($values, $instance); } - /** - * @dataProvider putAllDataProvider - */ + #[DataProvider('putAllDataProvider')] public function testPutAllFromMap(array $values) { - $instance = $this->getInstance(); + $instance = static::getInstance(); $map = new \Ds\Map($values); $instance->putAll($map); $this->assertToArray($values, $instance); } - /** - * @dataProvider putAllDataProvider - */ + #[DataProvider('putAllDataProvider')] public function testPutAllFromVector(array $values) { - $instance = $this->getInstance(); + $instance = static::getInstance(); $vector = new \Ds\Vector($values); $instance->putAll($vector); $this->assertToArray($values, $instance); } - /** - * @dataProvider putAllDataProvider - */ + #[DataProvider('putAllDataProvider')] public function testPutAllFromDeque(array $values) { - $instance = $this->getInstance(); + $instance = static::getInstance(); $deque = new \Ds\Deque($values); $instance->putAll($deque); $this->assertToArray($values, $instance); } - /** - * @dataProvider putAllDataProvider - */ + #[DataProvider('putAllDataProvider')] public function testPutAllFromStack(array $values) { - $instance = $this->getInstance(); + $instance = static::getInstance(); $stack = new \Ds\Stack(array_reverse($values)); $instance->putAll($stack); $this->assertToArray($values, $instance); $this->assertCount(0, $stack); } - /** - * @dataProvider putAllDataProvider - */ + #[DataProvider('putAllDataProvider')] public function testPutAllFromQueue(array $values) { - $instance = $this->getInstance(); + $instance = static::getInstance(); $queue = new \Ds\Queue($values); $instance->putAll($queue); $this->assertToArray($values, $instance); $this->assertCount(0, $queue); } - /** - * @dataProvider putAllDataProvider - */ + #[DataProvider('putAllDataProvider')] public function testPutAllFromPriorityQueue(array $values) { - $instance = $this->getInstance(); + $instance = static::getInstance(); $queue = new \Ds\PriorityQueue(); foreach ($values as $value) { diff --git a/tests/Map/reduce.php b/tests/Map/reduce.php index 59fad80..e44c55b 100644 --- a/tests/Map/reduce.php +++ b/tests/Map/reduce.php @@ -1,9 +1,11 @@ getInstance($values); + $instance = static::getInstance($values); $reduced = $instance->reduce($callback, $initial); @@ -75,12 +75,10 @@ public function testReduce(array $values, $initial, callable $callback, $expecte $this->assertEquals($expected, $reduced); } - /** - * @dataProvider reduceWithoutInitialDataProvider - */ + #[DataProvider('reduceWithoutInitialDataProvider')] public function testReduceWithoutInitial(array $values, callable $callback, $expected) { - $instance = $this->getInstance($values); + $instance = static::getInstance($values); $reduced = $instance->reduce($callback); @@ -90,7 +88,7 @@ public function testReduceWithoutInitial(array $values, callable $callback, $exp public function testReduceCallbackThrowsException() { - $instance = $this->getInstance([1, 2, 3]); + $instance = static::getInstance([1, 2, 3]); $result = null; try { @@ -108,7 +106,7 @@ public function testReduceCallbackThrowsException() public function testReduceCallbackThrowsExceptionLaterOn() { - $instance = $this->getInstance([1, 2, 3]); + $instance = static::getInstance([1, 2, 3]); $result = null; try { diff --git a/tests/Map/remove.php b/tests/Map/remove.php index 303be6c..eb71a34 100644 --- a/tests/Map/remove.php +++ b/tests/Map/remove.php @@ -1,11 +1,13 @@ testRemove($initial, $key, $expected, $result); @@ -45,7 +45,7 @@ public function testRemoveHashable(array $initial, $key, $expected, array $resul public function testRemoveAllFromFront() { - $instance = $this->getInstance(); + $instance = static::getInstance(); for ($i = 0; $i < self::MANY; $i++) { $instance->put($i, $i); @@ -62,7 +62,7 @@ public function testRemoveAllFromFront() public function testRemoveHalfFromMidway() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $size = self::MANY + (self::MANY & 1); // Force even $half = intdiv($size, 2); @@ -80,7 +80,7 @@ public function testRemoveHalfFromMidway() public function testRandomRemove() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $reference = []; for ($i = 0; $i < 10; $i++) { @@ -105,12 +105,10 @@ public function testRandomRemove() $this->assertToArray($reference, $instance); } - /** - * @dataProvider removeDataProvider - */ + #[DataProvider('removeDataProvider')] public function testRemove(array $initial, $key, $expected, array $result) { - $instance = $this->getInstance(); + $instance = static::getInstance(); foreach ($initial as $pair) { $instance->put($pair[0], $pair[1]); @@ -122,13 +120,13 @@ public function testRemove(array $initial, $key, $expected, array $result) public function testRemoveDefault() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->assertEquals('a', $instance->remove('?', 'a')); } public function testRemoveKeyNotFound() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->expectKeyNotFoundException(); $instance->remove('?'); } diff --git a/tests/Map/reverse.php b/tests/Map/reverse.php index 92204cf..c850f6c 100644 --- a/tests/Map/reverse.php +++ b/tests/Map/reverse.php @@ -1,23 +1,23 @@ basicDataProvider()); + return array_map($reverse, self::basicDataProvider()); } - /** - * @dataProvider reverseDataProvider - */ + #[DataProvider('reverseDataProvider')] public function testReverse(array $values, array $expected) { - $instance = $this->getInstance($values); + $instance = static::getInstance($values); $instance->reverse(); $this->assertToArray($expected, $instance); diff --git a/tests/Map/reversed.php b/tests/Map/reversed.php index e90e4d8..e469e9b 100644 --- a/tests/Map/reversed.php +++ b/tests/Map/reversed.php @@ -1,23 +1,23 @@ basicDataProvider()); + return array_map($reverse, self::basicDataProvider()); } - /** - * @dataProvider reversedDataProvider - */ + #[DataProvider('reversedDataProvider')] public function testReversed(array $values, array $expected) { - $instance = $this->getInstance($values); + $instance = static::getInstance($values); $this->assertToArray($expected, $instance->reversed()); } } diff --git a/tests/Map/skip.php b/tests/Map/skip.php index f015ec4..55bcb61 100644 --- a/tests/Map/skip.php +++ b/tests/Map/skip.php @@ -1,9 +1,11 @@ getInstance($values); + $instance = static::getInstance($values); $pair = $instance->skip($position); $this->assertEquals($expected, [$pair->key, $pair->value]); } - /** - * @dataProvider skipOutOfRangeDataProvider - */ + #[DataProvider('skipOutOfRangeDataProvider')] public function testSkipIndexOutOfRange(array $values, int $position) { $this->expectIndexOutOfRangeException(); - $instance = $this->getInstance($values); + $instance = static::getInstance($values); $instance->skip($position); } } diff --git a/tests/Map/slice.php b/tests/Map/slice.php index 149e767..b36e5ba 100644 --- a/tests/Map/slice.php +++ b/tests/Map/slice.php @@ -1,9 +1,11 @@ getInstance($values); + $instance = static::getInstance($values); $sliced = $instance->slice($index, $length); $expected = array_slice($values, $index, $length, true); @@ -34,12 +34,10 @@ public function testSlice(array $values, int $index, int $length) $this->assertToArray($expected, $sliced); } - /** - * @dataProvider sliceDataProvider - */ + #[DataProvider('sliceDataProvider')] public function testSliceWithoutLength(array $values, int $index, int $length) { - $instance = $this->getInstance($values); + $instance = static::getInstance($values); $sliced = $instance->slice($index); $expected = array_slice($values, $index, null, true); @@ -48,12 +46,10 @@ public function testSliceWithoutLength(array $values, int $index, int $length) $this->assertToArray($expected, $sliced); } - /** - * @dataProvider sliceDataProvider - */ + #[DataProvider('sliceDataProvider')] public function testSliceWithLengthNull(array $values, int $index, int $length) { - $instance = $this->getInstance($values); + $instance = static::getInstance($values); $sliced = $instance->slice($index, null); $expected = array_slice($values, $index, null, true); @@ -64,7 +60,7 @@ public function testSliceWithLengthNull(array $values, int $index, int $length) public function testSliceAfterRemoveOutsideOfSlice() { - $instance = $this->getInstance(['a', 'b', 'c', 'd', 'e']); + $instance = static::getInstance(['a', 'b', 'c', 'd', 'e']); $instance->remove(3); // d $this->assertToArray(['a', 'b', 'c'], $instance->slice(0, 3)); @@ -72,7 +68,7 @@ public function testSliceAfterRemoveOutsideOfSlice() public function testSliceAfterRemoveAtStartOfSlice() { - $instance = $this->getInstance(['a', 'b', 'c', 'd', 'e']); + $instance = static::getInstance(['a', 'b', 'c', 'd', 'e']); $instance->remove(1); // b $this->assertToArray([ @@ -84,7 +80,7 @@ public function testSliceAfterRemoveAtStartOfSlice() public function testSliceAfterRemoveWithinSlice() { - $instance = $this->getInstance(['a', 'b', 'c', 'd', 'e']); + $instance = static::getInstance(['a', 'b', 'c', 'd', 'e']); $instance->remove(2); // c $this->assertToArray([ diff --git a/tests/Map/sort.php b/tests/Map/sort.php index 473459a..67be7b1 100644 --- a/tests/Map/sort.php +++ b/tests/Map/sort.php @@ -1,9 +1,11 @@ getInstance($values); + $instance = static::getInstance($values); $expected = array_slice($values, 0, count($values), true); asort($expected); @@ -38,12 +38,10 @@ public function testSort(array $values) $this->assertToArray($expected, $instance); } - /** - * @dataProvider sortDataProvider - */ + #[DataProvider('sortDataProvider')] public function testSortUsingComparator(array $values) { - $instance = $this->getInstance($values); + $instance = static::getInstance($values); $expected = array_slice($values, 0, count($values), true); arsort($expected); diff --git a/tests/Map/sorted.php b/tests/Map/sorted.php index 671c02b..4391543 100644 --- a/tests/Map/sorted.php +++ b/tests/Map/sorted.php @@ -1,9 +1,11 @@ getInstance($values); + $instance = static::getInstance($values); $expected = array_slice($values, 0, count($values), true); asort($expected); @@ -38,12 +38,10 @@ public function testSorted(array $values) $this->assertToArray($values, $instance); } - /** - * @dataProvider sortedDataProvider - */ + #[DataProvider('sortedDataProvider')] public function testSortedUsingComparator(array $values) { - $instance = $this->getInstance($values); + $instance = static::getInstance($values); $sorted = $instance->sorted(function($a, $b) { return $b <=> $a; diff --git a/tests/Map/sum.php b/tests/Map/sum.php index fd9e0dc..3125cb9 100644 --- a/tests/Map/sum.php +++ b/tests/Map/sum.php @@ -1,9 +1,11 @@ =') ? [true, false, null] : ["a", true, false, null]; return [ @@ -28,12 +30,10 @@ public function sumDataProvider() ]; } - /** - * @dataProvider sumDataProvider - */ + #[DataProvider('sumDataProvider')] public function testSum($values, $expected) { - $instance = $this->getInstance($values); + $instance = static::getInstance($values); $this->assertEquals($expected, $instance->sum()); } } diff --git a/tests/Map/toArray.php b/tests/Map/toArray.php index ea83264..3ac0a4f 100644 --- a/tests/Map/toArray.php +++ b/tests/Map/toArray.php @@ -5,7 +5,7 @@ trait toArray { public function testToArrayWithBadKey() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $instance->put(new \stdClass(), 1); $this->expectInternalIllegalOffset(); diff --git a/tests/Map/union.php b/tests/Map/union.php index a382778..28d6418 100644 --- a/tests/Map/union.php +++ b/tests/Map/union.php @@ -1,9 +1,11 @@ getInstance($initial); - $other = $this->getInstance($values); + $instance = static::getInstance($initial); + $other = static::getInstance($values); $this->assertToArray($expected, $instance->union($other)); $this->assertToArray($initial, $instance); } - /** - * @dataProvider unionDataProvider - */ + #[DataProvider('unionDataProvider')] public function testUnionWithSelf(array $initial, array $values, array $expected) { - $instance = $this->getInstance($initial); + $instance = static::getInstance($initial); $this->assertToArray($initial, $instance->union($instance)); $this->assertToArray($initial, $instance); diff --git a/tests/Map/values.php b/tests/Map/values.php index 0afee57..ae7ec18 100644 --- a/tests/Map/values.php +++ b/tests/Map/values.php @@ -1,11 +1,13 @@ getInstance($initial); + $instance = static::getInstance($initial); $values = $instance->values(); $this->assertInstanceOf(Vector::class, $values); diff --git a/tests/Map/xor_.php b/tests/Map/xor_.php index 6f79e10..6a88865 100644 --- a/tests/Map/xor_.php +++ b/tests/Map/xor_.php @@ -1,9 +1,11 @@ getInstance($a); - $b = $this->getInstance($b); + $a = static::getInstance($a); + $b = static::getInstance($b); $this->assertEquals($expected, $a->xor($b)->toArray()); } - /** - * @dataProvider xorDataProvider - */ + #[DataProvider('xorDataProvider')] public function testXorWithSelf(array $a, array $b, array $expected) { - $map = $this->getInstance($a); + $map = static::getInstance($a); $this->assertEquals([], $map->xor($map)->toArray()); } diff --git a/tests/MapTest.php b/tests/MapTest.php index af075e6..1a0900e 100644 --- a/tests/MapTest.php +++ b/tests/MapTest.php @@ -4,7 +4,7 @@ use ArrayAccess; use Ds\Vector; -class MapTest extends CollectionTest +class MapTest extends CollectionTestCase { use Map\__construct; use Map\_clone; @@ -54,14 +54,14 @@ class MapTest extends CollectionTest use Map\values; use Map\xor_; - public function getInstance(array $values = []) + public static function getInstance(array $values = []) { return new \Ds\Map($values); } public function testCollisionChain() { - $instance = $this->getInstance(); + $instance = static::getInstance(); // We want to add three distinct values with the same hash mod. $instance->put( 3, 'a'); @@ -75,7 +75,7 @@ public function testCollisionChain() public function testCollisionChainAcrossResize() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $n = 64; @@ -90,7 +90,7 @@ public function testCollisionChainAcrossResize() public function testNonPackedRehash() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $instance->put( 3, 'a'); $instance->put(11, 'b'); @@ -114,7 +114,7 @@ public function testNonPackedRehash() public function testPutAfterRemove() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $instance->put(1, 1); $instance->put(2, 2); @@ -126,7 +126,7 @@ public function testPutAfterRemove() public function testRandomPutAndRemove() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $reference = []; for ($i = 0; $i < self::MANY; $i++) { @@ -151,7 +151,7 @@ public function testRandomPutAndRemove() public function testAlternatingPutAndRemove() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $reference = []; for ($i = 0; $i < self::MANY; $i++) { @@ -174,7 +174,7 @@ public function testAlternatingPutAndRemove() public function testImplementsArrayAccess() { - $this->assertInstanceOf(ArrayAccess::class, $this->getInstance()); + $this->assertInstanceOf(ArrayAccess::class, static::getInstance()); } /** @@ -183,8 +183,8 @@ public function testImplementsArrayAccess() public function testIssue200() { static::expectNotToPerformAssertions(); - $map = $this->getInstance(); - $map->put('#200', $this->getInstance()); + $map = static::getInstance(); + $map->put('#200', static::getInstance()); $map->keys()->merge($map->keys()); } } diff --git a/tests/PairTest.php b/tests/PairTest.php index edf8732..acfb7fe 100644 --- a/tests/PairTest.php +++ b/tests/PairTest.php @@ -1,7 +1,7 @@ getInstance($values); + $instance = static::getInstance($values); $clone = clone $instance; diff --git a/tests/PriorityQueue/_echo.php b/tests/PriorityQueue/_echo.php index 379b595..70063de 100644 --- a/tests/PriorityQueue/_echo.php +++ b/tests/PriorityQueue/_echo.php @@ -5,6 +5,6 @@ trait _echo { public function testEcho() { - $this->assertInstanceToString($this->getInstance()); + $this->assertInstanceToString(static::getInstance()); } } diff --git a/tests/PriorityQueue/_empty.php b/tests/PriorityQueue/_empty.php index 1e9045c..ef3c88e 100644 --- a/tests/PriorityQueue/_empty.php +++ b/tests/PriorityQueue/_empty.php @@ -5,7 +5,7 @@ trait _empty { public function testArrayAccessEmpty() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->expectArrayAccessUnsupportedException(); empty($instance['?']); } diff --git a/tests/PriorityQueue/_foreach.php b/tests/PriorityQueue/_foreach.php index 35e4b71..18d8b87 100644 --- a/tests/PriorityQueue/_foreach.php +++ b/tests/PriorityQueue/_foreach.php @@ -5,7 +5,7 @@ trait _foreach { public function testForEach() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $instance->push('a', 1); $instance->push('c', 3); diff --git a/tests/PriorityQueue/_isset.php b/tests/PriorityQueue/_isset.php index 5e2e266..9099a2f 100644 --- a/tests/PriorityQueue/_isset.php +++ b/tests/PriorityQueue/_isset.php @@ -5,7 +5,7 @@ trait _isset { public function testArrayAccessIsset() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->expectArrayAccessUnsupportedException(); isset($instance['?']); } diff --git a/tests/PriorityQueue/_jsonEncode.php b/tests/PriorityQueue/_jsonEncode.php index 6ddbae6..da79639 100644 --- a/tests/PriorityQueue/_jsonEncode.php +++ b/tests/PriorityQueue/_jsonEncode.php @@ -1,14 +1,14 @@ getInstance($initial); + $instance = static::getInstance($initial); $this->assertEquals(json_encode($expected), json_encode($instance)); } } diff --git a/tests/PriorityQueue/_serialize.php b/tests/PriorityQueue/_serialize.php index 4a1cdb1..9b5e098 100644 --- a/tests/PriorityQueue/_serialize.php +++ b/tests/PriorityQueue/_serialize.php @@ -1,9 +1,11 @@ getInstance($values); + $instance = static::getInstance($values); $this->assertSerialized($expected, $instance, true); } } diff --git a/tests/PriorityQueue/_unset.php b/tests/PriorityQueue/_unset.php index afbd8a7..defe43f 100644 --- a/tests/PriorityQueue/_unset.php +++ b/tests/PriorityQueue/_unset.php @@ -5,7 +5,7 @@ trait _unset { public function testArrayAccessUnset() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->expectArrayAccessUnsupportedException(); unset($instance['?']); } diff --git a/tests/PriorityQueue/_var_dump.php b/tests/PriorityQueue/_var_dump.php index 02d2373..0714b19 100644 --- a/tests/PriorityQueue/_var_dump.php +++ b/tests/PriorityQueue/_var_dump.php @@ -1,14 +1,14 @@ getInstance($values); + $instance = static::getInstance($values); $this->assertInstanceDump($expected, $instance); } } diff --git a/tests/PriorityQueue/allocate.php b/tests/PriorityQueue/allocate.php index c478ea1..187d503 100644 --- a/tests/PriorityQueue/allocate.php +++ b/tests/PriorityQueue/allocate.php @@ -1,9 +1,11 @@ getInstance(); + $instance = static::getInstance(); $instance->allocate($initial); $instance->allocate($allocate); diff --git a/tests/PriorityQueue/capacity.php b/tests/PriorityQueue/capacity.php index 2dfdefe..cf3aec4 100644 --- a/tests/PriorityQueue/capacity.php +++ b/tests/PriorityQueue/capacity.php @@ -9,7 +9,7 @@ public function testCapacity() { $min = PriorityQueue::MIN_CAPACITY; - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->assertEquals($min, $instance->capacity()); for ($i = 0; $i < $min; $i++) { @@ -44,7 +44,7 @@ public function testAutoTruncate() 0 => 8, ]; - $instance = $this->getInstance(); + $instance = static::getInstance(); foreach (range(1, array_keys($boundaries)[0]) as $value) { $instance->push($value, 1); @@ -65,7 +65,7 @@ public function testAutoTruncate() public function testClearResetsCapacity() { - $instance = $this->getInstance(range(1, self::MANY)); + $instance = static::getInstance(range(1, self::MANY)); $instance->clear(); $this->assertEquals(PriorityQueue::MIN_CAPACITY, $instance->capacity()); } diff --git a/tests/PriorityQueue/clear.php b/tests/PriorityQueue/clear.php index 1438807..6c104c3 100644 --- a/tests/PriorityQueue/clear.php +++ b/tests/PriorityQueue/clear.php @@ -5,7 +5,7 @@ trait clear { public function testClear() { - $instance = $this->getInstance(); + $instance = static::getInstance(); foreach (range(1, self::MANY) as $i) { $instance->push($i, rand()); diff --git a/tests/PriorityQueue/copy.php b/tests/PriorityQueue/copy.php index e66047c..8055763 100644 --- a/tests/PriorityQueue/copy.php +++ b/tests/PriorityQueue/copy.php @@ -1,14 +1,14 @@ getInstance($values); + $instance = static::getInstance($values); $copy = $instance->copy(); $this->assertEquals($instance->toArray(), $copy->toArray()); @@ -17,7 +17,7 @@ public function testCopy(array $values, array $expected) public function testCopyDoesNotAffectSubject() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $instance->push('a', 1); $instance->push('b', 2); $instance->push('c', 3); diff --git a/tests/PriorityQueue/count.php b/tests/PriorityQueue/count.php index 9027ee0..5620288 100644 --- a/tests/PriorityQueue/count.php +++ b/tests/PriorityQueue/count.php @@ -5,7 +5,7 @@ trait count { public function testCount() { - $instance = $this->getInstance(); + $instance = static::getInstance(); foreach (range(1, self::MANY) as $i) { $instance->push($i, rand()); diff --git a/tests/PriorityQueue/isEmpty.php b/tests/PriorityQueue/isEmpty.php index 3c51f5e..b380823 100644 --- a/tests/PriorityQueue/isEmpty.php +++ b/tests/PriorityQueue/isEmpty.php @@ -5,7 +5,7 @@ trait isEmpty { public function testIsEmpty() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->assertTrue($instance->isEmpty()); $instance->push('a', 1); diff --git a/tests/PriorityQueue/peek.php b/tests/PriorityQueue/peek.php index e7ce32a..5711dcf 100644 --- a/tests/PriorityQueue/peek.php +++ b/tests/PriorityQueue/peek.php @@ -1,9 +1,11 @@ getInstance($initial); + $instance = static::getInstance($initial); $this->assertEquals($expected, $instance->peek()); $this->assertCount(count($initial), $instance); } public function testPeekNotAllowedWhenEmpty() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->expectEmptyNotAllowedException(); $instance->peek(); } diff --git a/tests/PriorityQueue/pop.php b/tests/PriorityQueue/pop.php index b819afc..9c26184 100644 --- a/tests/PriorityQueue/pop.php +++ b/tests/PriorityQueue/pop.php @@ -1,9 +1,11 @@ getInstance($initial); + $instance = static::getInstance($initial); $this->assertEquals($expected, $instance->pop()); $this->assertToArray($result, $instance); @@ -26,7 +26,7 @@ public function testPop(array $initial, $expected, array $result) public function testPopAll() { - $instance = $this->getInstance(range(1, self::MANY)); + $instance = static::getInstance(range(1, self::MANY)); while ( ! $instance->isEmpty()) { $instance->pop(); @@ -37,7 +37,7 @@ public function testPopAll() public function testPopNowAllowedWhenEmpty() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->expectEmptyNotAllowedException(); $instance->pop(); } diff --git a/tests/PriorityQueue/push.php b/tests/PriorityQueue/push.php index 32c8826..2e32638 100644 --- a/tests/PriorityQueue/push.php +++ b/tests/PriorityQueue/push.php @@ -1,9 +1,11 @@ getInstance($initial); + $instance = static::getInstance($initial); foreach ($values as $value => $priority) { $instance->push($value, (int) $priority); @@ -34,7 +34,7 @@ public function testPush(array $initial, array $values, array $expected) public function testPushIdenticalValues() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $instance->push('a', 1); $instance->push('a', 1); @@ -45,7 +45,7 @@ public function testPushIdenticalValues() public function testPushManyRandom() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $reference = range(1, self::SOME); shuffle($reference); @@ -61,7 +61,7 @@ public function testPushManyRandom() public function testInsertionOrder() { - $instance = $this->getInstance(); + $instance = static::getInstance(); foreach (range(1, self::MANY) as $i) { $instance->push($i, 0); @@ -74,7 +74,7 @@ public function testInsertionOrder() public function testPushCircularReference() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $instance->push($instance, 1); $this->assertToArray([$instance], $instance); } diff --git a/tests/PriorityQueue/toArray.php b/tests/PriorityQueue/toArray.php index 2c90946..bd55cb2 100644 --- a/tests/PriorityQueue/toArray.php +++ b/tests/PriorityQueue/toArray.php @@ -1,14 +1,14 @@ getInstance($values); + $instance = static::getInstance($values); // Also check that toArray is not destructive $this->assertToArray($expected, $instance); diff --git a/tests/PriorityQueueTest.php b/tests/PriorityQueueTest.php index 95bea4d..a8a290b 100644 --- a/tests/PriorityQueueTest.php +++ b/tests/PriorityQueueTest.php @@ -1,7 +1,7 @@ sample()], + [self::sample()], ]; } - /** - * @dataProvider constructDataProvider - */ + #[DataProvider('constructDataProvider')] public function testConstruct(array $values) { $this->assertToArray($values, new Queue($values)); } - /** - * @dataProvider constructDataProvider - */ + #[DataProvider('constructDataProvider')] public function testConstructUsingIterable(array $values) { $this->assertToArray($values, new Queue(new \ArrayIterator($values))); diff --git a/tests/Queue/_clone.php b/tests/Queue/_clone.php index 60ff7c6..5b8fb5a 100644 --- a/tests/Queue/_clone.php +++ b/tests/Queue/_clone.php @@ -1,14 +1,14 @@ getInstance($values); + $instance = static::getInstance($values); $clone = clone $instance; diff --git a/tests/Queue/_echo.php b/tests/Queue/_echo.php index d85c112..a1ffb3e 100644 --- a/tests/Queue/_echo.php +++ b/tests/Queue/_echo.php @@ -5,6 +5,6 @@ trait _echo { public function testEcho() { - $this->assertInstanceToString($this->getInstance()); + $this->assertInstanceToString(static::getInstance()); } } diff --git a/tests/Queue/_empty.php b/tests/Queue/_empty.php index 177874f..a05987f 100644 --- a/tests/Queue/_empty.php +++ b/tests/Queue/_empty.php @@ -5,7 +5,7 @@ trait _empty { public function testArrayAccessEmpty() { - $set = $this->getInstance(); + $set = static::getInstance(); $this->expectArrayAccessUnsupportedException(); empty($set['a']); } diff --git a/tests/Queue/_foreach.php b/tests/Queue/_foreach.php index 79da3d9..e0cf757 100644 --- a/tests/Queue/_foreach.php +++ b/tests/Queue/_foreach.php @@ -5,7 +5,7 @@ trait _foreach { public function testForEach() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $instance->push('a'); $instance->push('b'); diff --git a/tests/Queue/_isset.php b/tests/Queue/_isset.php index 18b265f..94484b6 100644 --- a/tests/Queue/_isset.php +++ b/tests/Queue/_isset.php @@ -5,14 +5,14 @@ trait _isset { public function testArrayAccessIsset() { - $set = $this->getInstance(); + $set = static::getInstance(); $this->expectArrayAccessUnsupportedException(); isset($set['a']); } public function testArrayAccessIssetByMethod() { - $set = $this->getInstance(); + $set = static::getInstance(); $this->expectArrayAccessUnsupportedException(); $set->offsetExists('a'); } diff --git a/tests/Queue/_jsonEncode.php b/tests/Queue/_jsonEncode.php index efc6a1a..ef2f695 100644 --- a/tests/Queue/_jsonEncode.php +++ b/tests/Queue/_jsonEncode.php @@ -1,14 +1,14 @@ getInstance($initial); + $instance = static::getInstance($initial); $this->assertEquals(json_encode($expected), json_encode($instance)); } } diff --git a/tests/Queue/_list.php b/tests/Queue/_list.php index 49ab1b3..575a5fb 100644 --- a/tests/Queue/_list.php +++ b/tests/Queue/_list.php @@ -5,14 +5,14 @@ trait _list { public function testList() { - $instance = $this->getInstance(['a', 'b', 'c']); + $instance = static::getInstance(['a', 'b', 'c']); $this->expectListNotSupportedException(); list($a, $b, $c) = $instance; } public function testListByMethod() { - $instance = $this->getInstance(['a', 'b', 'c']); + $instance = static::getInstance(['a', 'b', 'c']); $this->expectListNotSupportedException(); $instance->offsetGet(0); } diff --git a/tests/Queue/_serialize.php b/tests/Queue/_serialize.php index e4cda85..c96e4cf 100644 --- a/tests/Queue/_serialize.php +++ b/tests/Queue/_serialize.php @@ -1,14 +1,14 @@ getInstance($values); + $instance = static::getInstance($values); $this->assertSerialized($expected, $instance, false); } } diff --git a/tests/Queue/_unset.php b/tests/Queue/_unset.php index 907bb6b..fe984ce 100644 --- a/tests/Queue/_unset.php +++ b/tests/Queue/_unset.php @@ -5,14 +5,14 @@ trait _unset { public function testArrayAccessUnset() { - $set = $this->getInstance(); + $set = static::getInstance(); $this->expectArrayAccessUnsupportedException(); unset($set['a']); } public function testArrayAccessUnsetByMethod() { - $set = $this->getInstance(); + $set = static::getInstance(); $this->expectArrayAccessUnsupportedException(); $set->offsetUnset('a'); } diff --git a/tests/Queue/_var_dump.php b/tests/Queue/_var_dump.php index 6ceabbf..9a13fee 100644 --- a/tests/Queue/_var_dump.php +++ b/tests/Queue/_var_dump.php @@ -1,14 +1,14 @@ getInstance($values); + $instance = static::getInstance($values); $this->assertInstanceDump($expected, $instance); } } diff --git a/tests/Queue/clear.php b/tests/Queue/clear.php index e851efa..614f747 100644 --- a/tests/Queue/clear.php +++ b/tests/Queue/clear.php @@ -5,7 +5,7 @@ trait clear { public function testClear() { - $instance = $this->getInstance($this->sample()); + $instance = static::getInstance(self::sample()); $instance->clear(); $this->assertToArray([], $instance); diff --git a/tests/Queue/copy.php b/tests/Queue/copy.php index d9abd7f..f41a57f 100644 --- a/tests/Queue/copy.php +++ b/tests/Queue/copy.php @@ -1,14 +1,14 @@ getInstance($values); + $instance = static::getInstance($values); $copy = $instance->copy(); $this->assertEquals($instance->toArray(), $copy->toArray()); diff --git a/tests/Queue/count.php b/tests/Queue/count.php index e986b81..79cc69c 100644 --- a/tests/Queue/count.php +++ b/tests/Queue/count.php @@ -1,20 +1,20 @@ getInstance($values); + $instance = static::getInstance($values); $this->assertCount(count($expected), $instance); } public function testCountEmpty() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->assertCount(0, $instance); } } diff --git a/tests/Queue/isEmpty.php b/tests/Queue/isEmpty.php index eb7339a..b3d2c4f 100644 --- a/tests/Queue/isEmpty.php +++ b/tests/Queue/isEmpty.php @@ -1,9 +1,11 @@ getInstance($values); + $instance = static::getInstance($values); $this->assertEquals($isEmpty, $instance->isEmpty()); } public function testIsNotEmptyAfterPop() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->assertTrue($instance->isEmpty()); $instance->push('a'); diff --git a/tests/Queue/peek.php b/tests/Queue/peek.php index 0e6e7df..5de4b31 100644 --- a/tests/Queue/peek.php +++ b/tests/Queue/peek.php @@ -1,9 +1,11 @@ getInstance($initial); + $instance = static::getInstance($initial); $value = $instance->peek(); @@ -27,7 +27,7 @@ public function testPeek($initial, $returned) public function testPeekNotAllowedWhenEmpty() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->expectEmptyNotAllowedException(); $instance->peek(); } diff --git a/tests/Queue/pop.php b/tests/Queue/pop.php index 7d38a8d..2590e65 100644 --- a/tests/Queue/pop.php +++ b/tests/Queue/pop.php @@ -1,9 +1,11 @@ getInstance($initial); + $instance = static::getInstance($initial); $value = $instance->pop(); @@ -28,14 +28,14 @@ public function testPop($initial, $returned, array $expected) public function testPopNotAllowedWhenEmpty() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->expectEmptyNotAllowedException(); $instance->pop(); } public function testPopAll() { - $instance = $this->getInstance(range(1, self::MANY)); + $instance = static::getInstance(range(1, self::MANY)); while ( ! $instance->isEmpty()) { $instance->pop(); diff --git a/tests/Queue/push.php b/tests/Queue/push.php index fcc49d4..2cb029c 100644 --- a/tests/Queue/push.php +++ b/tests/Queue/push.php @@ -1,19 +1,19 @@ basicDataProvider(); + return self::basicDataProvider(); } - /** - * @dataProvider pushDataProvider - */ + #[DataProvider('pushDataProvider')] public function testPushVariadic(array $values, array $expected) { - $instance = $this->getInstance(); + $instance = static::getInstance(); $instance->push(...$values); @@ -21,12 +21,10 @@ public function testPushVariadic(array $values, array $expected) $this->assertCount(count($expected), $instance); } - /** - * @dataProvider pushDataProvider - */ + #[DataProvider('pushDataProvider')] public function testPush(array $values, array $expected) { - $instance = $this->getInstance(); + $instance = static::getInstance(); foreach ($values as $value) { $instance->push($value); @@ -36,12 +34,10 @@ public function testPush(array $values, array $expected) $this->assertCount(count($expected), $instance); } - /** - * @dataProvider pushDataProvider - */ + #[DataProvider('pushDataProvider')] public function testArrayAccessPush(array $values, array $expected) { - $instance = $this->getInstance(); + $instance = static::getInstance(); foreach ($values as $value) { $instance[] = $value; @@ -51,12 +47,10 @@ public function testArrayAccessPush(array $values, array $expected) $this->assertCount(count($expected), $instance); } - /** - * @dataProvider pushDataProvider - */ + #[DataProvider('pushDataProvider')] public function testArrayAccessPushByMethod(array $values, array $expected) { - $instance = $this->getInstance(); + $instance = static::getInstance(); foreach ($values as $value) { $instance->offsetSet(null, $value); @@ -68,7 +62,7 @@ public function testArrayAccessPushByMethod(array $values, array $expected) public function testPushCircularReference() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $instance->push($instance); $this->assertToArray([$instance], $instance); } diff --git a/tests/Queue/toArray.php b/tests/Queue/toArray.php index f346a88..a7b866a 100644 --- a/tests/Queue/toArray.php +++ b/tests/Queue/toArray.php @@ -1,14 +1,14 @@ getInstance($values); + $instance = static::getInstance($values); $this->assertToArray($expected, $instance); } } diff --git a/tests/QueueTest.php b/tests/QueueTest.php index cbf1f36..c2ccfa0 100644 --- a/tests/QueueTest.php +++ b/tests/QueueTest.php @@ -4,7 +4,7 @@ use ArrayAccess; use Ds\Collection; -class QueueTest extends CollectionTest +class QueueTest extends CollectionTestCase { use Queue\__construct; use Queue\_clone; @@ -30,20 +30,20 @@ class QueueTest extends CollectionTest use Queue\push; use Queue\toArray; - public function getInstance(array $values = []) + public static function getInstance(array $values = []) { return new \Ds\Queue($values); } public function testArrayAccessSet() { - $set = $this->getInstance(); + $set = static::getInstance(); $this->expectArrayAccessUnsupportedException(); $set['a'] = 1; } public function testImplementsArrayAccess() { - $this->assertInstanceOf(ArrayAccess::class, $this->getInstance()); + $this->assertInstanceOf(ArrayAccess::class, static::getInstance()); } } diff --git a/tests/Sequence/_clone.php b/tests/Sequence/_clone.php index e76bdd8..f30ae08 100644 --- a/tests/Sequence/_clone.php +++ b/tests/Sequence/_clone.php @@ -1,19 +1,19 @@ basicDataProvider(); + return self::basicDataProvider(); } - /** - * @dataProvider cloneDataProvider - */ + #[DataProvider('cloneDataProvider')] public function testClone($values, array $expected) { - $instance = $this->getInstance($values); + $instance = static::getInstance($values); $clone = clone $instance; diff --git a/tests/Sequence/_echo.php b/tests/Sequence/_echo.php index 779edcc..c9f5557 100644 --- a/tests/Sequence/_echo.php +++ b/tests/Sequence/_echo.php @@ -5,6 +5,6 @@ trait _echo { public function testEcho() { - $this->assertInstanceToString($this->getInstance()); + $this->assertInstanceToString(static::getInstance()); } } diff --git a/tests/Sequence/_empty.php b/tests/Sequence/_empty.php index 24634d1..1341b59 100644 --- a/tests/Sequence/_empty.php +++ b/tests/Sequence/_empty.php @@ -1,9 +1,11 @@ getInstance($initial); + $instance = static::getInstance($initial); $this->assertEquals($empty, empty($instance[$index])); } - /** - * @dataProvider badIndexDataProvider - */ + #[DataProvider('badIndexDataProvider')] public function testArrayAccessEmptyIndexBadIndex($initial, $index) { - $instance = $this->getInstance($initial); + $instance = static::getInstance($initial); $this->assertTrue(empty($instance[$index])); } - /** - * @dataProvider outOfRangeDataProvider - */ + #[DataProvider('outOfRangeDataProvider')] public function testArrayAccessEmptyIndexOutOfRange($initial, $index) { - $instance = $this->getInstance($initial); + $instance = static::getInstance($initial); $this->assertTrue(empty($instance[$index])); } - /** - * @dataProvider emptyDataProvider - */ + #[DataProvider('emptyDataProvider')] public function testArrayAccessEmptyByReference($initial, $index, bool $empty) { - $instance = $this->getInstance([$initial]); + $instance = static::getInstance([$initial]); $this->assertEquals($empty, empty($instance[0][$index])); } } diff --git a/tests/Sequence/_foreach.php b/tests/Sequence/_foreach.php index 3665ca4..b36a86e 100644 --- a/tests/Sequence/_foreach.php +++ b/tests/Sequence/_foreach.php @@ -1,14 +1,14 @@ getInstance($values); + $instance = static::getInstance($values); $this->assertForEach($expected, $instance); } } diff --git a/tests/Sequence/_isset.php b/tests/Sequence/_isset.php index 9d2eb30..dc3e53e 100644 --- a/tests/Sequence/_isset.php +++ b/tests/Sequence/_isset.php @@ -1,9 +1,11 @@ getInstance($initial); + $instance = static::getInstance($initial); $this->assertEquals($isset, isset($instance[$index])); } - /** - * @dataProvider issetDataProvider - */ + #[DataProvider('issetDataProvider')] public function testArrayAccessIssetByMethod($initial, $index, bool $isset) { - $instance = $this->getInstance($initial); + $instance = static::getInstance($initial); $this->assertEquals($isset, $instance->offsetExists($index)); } - /** - * @dataProvider badIndexDataProvider - */ + #[DataProvider('badIndexDataProvider')] public function testArrayAccessIssetIndexBadIndex($initial, $index) { - $instance = $this->getInstance($initial); + $instance = static::getInstance($initial); $this->assertFalse(isset($instance[$index])); } - /** - * @dataProvider outOfRangeDataProvider - */ + #[DataProvider('outOfRangeDataProvider')] public function testArrayAccessIssetIndexOutOfRange($initial, $index) { - $instance = $this->getInstance($initial); + $instance = static::getInstance($initial); $this->assertFalse(isset($instance[$index])); } - /** - * @dataProvider issetDataProvider - */ + #[DataProvider('issetDataProvider')] public function testArrayAccessIssetByReference($initial, $index, bool $isset) { - $instance = $this->getInstance([$initial]); + $instance = static::getInstance([$initial]); $this->assertEquals($isset, isset($instance[0][$index])); } } diff --git a/tests/Sequence/_jsonEncode.php b/tests/Sequence/_jsonEncode.php index 6e1bb8e..6dc3a0d 100644 --- a/tests/Sequence/_jsonEncode.php +++ b/tests/Sequence/_jsonEncode.php @@ -1,19 +1,19 @@ basicDataProvider(); + return self::basicDataProvider(); } - /** - * @dataProvider jsonEncodeDataProvider - */ + #[DataProvider('jsonEncodeDataProvider')] public function testJsonEncode(array $initial, array $expected) { - $instance = $this->getInstance($initial); + $instance = static::getInstance($initial); $this->assertEquals(json_encode($expected), json_encode($instance)); } } diff --git a/tests/Sequence/_list.php b/tests/Sequence/_list.php index 40df1a7..e3cbba4 100644 --- a/tests/Sequence/_list.php +++ b/tests/Sequence/_list.php @@ -5,7 +5,7 @@ trait _list { public function testList() { - $instance = $this->getInstance(['a', 'b', 'c']); + $instance = static::getInstance(['a', 'b', 'c']); list($a, $b, $c) = $instance; $this->assertEquals('a', $a); diff --git a/tests/Sequence/_unset.php b/tests/Sequence/_unset.php index e6663dc..13c3c62 100644 --- a/tests/Sequence/_unset.php +++ b/tests/Sequence/_unset.php @@ -1,47 +1,41 @@ getInstance($initial); + $instance = static::getInstance($initial); unset($instance[$index]); $this->assertToArray($expected, $instance); $this->assertEquals(count($expected), count($instance)); } - /** - * @dataProvider removeDataProvider - */ + #[DataProvider('removeDataProvider')] public function testArrayAccessUnsetByMethod($initial, $index, $return, array $expected) { - $instance = $this->getInstance($initial); + $instance = static::getInstance($initial); $instance->offsetUnset($index); $this->assertToArray($expected, $instance); $this->assertEquals(count($expected), count($instance)); } - /** - * @dataProvider badIndexDataProvider - */ + #[DataProvider('badIndexDataProvider')] public function testArrayAccessUnsetIndexBadIndex($initial, $index) { - $instance = $this->getInstance($initial); + $instance = static::getInstance($initial); unset($instance[$index]); $this->assertFalse(isset($instance[$index])); } - /** - * @dataProvider outOfRangeDataProvider - */ + #[DataProvider('outOfRangeDataProvider')] public function testArrayAccessUnsetIndexOutOfRange($initial, $index) { - $instance = $this->getInstance($initial); + $instance = static::getInstance($initial); unset($instance[$index]); $this->assertFalse(isset($instance[$index])); @@ -50,7 +44,7 @@ public function testArrayAccessUnsetIndexOutOfRange($initial, $index) public function testArrayAccessUnsetByReference() { - $instance = $this->getInstance([[1]]); + $instance = static::getInstance([[1]]); unset($instance[0][0]); $this->assertToArray([[]], $instance); diff --git a/tests/Sequence/_var_dump.php b/tests/Sequence/_var_dump.php index 24f8485..db5d75e 100644 --- a/tests/Sequence/_var_dump.php +++ b/tests/Sequence/_var_dump.php @@ -1,14 +1,14 @@ getInstance($values); + $instance = static::getInstance($values); $this->assertInstanceDump($expected, $instance); } } diff --git a/tests/Sequence/apply.php b/tests/Sequence/apply.php index f4baebf..9786384 100644 --- a/tests/Sequence/apply.php +++ b/tests/Sequence/apply.php @@ -1,9 +1,11 @@ getInstance($values); + $instance = static::getInstance($values); $instance->apply($callback); $expected = array_map($callback, $values); @@ -37,7 +37,7 @@ public function testApply(array $values, callable $callback) public function testApplyCallbackThrowsException() { - $instance = $this->getInstance([1, 2, 3]); + $instance = static::getInstance([1, 2, 3]); try { $instance->apply(function($value) { @@ -53,7 +53,7 @@ public function testApplyCallbackThrowsException() public function testApplyCallbackThrowsExceptionLaterOn() { - $instance = $this->getInstance([1, 2, 3]); + $instance = static::getInstance([1, 2, 3]); try { $instance->apply(function($value) { @@ -73,7 +73,7 @@ public function testApplyCallbackThrowsExceptionLaterOn() public function testApplyDoesNotCallByReference() { - $instance = $this->getInstance([1, 2, 3]); + $instance = static::getInstance([1, 2, 3]); $instance->apply(function($value) { $before = $value; diff --git a/tests/Sequence/clear.php b/tests/Sequence/clear.php index b5cba5f..3c4c361 100644 --- a/tests/Sequence/clear.php +++ b/tests/Sequence/clear.php @@ -5,7 +5,7 @@ trait clear { public function testClear() { - $instance = $this->getInstance($this->sample()); + $instance = static::getInstance(self::sample()); $instance->clear(); $this->assertToArray([], $instance); diff --git a/tests/Sequence/contains.php b/tests/Sequence/contains.php index 8694687..02a20ca 100644 --- a/tests/Sequence/contains.php +++ b/tests/Sequence/contains.php @@ -1,11 +1,13 @@ sample(); + $sample = self::sample(); // initial, values, expected return [ @@ -27,12 +29,10 @@ public function containsDataProvider() ]; } - /** - * @dataProvider containsDataProvider - */ + #[DataProvider('containsDataProvider')] public function testContains($initial, array $values, bool $expected) { - $instance = $this->getInstance($initial); + $instance = static::getInstance($initial); $this->assertEquals($expected, $instance->contains(...$values)); } } diff --git a/tests/Sequence/copy.php b/tests/Sequence/copy.php index 7e37655..ec9069d 100644 --- a/tests/Sequence/copy.php +++ b/tests/Sequence/copy.php @@ -1,14 +1,14 @@ getInstance($values); + $instance = static::getInstance($values); $copy = $instance->copy(); $this->assertEquals($instance->toArray(), $copy->toArray()); diff --git a/tests/Sequence/count.php b/tests/Sequence/count.php index b6ce778..f4745ec 100644 --- a/tests/Sequence/count.php +++ b/tests/Sequence/count.php @@ -5,13 +5,13 @@ trait count { public function testCount() { - $instance = $this->getInstance($this->sample()); - $this->assertCount(count($this->sample()), $instance); + $instance = static::getInstance(self::sample()); + $this->assertCount(count(self::sample()), $instance); } public function testCountEmpty() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->assertCount(0, $instance); } } diff --git a/tests/Sequence/filter.php b/tests/Sequence/filter.php index f320e2d..2ee3752 100644 --- a/tests/Sequence/filter.php +++ b/tests/Sequence/filter.php @@ -1,9 +1,11 @@ getInstance($values); + $instance = static::getInstance($values); $filtered = $instance->filter($callback); $expected = array_values(array_filter($values, $callback)); @@ -34,12 +34,10 @@ public function testFilter(array $values, callable $callback) $this->assertEquals($expected, $filtered->toArray()); } - /** - * @dataProvider filterDataProvider - */ + #[DataProvider('filterDataProvider')] public function testFilterWithoutCallback(array $values, callable $callback) { - $instance = $this->getInstance($values); + $instance = static::getInstance($values); $filtered = $instance->filter(); $expected = array_values(array_filter($values)); @@ -50,7 +48,7 @@ public function testFilterWithoutCallback(array $values, callable $callback) public function testFilterCallbackThrowsException() { - $instance = $this->getInstance(["a", "b", "c"]); + $instance = static::getInstance(["a", "b", "c"]); $filtered = null; try { @@ -68,7 +66,7 @@ public function testFilterCallbackThrowsException() public function testFilterCallbackThrowsExceptionLaterOn() { - $instance = $this->getInstance(["a", "b", "c"]); + $instance = static::getInstance(["a", "b", "c"]); $filtered = null; try { @@ -89,7 +87,7 @@ public function testFilterCallbackThrowsExceptionLaterOn() public function testFilterDoesNotLeakWhenCallbackFails() { - $instance = $this->getInstance(["a", "b", "c"]); + $instance = static::getInstance(["a", "b", "c"]); $filtered = null; try { diff --git a/tests/Sequence/find.php b/tests/Sequence/find.php index 1fd12f0..98915fe 100644 --- a/tests/Sequence/find.php +++ b/tests/Sequence/find.php @@ -1,9 +1,11 @@ getInstance($initial); + $instance = static::getInstance($initial); $this->assertEquals($expected, $instance->find($value)); } } diff --git a/tests/Sequence/first.php b/tests/Sequence/first.php index a1823c8..46e1ad9 100644 --- a/tests/Sequence/first.php +++ b/tests/Sequence/first.php @@ -1,9 +1,11 @@ getInstance($initial); + $instance = static::getInstance($initial); $this->assertEquals($expected, $instance->first()); } public function testFirstNowAllowedWhenEmpty() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->expectEmptyNotAllowedException(); $instance->first(); } diff --git a/tests/Sequence/get.php b/tests/Sequence/get.php index 2a64608..95c05c0 100644 --- a/tests/Sequence/get.php +++ b/tests/Sequence/get.php @@ -1,9 +1,11 @@ getInstance($initial); + $instance = static::getInstance($initial); $returned = $instance->get($index); @@ -34,53 +34,43 @@ public function testGet(array $initial, $index, $return) $this->assertEquals($return, $returned); } - /** - * @dataProvider outOfRangeDataProvider - */ + #[DataProvider('outOfRangeDataProvider')] public function testGetIndexOutOfRange($initial, $index) { - $instance = $this->getInstance($initial); + $instance = static::getInstance($initial); $this->expectIndexOutOfRangeException(); $instance->get($index); } - /** - * @dataProvider badIndexDataProvider - */ + #[DataProvider('badIndexDataProvider')] public function testGetIndexBadIndex($initial, $index) { - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->expectWrongIndexTypeException(); $instance->get($index); } - /** - * @dataProvider getDataProvider - */ + #[DataProvider('getDataProvider')] public function testArrayAccessGet(array $initial, $index, $return) { - $instance = $this->getInstance($initial); + $instance = static::getInstance($initial); $this->assertEquals($return, $instance[$index]); } - /** - * @dataProvider badIndexDataProvider - */ + #[DataProvider('badIndexDataProvider')] public function testArrayAccessGetIndexBadIndex($initial, $index) { - $instance = $this->getInstance($initial); + $instance = static::getInstance($initial); $this->expectWrongIndexTypeException(); $instance[$index]; } - /** - * @dataProvider outOfRangeDataProvider - */ + #[DataProvider('outOfRangeDataProvider')] public function testArrayAccessGetIndexOutOfRange($initial, $index) { - $instance = $this->getInstance($initial); + $instance = static::getInstance($initial); $this->expectIndexOutOfRangeException(); $instance[$index]; } @@ -88,13 +78,13 @@ public function testArrayAccessGetIndexOutOfRange($initial, $index) public function testArrayAccessGetByReference() { - $instance = $this->getInstance([[1]]); + $instance = static::getInstance([[1]]); $this->assertEquals(1, $instance[0][0]); } public function testArrayAccessGetNullCoalesce() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->assertEquals(null, $instance[10] ?? null); } diff --git a/tests/Sequence/insert.php b/tests/Sequence/insert.php index ed7bab3..afb166d 100644 --- a/tests/Sequence/insert.php +++ b/tests/Sequence/insert.php @@ -1,11 +1,13 @@ sample(); + $s = self::sample(); $h = count($s) / 2; @@ -30,30 +32,26 @@ public function insertDataProvider() } - /** - * @dataProvider insertDataProvider - */ + #[DataProvider('insertDataProvider')] public function testInsertVariadic(array $initial, $index, array $values) { $expected = $initial; array_splice($expected, $index, 0, $values); - $instance = $this->getInstance($initial); + $instance = static::getInstance($initial); $instance->insert($index, ...$values); $this->assertEquals(count($expected), count($instance)); $this->assertToArray($expected, $instance); } - /** - * @dataProvider insertDataProvider - */ + #[DataProvider('insertDataProvider')] public function testInsert(array $initial, $index, array $values) { $expected = $initial; array_splice($expected, $index, 0, array_reverse($values)); - $instance = $this->getInstance($initial); + $instance = static::getInstance($initial); foreach ($values as $value) { $instance->insert($index, $value); @@ -63,22 +61,18 @@ public function testInsert(array $initial, $index, array $values) $this->assertToArray($expected, $instance); } - /** - * @dataProvider outOfRangeDataProvider - */ + #[DataProvider('outOfRangeDataProvider')] public function testInsertIndexOutOfRange($initial, $index) { - $instance = $this->getInstance($initial); + $instance = static::getInstance($initial); $this->expectIndexOutOfRangeException(); $instance->insert($index); } - /** - * @dataProvider badIndexDataProvider - */ + #[DataProvider('badIndexDataProvider')] public function testInsertIndexBadIndex($initial, $index) { - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->expectWrongIndexTypeException(); $instance->insert($index); } diff --git a/tests/Sequence/isEmpty.php b/tests/Sequence/isEmpty.php index c136212..8694b84 100644 --- a/tests/Sequence/isEmpty.php +++ b/tests/Sequence/isEmpty.php @@ -1,9 +1,11 @@ getInstance($values); + $instance = static::getInstance($values); $this->assertEquals($isEmpty, $instance->isEmpty()); } public function testIsNotEmptyAfterRemove() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->assertTrue($instance->isEmpty()); $instance->push('a'); diff --git a/tests/Sequence/join.php b/tests/Sequence/join.php index 94be662..55f9046 100644 --- a/tests/Sequence/join.php +++ b/tests/Sequence/join.php @@ -1,16 +1,18 @@ getInstance(); + $obj = static::getInstance(); foreach ($lengths as $length) { foreach ($glues as $glue) { @@ -23,22 +25,18 @@ public function joinDataProvider() return $data; } - /** - * @dataProvider joinDataProvider - */ + #[DataProvider('joinDataProvider')] public function testJoin(array $values, $glue) { - $instance = $this->getInstance($values); + $instance = static::getInstance($values); $expected = join($glue, $values); $this->assertEquals($expected, $instance->join($glue)); } - /** - * @dataProvider joinDataProvider - */ + #[DataProvider('joinDataProvider')] public function testJoinWithoutGlue(array $values, $glue) { - $instance = $this->getInstance($values); + $instance = static::getInstance($values); $expected = join($values); $this->assertEquals($expected, $instance->join()); } diff --git a/tests/Sequence/last.php b/tests/Sequence/last.php index 44f200f..10eff93 100644 --- a/tests/Sequence/last.php +++ b/tests/Sequence/last.php @@ -1,9 +1,11 @@ getInstance($initial); + $instance = static::getInstance($initial); $this->assertEquals($expected, $instance->last()); } public function testLastNotAllowedWhenEmpty() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->expectEmptyNotAllowedException(); $instance->last(); } diff --git a/tests/Sequence/map.php b/tests/Sequence/map.php index c273fea..b30480c 100644 --- a/tests/Sequence/map.php +++ b/tests/Sequence/map.php @@ -1,9 +1,11 @@ getInstance($values); + $instance = static::getInstance($values); $mapped = $instance->map($callback); $expected = array_map($callback, $values); @@ -39,7 +39,7 @@ public function testMap(array $values, callable $callback) public function testMapCallbackThrowsException() { - $instance = $this->getInstance([1, 2, 3]); + $instance = static::getInstance([1, 2, 3]); $mapped = null; try { @@ -57,7 +57,7 @@ public function testMapCallbackThrowsException() public function testMapCallbackThrowsExceptionLaterOn() { - $instance = $this->getInstance([1, 2, 3]); + $instance = static::getInstance([1, 2, 3]); $mapped = null; try { @@ -79,7 +79,7 @@ public function testMapCallbackThrowsExceptionLaterOn() public function testMapDoesNotLeakWhenCallbackFails() { - $instance = $this->getInstance(["a", "b", "c"]); + $instance = static::getInstance(["a", "b", "c"]); static::expectException(\Exception::class); diff --git a/tests/Sequence/merge.php b/tests/Sequence/merge.php index d666fb7..91750ae 100644 --- a/tests/Sequence/merge.php +++ b/tests/Sequence/merge.php @@ -1,9 +1,11 @@ getInstance($initial); + $instance = static::getInstance($initial); $this->assertToArray($expected, $instance->merge($values)); $this->assertToArray($initial, $instance); } - /** - * @dataProvider mergeDataProvider - */ + #[DataProvider('mergeDataProvider')] public function testMergeWithSelf(array $initial, array $values, array $expected) { - $instance = $this->getInstance($initial); + $instance = static::getInstance($initial); $this->assertToArray(array_merge($initial, $initial), $instance->merge($instance)); $this->assertToArray($initial, $instance); diff --git a/tests/Sequence/pop.php b/tests/Sequence/pop.php index a8a800d..e2edf43 100644 --- a/tests/Sequence/pop.php +++ b/tests/Sequence/pop.php @@ -1,9 +1,11 @@ getInstance($initial); + $instance = static::getInstance($initial); $result = $instance->pop(); @@ -26,14 +26,14 @@ public function testPop($initial, array $expected, $returned) $this->assertEquals(count($initial) - 1, count($instance)); // - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->expectEmptyNotAllowedException(); $instance->pop(); } public function testPopAll() { - $instance = $this->getInstance(range(1, self::MANY)); + $instance = static::getInstance(range(1, self::MANY)); while ( ! $instance->isEmpty()) { $instance->pop(); diff --git a/tests/Sequence/push.php b/tests/Sequence/push.php index 926e27a..8b90dbf 100644 --- a/tests/Sequence/push.php +++ b/tests/Sequence/push.php @@ -1,31 +1,29 @@ basicDataProvider(); + return self::basicDataProvider(); } - /** - * @dataProvider pushDataProvider - */ + #[DataProvider('pushDataProvider')] public function testPushVariadic(array $values, array $expected) { - $instance = $this->getInstance(); + $instance = static::getInstance(); $instance->push(...$values); $this->assertToArray($expected, $instance); $this->assertEquals(count($expected), count($instance)); } - /** - * @dataProvider pushDataProvider - */ + #[DataProvider('pushDataProvider')] public function testPush(array $values, array $expected) { - $instance = $this->getInstance(); + $instance = static::getInstance(); foreach ($values as $value) { $instance->push($value); @@ -35,12 +33,10 @@ public function testPush(array $values, array $expected) $this->assertEquals(count($expected), count($instance)); } - /** - * @dataProvider pushDataProvider - */ + #[DataProvider('pushDataProvider')] public function testArrayAccessPush(array $values, array $expected) { - $instance = $this->getInstance(); + $instance = static::getInstance(); foreach ($values as $value) { $instance[] = $value; @@ -50,12 +46,10 @@ public function testArrayAccessPush(array $values, array $expected) $this->assertEquals(count($expected), count($instance)); } - /** - * @dataProvider pushDataProvider - */ + #[DataProvider('pushDataProvider')] public function testArrayAccessPushByMethod(array $values, array $expected) { - $instance = $this->getInstance(); + $instance = static::getInstance(); foreach ($values as $value) { $instance->offsetSet(null, $value); @@ -67,15 +61,15 @@ public function testArrayAccessPushByMethod(array $values, array $expected) public function testPushCircularReference() { - $instance = $this->getInstance(['a', 'b', 'c']); + $instance = static::getInstance(['a', 'b', 'c']); $instance->push($instance); $this->assertToArray(['a', 'b', 'c', $instance], $instance); } public function testPushIndirectCircularReference() { - $a = $this->getInstance(); - $b = $this->getInstance(); + $a = static::getInstance(); + $b = static::getInstance(); $a->push($b); $b->push($a); @@ -86,8 +80,8 @@ public function testPushIndirectCircularReference() public function testPushDeeperIndirectCircularReference() { - $a = $this->getInstance(); - $b = $this->getInstance(); + $a = static::getInstance(); + $b = static::getInstance(); $a->push($b); $b->push($a); @@ -104,8 +98,8 @@ public function testPushDeeperIndirectCircularReference() public function testPushIndirectCircularReferenceAfterUnshifts() { - $a = $this->getInstance(); - $b = $this->getInstance(); + $a = static::getInstance(); + $b = static::getInstance(); $a->push(...range(1, 5)); $b->push(...range(1, 5)); diff --git a/tests/Sequence/reduce.php b/tests/Sequence/reduce.php index 1dd8b8e..9eea1a9 100644 --- a/tests/Sequence/reduce.php +++ b/tests/Sequence/reduce.php @@ -1,9 +1,11 @@ getInstance($values); + $instance = static::getInstance($values); $reduced = $instance->reduce($callback, $initial); $expected = array_reduce($values, $callback, $initial); @@ -34,12 +34,10 @@ public function testReduce(array $values, $initial, callable $callback) $this->assertEquals($expected, $reduced); } - /** - * @dataProvider reduceDataProvider - */ + #[DataProvider('reduceDataProvider')] public function testReduceWithoutInitial(array $values, $initial, callable $callback) { - $instance = $this->getInstance($values); + $instance = static::getInstance($values); $reduced = $instance->reduce($callback); $expected = array_reduce($values, $callback); @@ -50,7 +48,7 @@ public function testReduceWithoutInitial(array $values, $initial, callable $call public function testReduceCallbackThrowsException() { - $instance = $this->getInstance(["a", "b", "c"]); + $instance = static::getInstance(["a", "b", "c"]); $result = null; try { @@ -68,7 +66,7 @@ public function testReduceCallbackThrowsException() public function testReduceCallbackThrowsExceptionLaterOn() { - $instance = $this->getInstance(["a", "b", "c"]); + $instance = static::getInstance(["a", "b", "c"]); $result = null; try { @@ -90,7 +88,7 @@ public function testReduceCallbackThrowsExceptionLaterOn() public function testReduceCallbackDoesNotLeakOnFailure() { - $instance = $this->getInstance(["a", "b", "c"]); + $instance = static::getInstance(["a", "b", "c"]); static::expectException(\Exception::class); diff --git a/tests/Sequence/remove.php b/tests/Sequence/remove.php index 0e61403..ff46fd1 100644 --- a/tests/Sequence/remove.php +++ b/tests/Sequence/remove.php @@ -1,9 +1,11 @@ getInstance($initial); + $instance = static::getInstance($initial); $returned = $instance->remove($index); $this->assertEquals(count($initial) - 1, count($instance)); @@ -32,22 +32,18 @@ public function testRemove($initial, $index, $return, array $expected) $this->assertEquals($return, $returned); } - /** - * @dataProvider outOfRangeDataProvider - */ + #[DataProvider('outOfRangeDataProvider')] public function testRemoveIndexOutOfRange($initial, $index) { - $instance = $this->getInstance($initial); + $instance = static::getInstance($initial); $this->expectIndexOutOfRangeException(); $instance->remove($index); } - /** - * @dataProvider badIndexDataProvider - */ + #[DataProvider('badIndexDataProvider')] public function testRemoveIndexBadIndex($initial, $index) { - $instance = $this->getInstance($initial); + $instance = static::getInstance($initial); $this->expectWrongIndexTypeException(); $instance->remove($index); } diff --git a/tests/Sequence/reverse.php b/tests/Sequence/reverse.php index ee8ce3d..9db63d1 100644 --- a/tests/Sequence/reverse.php +++ b/tests/Sequence/reverse.php @@ -1,21 +1,21 @@ basicDataProvider() + self::basicDataProvider() ); } - /** - * @dataProvider reverseDataProvider - */ + #[DataProvider('reverseDataProvider')] public function testReverse(array $values, array $expected) { - $instance = $this->getInstance($values); + $instance = static::getInstance($values); $instance->reverse(); $this->assertToArray($expected, $instance); diff --git a/tests/Sequence/reversed.php b/tests/Sequence/reversed.php index ec38385..fd97e92 100644 --- a/tests/Sequence/reversed.php +++ b/tests/Sequence/reversed.php @@ -1,21 +1,21 @@ basicDataProvider() + self::basicDataProvider() ); } - /** - * @dataProvider reversedDataProvider - */ + #[DataProvider('reversedDataProvider')] public function testReversed(array $values, array $expected) { - $instance = $this->getInstance($values); + $instance = static::getInstance($values); $this->assertToArray($expected, $instance->reversed()); $this->assertToArray($values, $instance); } diff --git a/tests/Sequence/rotate.php b/tests/Sequence/rotate.php index db15605..cba5892 100644 --- a/tests/Sequence/rotate.php +++ b/tests/Sequence/rotate.php @@ -1,9 +1,11 @@ getInstance($values); + $instance = static::getInstance($values); $instance->rotate($rotation); $this->assertToArray($expected, $instance); } diff --git a/tests/Sequence/set.php b/tests/Sequence/set.php index 20e23e7..4a6ac40 100644 --- a/tests/Sequence/set.php +++ b/tests/Sequence/set.php @@ -1,9 +1,11 @@ getInstance($initial); + $instance = static::getInstance($initial); $instance->set($index, $value); @@ -35,53 +35,43 @@ public function testSet($initial, $index, $value, array $expected) $this->assertEquals(count($initial), count($instance)); } - /** - * @dataProvider outOfRangeDataProvider - */ + #[DataProvider('outOfRangeDataProvider')] public function testSetOutOfRange($initial, $index) { - $instance = $this->getInstance($initial); + $instance = static::getInstance($initial); $this->expectIndexOutOfRangeException(); $instance->set($index, 1); } - /** - * @dataProvider badIndexDataProvider - */ + #[DataProvider('badIndexDataProvider')] public function testSetIndexBadIndex($initial, $index) { - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->expectWrongIndexTypeException(); $instance->set($index, 1); } - /** - * @dataProvider setDataProvider - */ + #[DataProvider('setDataProvider')] public function testArrayAccessSet($initial, $index, $value, array $expected) { - $instance = $this->getInstance($initial); + $instance = static::getInstance($initial); $instance[$index] = $value; $this->assertToArray($expected, $instance); $this->assertEquals(count($expected), count($instance)); } - /** - * @dataProvider badIndexDataProvider - */ + #[DataProvider('badIndexDataProvider')] public function testArrayAccessSetIndexBadIndex($initial, $index) { - $instance = $this->getInstance($initial); + $instance = static::getInstance($initial); $this->expectWrongIndexTypeException(); $instance[$index] = 1; } - /** - * @dataProvider outOfRangeDataProvider - */ + #[DataProvider('outOfRangeDataProvider')] public function testArrayAccessSetIndexOutOfRange($initial, $index) { - $instance = $this->getInstance($initial); + $instance = static::getInstance($initial); $this->expectIndexOutOfRangeException(); $instance[$index] = 1; } @@ -89,7 +79,7 @@ public function testArrayAccessSetIndexOutOfRange($initial, $index) public function testArrayAccessSetByReference() { - $instance = $this->getInstance([[1]]); + $instance = static::getInstance([[1]]); $instance[0][0] = 2; $this->assertToArray([[2]], $instance); @@ -97,7 +87,7 @@ public function testArrayAccessSetByReference() public function testSetWithReference() { - $instance = $this->getInstance(['a', 'b', 'c']); + $instance = static::getInstance(['a', 'b', 'c']); $key = 1; $ref = &$key; @@ -117,7 +107,7 @@ public function testSetWithReference() public function testArrayAccessSetWithReference() { - $instance = $this->getInstance(['a', 'b', 'c']); + $instance = static::getInstance(['a', 'b', 'c']); $key = 1; $ref = &$key; diff --git a/tests/Sequence/shift.php b/tests/Sequence/shift.php index 8a80dd8..4e3618f 100644 --- a/tests/Sequence/shift.php +++ b/tests/Sequence/shift.php @@ -1,9 +1,11 @@ getInstance($initial); + $instance = static::getInstance($initial); $this->assertEquals($expected, $instance->shift()); $this->assertToArray($result, $instance); @@ -29,14 +29,14 @@ public function testShift(array $initial, $expected, array $result) public function testShiftNotAllowedWhenEmpty() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->expectEmptyNotAllowedException(); $instance->shift(); } public function testShiftAll() { - $instance = $this->getInstance(range(1, self::MANY)); + $instance = static::getInstance(range(1, self::MANY)); while ( ! $instance->isEmpty()) { $instance->shift(); diff --git a/tests/Sequence/slice.php b/tests/Sequence/slice.php index d99560f..39f8270 100644 --- a/tests/Sequence/slice.php +++ b/tests/Sequence/slice.php @@ -1,9 +1,11 @@ getInstance($values); + $instance = static::getInstance($values); $sliced = $instance->slice($index, $length); $expected = array_slice($values, $index, $length); @@ -35,12 +35,10 @@ public function testSlice(array $values, int $index, int $length) $this->assertToArray($expected, $sliced); } - /** - * @dataProvider sliceDataProvider - */ + #[DataProvider('sliceDataProvider')] public function testSliceWithoutLength(array $values, int $index, int $length) { - $instance = $this->getInstance($values); + $instance = static::getInstance($values); $sliced = $instance->slice($index); $expected = array_slice($values, $index); @@ -49,12 +47,10 @@ public function testSliceWithoutLength(array $values, int $index, int $length) $this->assertToArray($expected, $sliced); } - /** - * @dataProvider sliceDataProvider - */ + #[DataProvider('sliceDataProvider')] public function testSliceWithLengthNull(array $values, int $index, int $length) { - $instance = $this->getInstance($values); + $instance = static::getInstance($values); $sliced = $instance->slice($index, null); $expected = array_slice($values, $index); @@ -69,7 +65,7 @@ public function testLargeSliceHalf() $x = 0; $y = intdiv($n, 2); - $instance = $this->getInstance(range(0, $n)); + $instance = static::getInstance(range(0, $n)); $this->assertToArray(range($x, $y - 1), $instance->slice($x, $y)); $this->assertToArray(range($y, $n), $instance->slice($y)); @@ -81,7 +77,7 @@ public function testLargeSliceOffset() $x = intdiv($n, 4); $y = intdiv($n, 4) + intdiv($n, 2); - $instance = $this->getInstance(range(0, $n)); + $instance = static::getInstance(range(0, $n)); $this->assertToArray(range($x, $y - 1), $instance->slice($x, $y - $x)); } diff --git a/tests/Sequence/sort.php b/tests/Sequence/sort.php index 254e95f..5a16eea 100644 --- a/tests/Sequence/sort.php +++ b/tests/Sequence/sort.php @@ -5,7 +5,7 @@ trait sort { public function testSort() { - $instance = $this->getInstance([4, 1, 2, 5, 3]); + $instance = static::getInstance([4, 1, 2, 5, 3]); $instance->sort(); $this->assertToArray([1, 2, 3, 4, 5], $instance); @@ -13,7 +13,7 @@ public function testSort() public function testSortUsingComparator() { - $instance = $this->getInstance([4, 1, 2, 5, 3]); + $instance = static::getInstance([4, 1, 2, 5, 3]); $instance->sort(function($a, $b) { return $b <=> $a; diff --git a/tests/Sequence/sorted.php b/tests/Sequence/sorted.php index 832088a..02a5b76 100644 --- a/tests/Sequence/sorted.php +++ b/tests/Sequence/sorted.php @@ -5,7 +5,7 @@ trait sorted { public function testSorted() { - $instance = $this->getInstance([4, 1, 2, 5, 3]); + $instance = static::getInstance([4, 1, 2, 5, 3]); $sorted = $instance->sorted(); $this->assertToArray([1, 2, 3, 4, 5], $sorted); @@ -14,7 +14,7 @@ public function testSorted() public function testSortedUsingComparator() { - $instance = $this->getInstance([4, 1, 2, 5, 3]); + $instance = static::getInstance([4, 1, 2, 5, 3]); $sorted = $instance->sorted(function($a, $b) { return $b <=> $a; diff --git a/tests/Sequence/sum.php b/tests/Sequence/sum.php index 77e4e51..fa95b58 100644 --- a/tests/Sequence/sum.php +++ b/tests/Sequence/sum.php @@ -1,9 +1,11 @@ =') ? [true, false, null] : ["a", true, false, null]; return [ @@ -28,12 +30,10 @@ public function sumDataProvider() ]; } - /** - * @dataProvider sumDataProvider - */ + #[DataProvider('sumDataProvider')] public function testSum($values, $expected) { - $instance = $this->getInstance($values); + $instance = static::getInstance($values); $this->assertEquals($expected, $instance->sum()); } } diff --git a/tests/Sequence/toArray.php b/tests/Sequence/toArray.php index 758cfc1..6e0ca1f 100644 --- a/tests/Sequence/toArray.php +++ b/tests/Sequence/toArray.php @@ -1,19 +1,19 @@ basicDataProvider(); + return self::basicDataProvider(); } - /** - * @dataProvider toArrayDataProvider - */ + #[DataProvider('toArrayDataProvider')] public function testToArray(array $values, array $expected) { - $instance = $this->getInstance($values); + $instance = static::getInstance($values); $this->assertToArray($expected, $instance); } } diff --git a/tests/Sequence/unshift.php b/tests/Sequence/unshift.php index e380fc6..a497509 100644 --- a/tests/Sequence/unshift.php +++ b/tests/Sequence/unshift.php @@ -1,19 +1,19 @@ basicDataProvider(); + return self::basicDataProvider(); } - /** - * @dataProvider unshiftDataProvider - */ + #[DataProvider('unshiftDataProvider')] public function testUnshiftVariadic(array $initial, array $values) { - $instance = $this->getInstance($initial); + $instance = static::getInstance($initial); $instance->unshift(...$values); $expected = array_merge($values, $initial); @@ -22,12 +22,10 @@ public function testUnshiftVariadic(array $initial, array $values) $this->assertEquals(count($expected), count($instance)); } - /** - * @dataProvider unshiftDataProvider - */ + #[DataProvider('unshiftDataProvider')] public function testUnshift(array $initial, array $values) { - $instance = $this->getInstance($initial); + $instance = static::getInstance($initial); foreach ($values as $value) { $instance->unshift($value); diff --git a/tests/Set/__construct.php b/tests/Set/__construct.php index 27e8779..f737ce1 100644 --- a/tests/Set/__construct.php +++ b/tests/Set/__construct.php @@ -1,13 +1,15 @@ getUniqueAndDuplicateData(); + list($unique, $duplicated) = self::getUniqueAndDuplicateData(); return [ [[], []], @@ -19,17 +21,13 @@ public function constructDataProvider() ]; } - /** - * @dataProvider constructDataProvider - */ + #[DataProvider('constructDataProvider')] public function testConstruct(array $values, array $expected) { $this->assertToArray($expected, new Set($values)); } - /** - * @dataProvider constructDataProvider - */ + #[DataProvider('constructDataProvider')] public function testConstructUsingIterable(array $values, array $expected) { $this->assertToArray($expected, new Set(new \ArrayIterator($values))); diff --git a/tests/Set/_clone.php b/tests/Set/_clone.php index 5258ff3..b336989 100644 --- a/tests/Set/_clone.php +++ b/tests/Set/_clone.php @@ -1,14 +1,14 @@ getInstance($values); + $instance = static::getInstance($values); $clone = clone $instance; diff --git a/tests/Set/_echo.php b/tests/Set/_echo.php index d656e18..4d845ad 100644 --- a/tests/Set/_echo.php +++ b/tests/Set/_echo.php @@ -5,6 +5,6 @@ trait _echo { public function testEcho() { - $this->assertInstanceToString($this->getInstance()); + $this->assertInstanceToString(static::getInstance()); } } diff --git a/tests/Set/_empty.php b/tests/Set/_empty.php index d126ca9..cf1270b 100644 --- a/tests/Set/_empty.php +++ b/tests/Set/_empty.php @@ -5,7 +5,7 @@ trait _empty { public function testArrayAccessEmpty() { - $set = $this->getInstance(['a', 'b', 'c']); + $set = static::getInstance(['a', 'b', 'c']); $this->expectArrayAccessUnsupportedException(); empty($set[0]); } diff --git a/tests/Set/_foreach.php b/tests/Set/_foreach.php index 6943843..ded7fbc 100644 --- a/tests/Set/_foreach.php +++ b/tests/Set/_foreach.php @@ -1,14 +1,14 @@ getInstance($values); + $instance = static::getInstance($values); $this->assertForEach($expected, $instance); } } diff --git a/tests/Set/_isset.php b/tests/Set/_isset.php index ce68470..fce021d 100644 --- a/tests/Set/_isset.php +++ b/tests/Set/_isset.php @@ -5,14 +5,14 @@ trait _isset { public function testArrayAccessIsset() { - $set = $this->getInstance(['a', 'b', 'c']); + $set = static::getInstance(['a', 'b', 'c']); $this->expectArrayAccessUnsupportedException(); isset($set[0]); } public function testArrayAccessIssetByMethod() { - $set = $this->getInstance(['a', 'b', 'c']); + $set = static::getInstance(['a', 'b', 'c']); $this->expectArrayAccessUnsupportedException(); $set->offsetExists(0); } diff --git a/tests/Set/_jsonEncode.php b/tests/Set/_jsonEncode.php index 9cfa4fd..29960a9 100644 --- a/tests/Set/_jsonEncode.php +++ b/tests/Set/_jsonEncode.php @@ -1,14 +1,14 @@ getInstance($initial); + $instance = static::getInstance($initial); $this->assertEquals(json_encode($expected), json_encode($instance)); } } diff --git a/tests/Set/_list.php b/tests/Set/_list.php index c602181..4d7a913 100644 --- a/tests/Set/_list.php +++ b/tests/Set/_list.php @@ -5,7 +5,7 @@ trait _list { public function testList() { - $instance = $this->getInstance(['a', 'b', 'c']); + $instance = static::getInstance(['a', 'b', 'c']); list($a, $b, $c) = $instance; $this->assertEquals('a', $a); diff --git a/tests/Set/_serialize.php b/tests/Set/_serialize.php index bbe55be..6bedfc9 100644 --- a/tests/Set/_serialize.php +++ b/tests/Set/_serialize.php @@ -1,14 +1,14 @@ getInstance($values); + $instance = static::getInstance($values); $this->assertSerialized($expected, $instance, false); } } diff --git a/tests/Set/_unset.php b/tests/Set/_unset.php index a93e1cf..f894a80 100644 --- a/tests/Set/_unset.php +++ b/tests/Set/_unset.php @@ -5,14 +5,14 @@ trait _unset { public function testArrayAccessUnset() { - $set = $this->getInstance(['a', 'b', 'c']); + $set = static::getInstance(['a', 'b', 'c']); $this->expectArrayAccessUnsupportedException(); unset($set[0]); } public function testArrayAccessUnsetByMethod() { - $set = $this->getInstance(); + $set = static::getInstance(); $this->expectArrayAccessUnsupportedException(); $set->offsetUnset('a'); } diff --git a/tests/Set/_var_dump.php b/tests/Set/_var_dump.php index 135a4bb..5533a97 100644 --- a/tests/Set/_var_dump.php +++ b/tests/Set/_var_dump.php @@ -1,14 +1,14 @@ getInstance($values); + $instance = static::getInstance($values); $this->assertInstanceDump($expected, $instance); } } diff --git a/tests/Set/add.php b/tests/Set/add.php index 8197031..7887828 100644 --- a/tests/Set/add.php +++ b/tests/Set/add.php @@ -1,11 +1,13 @@ getUniqueAndDuplicateData(); + list($unique, $duplicates) = self::getUniqueAndDuplicateData(); // initial, input, expected return [ @@ -40,15 +42,13 @@ public function addDataProvider() ]; } - /** - * @dataProvider addDataProvider - */ + #[DataProvider('addDataProvider')] public function testAdd( array $initial, array $values, array $expected ) { - $instance = $this->getInstance($initial); + $instance = static::getInstance($initial); foreach($values as $value) { $instance->add($value); @@ -58,15 +58,13 @@ public function testAdd( $this->assertToArray($expected, $instance); } - /** - * @dataProvider addDataProvider - */ + #[DataProvider('addDataProvider')] public function testArrayAccessAdd( array $initial, array $values, array $expected ) { - $instance = $this->getInstance($initial); + $instance = static::getInstance($initial); foreach($values as $value) { $instance[] = $value; @@ -76,15 +74,13 @@ public function testArrayAccessAdd( $this->assertToArray($expected, $instance); } - /** - * @dataProvider addDataProvider - */ + #[DataProvider('addDataProvider')] public function testArrayAccessAddByMethod( array $initial, array $values, array $expected ) { - $instance = $this->getInstance($initial); + $instance = static::getInstance($initial); foreach($values as $value) { $instance->offsetSet(null, $value); @@ -94,15 +90,13 @@ public function testArrayAccessAddByMethod( $this->assertToArray($expected, $instance); } - /** - * @dataProvider addDataProvider - */ + #[DataProvider('addDataProvider')] public function testAddVariadic( array $initial, array $values, array $expected ) { - $instance = $this->getInstance($initial); + $instance = static::getInstance($initial); $instance->add(...$values); $this->assertEquals(count($expected), count($instance)); @@ -111,15 +105,15 @@ public function testAddVariadic( public function testAddCircularReference() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $instance->add($instance); $this->assertToArray([$instance], $instance); } public function testAddIndirectCircularReference() { - $a = $this->getInstance(); - $b = $this->getInstance(); + $a = static::getInstance(); + $b = static::getInstance(); $a->add($b); $b->add($a); diff --git a/tests/Set/allocate.php b/tests/Set/allocate.php index 82610ea..f8f4b03 100644 --- a/tests/Set/allocate.php +++ b/tests/Set/allocate.php @@ -1,9 +1,11 @@ getInstance(); + $instance = static::getInstance(); $instance->allocate($initial); $instance->allocate($allocate); diff --git a/tests/Set/capacity.php b/tests/Set/capacity.php index 9e07e86..73b6741 100644 --- a/tests/Set/capacity.php +++ b/tests/Set/capacity.php @@ -9,7 +9,7 @@ public function testCapacity() { $min = Set::MIN_CAPACITY; - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->assertEquals($min, $instance->capacity()); for ($i = 0; $i < $min; $i++) { @@ -44,7 +44,7 @@ public function testAutoTruncate() 0 => 8, ]; - $instance = $this->getInstance(range(1, array_keys($boundaries)[0])); + $instance = static::getInstance(range(1, array_keys($boundaries)[0])); for(;;) { if ( ! is_null(($expected = $boundaries[$instance->count()] ?? null))) { @@ -61,7 +61,7 @@ public function testAutoTruncate() public function testClearResetsCapacity() { - $instance = $this->getInstance(range(1, self::MANY)); + $instance = static::getInstance(range(1, self::MANY)); $instance->clear(); $this->assertEquals(Set::MIN_CAPACITY, $instance->capacity()); } diff --git a/tests/Set/clear.php b/tests/Set/clear.php index a698b01..9031772 100644 --- a/tests/Set/clear.php +++ b/tests/Set/clear.php @@ -5,7 +5,7 @@ trait clear { public function testClear() { - $instance = $this->getInstance($this->sample()); + $instance = static::getInstance(self::sample()); $instance->clear(); $this->assertToArray([], $instance); diff --git a/tests/Set/contains.php b/tests/Set/contains.php index 84cca10..0b81a4a 100644 --- a/tests/Set/contains.php +++ b/tests/Set/contains.php @@ -1,11 +1,13 @@ getUniqueAndDuplicateData(); + list($sample, $duplicates) = self::getUniqueAndDuplicateData(); // initial, values, contains return [ @@ -25,15 +27,13 @@ public function containsDataProvider() ]; } - /** - * @dataProvider containsDataProvider - */ + #[DataProvider('containsDataProvider')] public function testContains( array $initial, array $values, bool $contains ) { - $set = $this->getInstance($initial); + $set = static::getInstance($initial); $this->assertEquals($contains, $set->contains(...$values)); } } diff --git a/tests/Set/copy.php b/tests/Set/copy.php index 943a041..d609e57 100644 --- a/tests/Set/copy.php +++ b/tests/Set/copy.php @@ -1,14 +1,14 @@ getInstance($values); + $instance = static::getInstance($values); $copy = $instance->copy(); $this->assertEquals($instance->toArray(), $copy->toArray()); diff --git a/tests/Set/count.php b/tests/Set/count.php index 1692e28..82fa870 100644 --- a/tests/Set/count.php +++ b/tests/Set/count.php @@ -5,18 +5,18 @@ trait count { public function testCount() { - list($unique, $duplicates) = $this->getUniqueAndDuplicateData(); + list($unique, $duplicates) = self::getUniqueAndDuplicateData(); - $instance = $this->getInstance($unique); + $instance = static::getInstance($unique); $this->assertCount(count($unique), $instance); - $instance = $this->getInstance($duplicates); + $instance = static::getInstance($duplicates); $this->assertCount(count($unique), $instance); } public function testCountEmpty() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->assertCount(0, $instance); } } diff --git a/tests/Set/diff.php b/tests/Set/diff.php index 6253a12..9b37e1c 100644 --- a/tests/Set/diff.php +++ b/tests/Set/diff.php @@ -1,9 +1,11 @@ getInstance($a); - $b = $this->getInstance($b); + $a = static::getInstance($a); + $b = static::getInstance($b); $this->assertEquals($expected, $a->diff($b)->toArray()); } @@ -33,8 +33,8 @@ public function testDiff(array $a, array $b, array $expected) // */ // public function testDiffOperator(array $a, array $b, array $expected) // { - // $a = $this->getInstance($a); - // $b = $this->getInstance($b); + // $a = static::getInstance($a); + // $b = static::getInstance($b); // $this->assertEquals($expected, ($a - $b)->toArray()); // } @@ -44,19 +44,17 @@ public function testDiff(array $a, array $b, array $expected) // */ // public function testDiffOperatorAssign(array $a, array $b, array $expected) // { - // $a = $this->getInstance($a); - // $b = $this->getInstance($b); + // $a = static::getInstance($a); + // $b = static::getInstance($b); // $a -= $b; // $this->assertEquals($expected, $a->toArray()); // } - /** - * @dataProvider diffDataProvider - */ + #[DataProvider('diffDataProvider')] public function testDiffWithSelf(array $a, array $b, array $expected) { - $a = $this->getInstance($a); + $a = static::getInstance($a); $this->assertEquals([], $a->diff($a)->toArray()); } @@ -65,7 +63,7 @@ public function testDiffWithSelf(array $a, array $b, array $expected) // */ // public function testDiffOperatorWithSelf(array $a, array $b, array $expected) // { - // $a = $this->getInstance($a); + // $a = static::getInstance($a); // $this->assertEquals([], ($a - $a)->toArray()); // } @@ -74,7 +72,7 @@ public function testDiffWithSelf(array $a, array $b, array $expected) // */ // public function testDiffOperatorAssignWithSelf(array $a, array $b, array $expected) // { - // $a = $this->getInstance($a); + // $a = static::getInstance($a); // $a -= $a; // $this->assertEquals([], $a->toArray()); diff --git a/tests/Set/filter.php b/tests/Set/filter.php index b626173..be27b1e 100644 --- a/tests/Set/filter.php +++ b/tests/Set/filter.php @@ -1,9 +1,11 @@ getInstance($values); + $instance = static::getInstance($values); $filtered = $instance->filter($callback); $expected = array_values(array_filter($values, $callback)); @@ -28,12 +28,10 @@ public function testFilter(array $values, callable $callback) $this->assertEquals($expected, $filtered->toArray()); } - /** - * @dataProvider filterDataProvider - */ + #[DataProvider('filterDataProvider')] public function testFilterWithoutCallback(array $values, callable $callback) { - $instance = $this->getInstance($values); + $instance = static::getInstance($values); $filtered = $instance->filter(); $expected = array_values(array_filter($values)); @@ -44,7 +42,7 @@ public function testFilterWithoutCallback(array $values, callable $callback) public function testFilterCallbackThrowsException() { - $instance = $this->getInstance([1, 2, 3]); + $instance = static::getInstance([1, 2, 3]); $filtered = null; try { @@ -62,7 +60,7 @@ public function testFilterCallbackThrowsException() public function testFilterCallbackThrowsExceptionLaterOn() { - $instance = $this->getInstance([1, 2, 3]); + $instance = static::getInstance([1, 2, 3]); $filtered = null; try { diff --git a/tests/Set/first.php b/tests/Set/first.php index 58d97d8..2053538 100644 --- a/tests/Set/first.php +++ b/tests/Set/first.php @@ -1,9 +1,11 @@ getInstance($initial); + $instance = static::getInstance($initial); $this->assertEquals($expected, $instance->first()); } public function testFirstNowAllowedWhenEmpty() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->expectEmptyNotAllowedException(); $instance->first(); } diff --git a/tests/Set/get.php b/tests/Set/get.php index 7ce2cc3..6fee2c8 100644 --- a/tests/Set/get.php +++ b/tests/Set/get.php @@ -1,9 +1,11 @@ getInstance($initial); + $instance = static::getInstance($initial); $returned = $instance->get($index); @@ -34,67 +34,55 @@ public function testGet(array $initial, $index, $return) $this->assertEquals($return, $returned); } - /** - * @dataProvider outOfRangeDataProvider - */ + #[DataProvider('outOfRangeDataProvider')] public function testGetIndexOutOfRange($initial, $index) { - $instance = $this->getInstance($initial); + $instance = static::getInstance($initial); $this->expectIndexOutOfRangeException(); $instance->get($index); } - /** - * @dataProvider badIndexDataProvider - */ + #[DataProvider('badIndexDataProvider')] public function testGetIndexBadIndex($initial, $index) { - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->expectWrongIndexTypeException(); $instance->get($index); } - /** - * @dataProvider getDataProvider - */ + #[DataProvider('getDataProvider')] public function testArrayAccessGet(array $initial, $index, $return) { - $instance = $this->getInstance($initial); + $instance = static::getInstance($initial); $this->assertEquals($return, $instance[$index]); } - /** - * @dataProvider getDataProvider - */ + #[DataProvider('getDataProvider')] public function testArrayAccessGetByMethod(array $initial, $index, $return) { - $instance = $this->getInstance($initial); + $instance = static::getInstance($initial); $this->assertEquals($return, $instance->offsetGet($index)); } - /** - * @dataProvider badIndexDataProvider - */ + #[DataProvider('badIndexDataProvider')] public function testArrayAccessGetIndexBadIndex($initial, $index) { - $instance = $this->getInstance($initial); + $instance = static::getInstance($initial); $this->expectWrongIndexTypeException(); $instance[$index]; } - /** - * @dataProvider outOfRangeDataProvider - */ + #[DataProvider('outOfRangeDataProvider')] public function testArrayAccessGetIndexOutOfRange($initial, $index) { - $instance = $this->getInstance($initial); + $instance = static::getInstance($initial); $this->expectIndexOutOfRangeException(); $instance[$index]; } public function testGetFirstAfterRemove() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $instance->add('a', 'b', 'c'); $this->assertEquals('a', $instance->get(0)); @@ -108,7 +96,7 @@ public function testGetFirstAfterRemove() public function testGetLastAfterRemove() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $instance->add('a', 'b', 'c'); $this->assertEquals('c', $instance->get(2)); @@ -120,7 +108,7 @@ public function testGetLastAfterRemove() $this->assertEquals('a', $instance->get(0)); } - public function getAfterRemoveProvider() + public static function getAfterRemoveProvider() { // values, value to remove, get index, expected result return [ @@ -135,12 +123,10 @@ public function getAfterRemoveProvider() ]; } - /** - * @dataProvider getAfterRemoveProvider - */ + #[DataProvider('getAfterRemoveProvider')] public function testGetAfterRemove(array $values, $remove, $index, $expected) { - $instance = $this->getInstance($values); + $instance = static::getInstance($values); $instance->remove($remove); $this->assertEquals($expected, $instance->get($index)); @@ -148,7 +134,7 @@ public function testGetAfterRemove(array $values, $remove, $index, $expected) public function testGetAfterRemoveAtTheStart() { - $instance = $this->getInstance(['a', 'b', 'c', 'd', 'e']); + $instance = static::getInstance(['a', 'b', 'c', 'd', 'e']); $instance->remove('a'); $this->assertEquals('b', $instance->get(0)); @@ -174,7 +160,7 @@ public function testGetAfterRemoveAtTheStart() public function testGetAfterRemoveAtTheEnd() { - $instance = $this->getInstance(['a', 'b', 'c', 'd', 'e']); + $instance = static::getInstance(['a', 'b', 'c', 'd', 'e']); $instance->remove('e'); $this->assertEquals('a', $instance->get(0)); @@ -200,7 +186,7 @@ public function testGetAfterRemoveAtTheEnd() public function testGetAfterMultipleRemoveAtEitherEnd() { - $instance = $this->getInstance(['a', 'b', 'c', 'd', 'e']); + $instance = static::getInstance(['a', 'b', 'c', 'd', 'e']); $instance->remove('a'); $this->assertEquals('b', $instance->get(0)); diff --git a/tests/Set/intersect.php b/tests/Set/intersect.php index 9e03c86..cc5b991 100644 --- a/tests/Set/intersect.php +++ b/tests/Set/intersect.php @@ -1,9 +1,11 @@ getInstance($initial); - $b = $this->getInstance($values); + $a = static::getInstance($initial); + $b = static::getInstance($values); $this->assertEquals($expected, $a->intersect($b)->toArray()); } - /** - * @dataProvider intersectDataProvider - */ + #[DataProvider('intersectDataProvider')] public function testIntersectWithSelf(array $initial, array $values, array $expected) { - $a = $this->getInstance($initial); + $a = static::getInstance($initial); $this->assertEquals($initial, $a->intersect($a)->toArray()); } @@ -42,8 +40,8 @@ public function testIntersectWithSelf(array $initial, array $values, array $expe */ public function testIntersectContains() { - $ab = $this->getInstance(["a", "b"]); - $bc = $this->getInstance(["b", "c"]); + $ab = static::getInstance(["a", "b"]); + $bc = static::getInstance(["b", "c"]); $b = $ab->intersect($bc); @@ -59,8 +57,8 @@ public function testIntersectContains() */ public function testIntersectAdd() { - $ab = $this->getInstance(["a", "b"]); - $bc = $this->getInstance(["b", "c"]); + $ab = static::getInstance(["a", "b"]); + $bc = static::getInstance(["b", "c"]); $b = $ab->intersect($bc); $b->add("b"); @@ -73,8 +71,8 @@ public function testIntersectAdd() // */ // public function testIntersectOperator(array $initial, array $values, array $expected) // { - // $a = $this->getInstance($initial); - // $b = $this->getInstance($values); + // $a = static::getInstance($initial); + // $b = static::getInstance($values); // $this->assertEquals($expected, ($a & $b)->toArray()); // } @@ -84,8 +82,8 @@ public function testIntersectAdd() // */ // public function testIntersectOperatorAssign(array $initial, array $values, array $expected) // { - // $a = $this->getInstance($initial); - // $b = $this->getInstance($values); + // $a = static::getInstance($initial); + // $b = static::getInstance($values); // $a &= $b; // $this->assertEquals($expected, $a->toArray()); @@ -96,7 +94,7 @@ public function testIntersectAdd() // */ // public function testIntersectOperatorWithSelf(array $initial, array $values, array $expected) // { - // $a = $this->getInstance($initial); + // $a = static::getInstance($initial); // $this->assertEquals($initial, ($a & $a)->toArray()); // } @@ -105,7 +103,7 @@ public function testIntersectAdd() // */ // public function testIntersectOperatorAssignWithSelf(array $initial, array $values, array $expected) // { - // $a = $this->getInstance($initial); + // $a = static::getInstance($initial); // $a &= $a; // $this->assertEquals($initial, $a->toArray()); diff --git a/tests/Set/isEmpty.php b/tests/Set/isEmpty.php index 26d908c..cf8377d 100644 --- a/tests/Set/isEmpty.php +++ b/tests/Set/isEmpty.php @@ -1,9 +1,11 @@ getInstance($values); + $instance = static::getInstance($values); $this->assertEquals($isEmpty, $instance->isEmpty()); } public function testIsNotEmptyAfterRemove() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->assertTrue($instance->isEmpty()); $instance->add('a'); diff --git a/tests/Set/join.php b/tests/Set/join.php index 7b09e7b..3e3a81e 100644 --- a/tests/Set/join.php +++ b/tests/Set/join.php @@ -1,9 +1,11 @@ getInstance($values); + $instance = static::getInstance($values); $expected = join($glue, $values); $this->assertEquals($expected, $instance->join($glue)); } - /** - * @dataProvider joinDataProvider - */ + #[DataProvider('joinDataProvider')] public function testJoinWithoutGlue(array $values, $glue) { - $instance = $this->getInstance($values); + $instance = static::getInstance($values); $expected = join($values); $this->assertEquals($expected, $instance->join()); } diff --git a/tests/Set/last.php b/tests/Set/last.php index 67d45a5..2e31d64 100644 --- a/tests/Set/last.php +++ b/tests/Set/last.php @@ -1,9 +1,11 @@ getInstance($initial); + $instance = static::getInstance($initial); $this->assertEquals($expected, $instance->last()); } public function testLastNotAllowedWhenEmpty() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->expectEmptyNotAllowedException(); $instance->last(); } diff --git a/tests/Set/map.php b/tests/Set/map.php index bbbe75a..a6ab43f 100644 --- a/tests/Set/map.php +++ b/tests/Set/map.php @@ -1,9 +1,11 @@ getInstance($values); + $instance = static::getInstance($values); $mapped = $instance->map($callback); $expected = array_unique(array_map($callback, $values)); @@ -39,7 +39,7 @@ public function testMap(array $values, callable $callback) public function testMapCallbackThrowsException() { - $instance = $this->getInstance([1, 2, 3]); + $instance = static::getInstance([1, 2, 3]); $mapped = null; try { @@ -57,7 +57,7 @@ public function testMapCallbackThrowsException() public function testMapCallbackThrowsExceptionLaterOn() { - $instance = $this->getInstance([1, 2, 3]); + $instance = static::getInstance([1, 2, 3]); $mapped = null; try { @@ -79,7 +79,7 @@ public function testMapCallbackThrowsExceptionLaterOn() public function testMapDoesNotLeakWhenCallbackFails() { - $instance = $this->getInstance(["a", "b", "c"]); + $instance = static::getInstance(["a", "b", "c"]); static::expectException(\Exception::class); diff --git a/tests/Set/merge.php b/tests/Set/merge.php index b1c27ee..538493d 100644 --- a/tests/Set/merge.php +++ b/tests/Set/merge.php @@ -1,9 +1,11 @@ getInstance($initial); + $instance = static::getInstance($initial); $this->assertToArray($expected, $instance->merge($values)); $this->assertToArray($initial, $instance); } - /** - * @dataProvider mergeDataProvider - */ + #[DataProvider('mergeDataProvider')] public function testMergeWithSelf(array $initial, array $values, array $expected) { - $instance = $this->getInstance($initial); + $instance = static::getInstance($initial); $this->assertToArray($initial, $instance->merge($instance)); $this->assertToArray($initial, $instance); diff --git a/tests/Set/reduce.php b/tests/Set/reduce.php index 2fe10cb..5ef98ca 100644 --- a/tests/Set/reduce.php +++ b/tests/Set/reduce.php @@ -1,9 +1,11 @@ getInstance($values); + $instance = static::getInstance($values); $reduced = $instance->reduce($callback, $initial); $expected = array_reduce($values, $callback, $initial); @@ -33,12 +33,10 @@ public function testReduce(array $values, $initial, callable $callback) $this->assertEquals($expected, $reduced); } - /** - * @dataProvider reduceDataProvider - */ + #[DataProvider('reduceDataProvider')] public function testReduceWithoutInitial(array $values, $initial, callable $callback) { - $instance = $this->getInstance($values); + $instance = static::getInstance($values); $reduced = $instance->reduce($callback); $expected = array_reduce($values, $callback); @@ -49,7 +47,7 @@ public function testReduceWithoutInitial(array $values, $initial, callable $call public function testReduceCallbackThrowsException() { - $instance = $this->getInstance([1, 2, 3]); + $instance = static::getInstance([1, 2, 3]); $result = null; try { @@ -67,7 +65,7 @@ public function testReduceCallbackThrowsException() public function testReduceCallbackThrowsExceptionLaterOn() { - $instance = $this->getInstance([1, 2, 3]); + $instance = static::getInstance([1, 2, 3]); $result = null; try { diff --git a/tests/Set/remove.php b/tests/Set/remove.php index a6f6b4d..2482865 100644 --- a/tests/Set/remove.php +++ b/tests/Set/remove.php @@ -1,11 +1,13 @@ getUniqueAndDuplicateData(); + list($unique, $duplicates) = self::getUniqueAndDuplicateData(); // initial, values to remove, expected. return [ @@ -34,15 +36,13 @@ public function removeDataProvider() ]; } - /** - * @dataProvider removeDataProvider - */ + #[DataProvider('removeDataProvider')] public function testRemove( array $initial, array $values, array $expected ) { - $instance = $this->getInstance($initial); + $instance = static::getInstance($initial); foreach ($values as $value) { $instance->remove($value); @@ -59,15 +59,13 @@ public function testRemove( } } - /** - * @dataProvider removeDataProvider - */ + #[DataProvider('removeDataProvider')] public function testRemoveVariadic( array $initial, array $values, array $expected ) { - $instance = $this->getInstance($initial); + $instance = static::getInstance($initial); $instance->remove(...$values); $this->assertEquals(count($expected), count($instance)); diff --git a/tests/Set/reverse.php b/tests/Set/reverse.php index 458179f..7c06fc0 100644 --- a/tests/Set/reverse.php +++ b/tests/Set/reverse.php @@ -1,21 +1,21 @@ basicDataProvider() + self::basicDataProvider() ); } - /** - * @dataProvider reverseDataProvider - */ + #[DataProvider('reverseDataProvider')] public function testReverse(array $values, array $expected) { - $instance = $this->getInstance($values); + $instance = static::getInstance($values); $instance->reverse(); $this->assertToArray($expected, $instance); diff --git a/tests/Set/reversed.php b/tests/Set/reversed.php index 2ac5d2a..a10d034 100644 --- a/tests/Set/reversed.php +++ b/tests/Set/reversed.php @@ -1,21 +1,21 @@ basicDataProvider() + self::basicDataProvider() ); } - /** - * @dataProvider reversedDataProvider - */ + #[DataProvider('reversedDataProvider')] public function testReversed(array $values, array $expected) { - $instance = $this->getInstance($values); + $instance = static::getInstance($values); $reversed = $instance->reversed(); $this->assertToArray($expected, $reversed); diff --git a/tests/Set/slice.php b/tests/Set/slice.php index fa08d78..2b9d8d2 100644 --- a/tests/Set/slice.php +++ b/tests/Set/slice.php @@ -1,9 +1,11 @@ getInstance($values); + $instance = static::getInstance($values); $sliced = $instance->slice($index, $length); $expected = array_slice($values, $index, $length); @@ -34,12 +34,10 @@ public function testSlice(array $values, int $index, int $length) $this->assertToArray($expected, $sliced); } - /** - * @dataProvider sliceDataProvider - */ + #[DataProvider('sliceDataProvider')] public function testSliceWithoutLength(array $values, int $index, int $length) { - $instance = $this->getInstance($values); + $instance = static::getInstance($values); $sliced = $instance->slice($index); $expected = array_slice($values, $index, null); @@ -48,12 +46,10 @@ public function testSliceWithoutLength(array $values, int $index, int $length) $this->assertToArray($expected, $sliced); } - /** - * @dataProvider sliceDataProvider - */ + #[DataProvider('sliceDataProvider')] public function testSliceWithLengthNull(array $values, int $index, int $length) { - $instance = $this->getInstance($values); + $instance = static::getInstance($values); $sliced = $instance->slice($index, null); $expected = array_slice($values, $index, null); @@ -64,7 +60,7 @@ public function testSliceWithLengthNull(array $values, int $index, int $length) public function testSliceAfterRemoveOutsideOfSlice() { - $instance = $this->getInstance(['a', 'b', 'c', 'd', 'e']); + $instance = static::getInstance(['a', 'b', 'c', 'd', 'e']); $instance->remove('d'); $this->assertToArray(['a', 'b', 'c'], $instance->slice(0, 3)); @@ -72,7 +68,7 @@ public function testSliceAfterRemoveOutsideOfSlice() public function testSliceAfterRemoveAtStartOfSlice() { - $instance = $this->getInstance(['a', 'b', 'c', 'd', 'e']); + $instance = static::getInstance(['a', 'b', 'c', 'd', 'e']); $instance->remove('b'); $this->assertToArray(['c', 'd', 'e'], $instance->slice(1)); @@ -80,7 +76,7 @@ public function testSliceAfterRemoveAtStartOfSlice() public function testSliceAfterRemoveWithinSlice() { - $instance = $this->getInstance(['a', 'b', 'c', 'd', 'e']); + $instance = static::getInstance(['a', 'b', 'c', 'd', 'e']); $instance->remove('c'); $this->assertToArray(['b', 'd', 'e'], $instance->slice(1)); @@ -92,7 +88,7 @@ public function testLargeSliceHalf() $x = 0; $y = intdiv($n, 2); - $instance = $this->getInstance(range(0, $n)); + $instance = static::getInstance(range(0, $n)); $this->assertToArray(range($x, $y - 1), $instance->slice($x, $y)); $this->assertToArray(range($y, $n), $instance->slice($y)); @@ -104,7 +100,7 @@ public function testLargeSliceOffset() $x = intdiv($n, 4); $y = intdiv($n, 4) + intdiv($n, 2); - $instance = $this->getInstance(range(0, $n)); + $instance = static::getInstance(range(0, $n)); $this->assertToArray(range($x, $y - 1), $instance->slice($x, $y - $x)); } diff --git a/tests/Set/sort.php b/tests/Set/sort.php index b2a5bcf..9c805bb 100644 --- a/tests/Set/sort.php +++ b/tests/Set/sort.php @@ -5,7 +5,7 @@ trait sort { public function testSort() { - $instance = $this->getInstance([4, 1, 2, 5, 3]); + $instance = static::getInstance([4, 1, 2, 5, 3]); $instance->sort(); $this->assertToArray([1, 2, 3, 4, 5], $instance); @@ -13,7 +13,7 @@ public function testSort() public function testSortUsingComparator() { - $instance = $this->getInstance([4, 1, 2, 5, 3]); + $instance = static::getInstance([4, 1, 2, 5, 3]); $instance->sort(function($a, $b) { return $b <=> $a; diff --git a/tests/Set/sorted.php b/tests/Set/sorted.php index 586e921..0db5d5f 100644 --- a/tests/Set/sorted.php +++ b/tests/Set/sorted.php @@ -5,7 +5,7 @@ trait sorted { public function testSorted() { - $instance = $this->getInstance([4, 1, 2, 5, 3]); + $instance = static::getInstance([4, 1, 2, 5, 3]); $sorted = $instance->sorted(); @@ -15,7 +15,7 @@ public function testSorted() public function testSortedUsingComparator() { - $instance = $this->getInstance([4, 1, 2, 5, 3]); + $instance = static::getInstance([4, 1, 2, 5, 3]); $sorted = $instance->sorted(function($a, $b) { return $b <=> $a; diff --git a/tests/Set/sum.php b/tests/Set/sum.php index ce4a621..f474105 100644 --- a/tests/Set/sum.php +++ b/tests/Set/sum.php @@ -1,9 +1,11 @@ =') ? [true, false, null] : ["a", true, false, null]; return [ @@ -28,12 +30,10 @@ public function sumDataProvider() ]; } - /** - * @dataProvider sumDataProvider - */ + #[DataProvider('sumDataProvider')] public function testSum($values, $expected) { - $instance = $this->getInstance($values); + $instance = static::getInstance($values); $this->assertEquals($expected, $instance->sum()); } } diff --git a/tests/Set/toArray.php b/tests/Set/toArray.php index 86efc91..aaf21f1 100644 --- a/tests/Set/toArray.php +++ b/tests/Set/toArray.php @@ -1,14 +1,14 @@ getInstance($values); + $instance = static::getInstance($values); $this->assertToArray($expected, $instance); } } diff --git a/tests/Set/union.php b/tests/Set/union.php index 776b8b1..0f5618f 100644 --- a/tests/Set/union.php +++ b/tests/Set/union.php @@ -1,9 +1,11 @@ getInstance($initial); - $b = $this->getInstance($values); + $a = static::getInstance($initial); + $b = static::getInstance($values); $this->assertEquals($expected, $a->union($b)->toArray()); } - /** - * @dataProvider unionDataProvider - */ + #[DataProvider('unionDataProvider')] public function testUnionWithSelf(array $initial, array $values, array $expected) { - $a = $this->getInstance($initial); + $a = static::getInstance($initial); $this->assertEquals($initial, $a->union($a)->toArray()); } @@ -41,8 +39,8 @@ public function testUnionWhenOperatingOnSetsWithObjectsWithNonZeroHash() $a = new \Ds\Tests\HashableObject("a", rand()); $b = new \Ds\Tests\HashableObject("b", rand()); - $setA = $this->getInstance([$a]); - $setB = $this->getInstance([$b]); + $setA = static::getInstance([$a]); + $setB = static::getInstance([$b]); $this->assertToArray([$a, $b], $setA->union($setB)); } @@ -52,8 +50,8 @@ public function testUnionWhenOperatingOnSetsWithObjectsWithZeroHash() $a = new \Ds\Tests\HashableObject("a", 0); $b = new \Ds\Tests\HashableObject("b", 0); - $setA = $this->getInstance([$a]); - $setB = $this->getInstance([$b]); + $setA = static::getInstance([$a]); + $setB = static::getInstance([$b]); $this->assertToArray([$a, $b], $setA->union($setB)); } @@ -63,8 +61,8 @@ public function testUnionWhenOperatingOnSetsWithObjectsWithZeroHash() // */ // public function testUnionOperator(array $initial, array $values, array $expected) // { - // $a = $this->getInstance($initial); - // $b = $this->getInstance($values); + // $a = static::getInstance($initial); + // $b = static::getInstance($values); // $this->assertEquals($expected, ($a | $b)->toArray()); // } @@ -74,8 +72,8 @@ public function testUnionWhenOperatingOnSetsWithObjectsWithZeroHash() // */ // public function testUnionOperatorAssign(array $initial, array $values, array $expected) // { - // $a = $this->getInstance($initial); - // $b = $this->getInstance($values); + // $a = static::getInstance($initial); + // $b = static::getInstance($values); // $a |= $b; // $this->assertEquals($expected, $a->toArray()); @@ -86,7 +84,7 @@ public function testUnionWhenOperatingOnSetsWithObjectsWithZeroHash() // */ // public function testUnionOperatorWithSelf(array $initial, array $values, array $expected) // { - // $a = $this->getInstance($initial); + // $a = static::getInstance($initial); // $this->assertEquals($initial, ($a | $a)->toArray()); // } @@ -95,7 +93,7 @@ public function testUnionWhenOperatingOnSetsWithObjectsWithZeroHash() // */ // public function testUnionOperatorAssignWithSelf(array $initial, array $values, array $expected) // { - // $a = $this->getInstance($initial); + // $a = static::getInstance($initial); // $a |= $a; // $this->assertEquals($initial, $a->toArray()); diff --git a/tests/Set/xor_.php b/tests/Set/xor_.php index 79071ce..b48c6d6 100644 --- a/tests/Set/xor_.php +++ b/tests/Set/xor_.php @@ -1,9 +1,11 @@ getInstance($a); - $b = $this->getInstance($b); + $a = static::getInstance($a); + $b = static::getInstance($b); $this->assertEquals($expected, $a->xor($b)->toArray()); } - /** - * @dataProvider xorDataProvider - */ + #[DataProvider('xorDataProvider')] public function testXorWithSelf(array $a, array $b, array $expected) { - $a = $this->getInstance($a); + $a = static::getInstance($a); $this->assertEquals([], $a->xor($a)->toArray()); } @@ -40,8 +38,8 @@ public function testXorWithSelf(array $a, array $b, array $expected) */ public function testXorAfterDiff() { - $a = $this->getInstance(['guest', 'member']); - $b = $this->getInstance(['member', 'nothing']); + $a = static::getInstance(['guest', 'member']); + $b = static::getInstance(['member', 'nothing']); $k = $a->diff($b); // [guest] $x = $a->xor($k); // [guest, member] ^ [guest] = [member] @@ -54,8 +52,8 @@ public function testXorAfterDiff() // */ // public function testXorOperator(array $a, array $b, array $expected) // { - // $a = $this->getInstance($a); - // $b = $this->getInstance($b); + // $a = static::getInstance($a); + // $b = static::getInstance($b); // $this->assertEquals($expected, ($a ^ $b)->toArray()); // } @@ -65,8 +63,8 @@ public function testXorAfterDiff() // */ // public function testXorOperatorAssign(array $a, array $b, array $expected) // { - // $a = $this->getInstance($a); - // $b = $this->getInstance($b); + // $a = static::getInstance($a); + // $b = static::getInstance($b); // $a ^= $b; // $this->assertEquals($expected, $a->toArray()); @@ -77,7 +75,7 @@ public function testXorAfterDiff() // */ // public function testXorOperatorWithSelf(array $a, array $b, array $expected) // { - // $a = $this->getInstance($a); + // $a = static::getInstance($a); // $this->assertEquals([], ($a ^ $a)->toArray()); // } @@ -86,7 +84,7 @@ public function testXorAfterDiff() // */ // public function testXorOperatorAssignWithSelf(array $a, array $b, array $expected) // { - // $a = $this->getInstance($a); + // $a = static::getInstance($a); // $a ^= $a; // $this->assertEquals([], $a->toArray()); diff --git a/tests/SetTest.php b/tests/SetTest.php index c6a552b..d1d4ced 100644 --- a/tests/SetTest.php +++ b/tests/SetTest.php @@ -3,7 +3,7 @@ use ArrayAccess; -class SetTest extends CollectionTest +class SetTest extends CollectionTestCase { use Set\__construct; use Set\_clone; @@ -46,14 +46,14 @@ class SetTest extends CollectionTest use Set\union; use Set\xor_; - public function getInstance(array $values = []) + public static function getInstance(array $values = []) { return new \Ds\Set($values); } - public function getUniqueAndDuplicateData() + public static function getUniqueAndDuplicateData() { - $sample = $this->sample(); + $sample = self::sample(); $duplicates = []; foreach ($sample as $value) { @@ -71,14 +71,14 @@ public function getUniqueAndDuplicateData() public function testArrayAccessSet() { - $set = $this->getInstance(); + $set = static::getInstance(); $this->expectArrayAccessUnsupportedException(); $set['a'] = 1; } public function testImplementsArrayAccess() { - $this->assertInstanceOf(ArrayAccess::class, $this->getInstance()); + $this->assertInstanceOf(ArrayAccess::class, static::getInstance()); } /** diff --git a/tests/Stack/__construct.php b/tests/Stack/__construct.php index 5272ebd..0745087 100644 --- a/tests/Stack/__construct.php +++ b/tests/Stack/__construct.php @@ -1,32 +1,30 @@ sample()], + [self::sample()], ]; } - /** - * @dataProvider constructDataProvider - */ + #[DataProvider('constructDataProvider')] public function testConstruct(array $values) { $this->assertToArray(array_reverse($values), new Stack($values)); } - /** - * @dataProvider constructDataProvider - */ + #[DataProvider('constructDataProvider')] public function testConstructUsingIterable(array $values) { $this->assertToArray(array_reverse($values), new Stack(new \ArrayIterator($values))); diff --git a/tests/Stack/_clone.php b/tests/Stack/_clone.php index 5cc26ab..6f0b23d 100644 --- a/tests/Stack/_clone.php +++ b/tests/Stack/_clone.php @@ -1,14 +1,14 @@ getInstance($values); + $instance = static::getInstance($values); $clone = clone $instance; diff --git a/tests/Stack/_echo.php b/tests/Stack/_echo.php index fe6c0f0..dc8b65a 100644 --- a/tests/Stack/_echo.php +++ b/tests/Stack/_echo.php @@ -5,6 +5,6 @@ trait _echo { public function testEcho() { - $this->assertInstanceToString($this->getInstance()); + $this->assertInstanceToString(static::getInstance()); } } diff --git a/tests/Stack/_empty.php b/tests/Stack/_empty.php index 74de072..246b313 100644 --- a/tests/Stack/_empty.php +++ b/tests/Stack/_empty.php @@ -5,7 +5,7 @@ trait _empty { public function testArrayAccessEmpty() { - $set = $this->getInstance(); + $set = static::getInstance(); $this->expectArrayAccessUnsupportedException(); empty($set['a']); } diff --git a/tests/Stack/_foreach.php b/tests/Stack/_foreach.php index f95cbb0..3869302 100644 --- a/tests/Stack/_foreach.php +++ b/tests/Stack/_foreach.php @@ -5,7 +5,7 @@ trait _foreach { public function testForEach() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $instance->push('a'); $instance->push('b'); diff --git a/tests/Stack/_isset.php b/tests/Stack/_isset.php index d1d8c4c..2b4f5ee 100644 --- a/tests/Stack/_isset.php +++ b/tests/Stack/_isset.php @@ -5,7 +5,7 @@ trait _isset { public function testArrayAccessIsset() { - $set = $this->getInstance(); + $set = static::getInstance(); $this->expectArrayAccessUnsupportedException(); isset($set['a']); } diff --git a/tests/Stack/_jsonEncode.php b/tests/Stack/_jsonEncode.php index 9e0803e..ab78353 100644 --- a/tests/Stack/_jsonEncode.php +++ b/tests/Stack/_jsonEncode.php @@ -1,14 +1,14 @@ getInstance($initial); + $instance = static::getInstance($initial); $this->assertEquals(json_encode($expected), json_encode($instance)); } } diff --git a/tests/Stack/_list.php b/tests/Stack/_list.php index f649974..b6b12db 100644 --- a/tests/Stack/_list.php +++ b/tests/Stack/_list.php @@ -5,7 +5,7 @@ trait _list { public function testList() { - $instance = $this->getInstance(['a', 'b', 'c']); + $instance = static::getInstance(['a', 'b', 'c']); $this->expectListNotSupportedException(); list($a, $b, $c) = $instance; } diff --git a/tests/Stack/_serialize.php b/tests/Stack/_serialize.php index a3300e0..c099bab 100644 --- a/tests/Stack/_serialize.php +++ b/tests/Stack/_serialize.php @@ -1,18 +1,18 @@ getInstance($values); + $instance = static::getInstance($values); $this->assertSerialized($expected, $instance, false); } } diff --git a/tests/Stack/_unset.php b/tests/Stack/_unset.php index 064ccbf..86d7ab2 100644 --- a/tests/Stack/_unset.php +++ b/tests/Stack/_unset.php @@ -5,7 +5,7 @@ trait _unset { public function testArrayAccessUnset() { - $set = $this->getInstance(); + $set = static::getInstance(); $this->expectArrayAccessUnsupportedException(); unset($set['a']); } diff --git a/tests/Stack/_var_dump.php b/tests/Stack/_var_dump.php index 37fd500..48038dd 100644 --- a/tests/Stack/_var_dump.php +++ b/tests/Stack/_var_dump.php @@ -1,14 +1,14 @@ getInstance($values); + $instance = static::getInstance($values); $this->assertInstanceDump($expected, $instance); } } diff --git a/tests/Stack/clear.php b/tests/Stack/clear.php index 2d05be2..bee5191 100644 --- a/tests/Stack/clear.php +++ b/tests/Stack/clear.php @@ -5,7 +5,7 @@ trait clear { public function testClear() { - $instance = $this->getInstance($this->sample()); + $instance = static::getInstance(self::sample()); $instance->clear(); $this->assertToArray([], $instance); diff --git a/tests/Stack/copy.php b/tests/Stack/copy.php index 27feaa1..25cc462 100644 --- a/tests/Stack/copy.php +++ b/tests/Stack/copy.php @@ -1,14 +1,14 @@ getInstance($values); + $instance = static::getInstance($values); $copy = $instance->copy(); $this->assertEquals($instance->toArray(), $copy->toArray()); diff --git a/tests/Stack/count.php b/tests/Stack/count.php index 5730a71..4d9f613 100644 --- a/tests/Stack/count.php +++ b/tests/Stack/count.php @@ -1,20 +1,20 @@ getInstance($values); + $instance = static::getInstance($values); $this->assertCount(count($expected), $instance); } public function testCountEmpty() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->assertCount(0, $instance); } } diff --git a/tests/Stack/isEmpty.php b/tests/Stack/isEmpty.php index 1933458..8bc1bd1 100644 --- a/tests/Stack/isEmpty.php +++ b/tests/Stack/isEmpty.php @@ -1,9 +1,11 @@ getInstance($values); + $instance = static::getInstance($values); $this->assertEquals($isEmpty, $instance->isEmpty()); } public function testIsNotEmptyAfterPop() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->assertTrue($instance->isEmpty()); $instance->push('a'); diff --git a/tests/Stack/peek.php b/tests/Stack/peek.php index 7c6bffc..5f99e74 100644 --- a/tests/Stack/peek.php +++ b/tests/Stack/peek.php @@ -1,9 +1,11 @@ getInstance($initial); + $instance = static::getInstance($initial); $value = $instance->peek(); @@ -27,7 +27,7 @@ public function testPeek($initial, $returned) public function testPeekNotAllowedWhenEmpty() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->expectEmptyNotAllowedException(); $instance->peek(); } diff --git a/tests/Stack/pop.php b/tests/Stack/pop.php index 5fa1e2b..ff171b4 100644 --- a/tests/Stack/pop.php +++ b/tests/Stack/pop.php @@ -1,10 +1,12 @@ getInstance($initial); + $instance = static::getInstance($initial); $result = $instance->pop(); @@ -29,7 +29,7 @@ public function testPop($initial, $returned, array $expected) public function testPopAll() { - $instance = $this->getInstance(range(1, self::MANY)); + $instance = static::getInstance(range(1, self::MANY)); while ( ! $instance->isEmpty()) { $instance->pop(); @@ -40,7 +40,7 @@ public function testPopAll() public function testPopNowAllowedWhenEmpty() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->expectEmptyNotAllowedException(); $instance->pop(); } diff --git a/tests/Stack/push.php b/tests/Stack/push.php index cb10910..93fcc1d 100644 --- a/tests/Stack/push.php +++ b/tests/Stack/push.php @@ -1,31 +1,29 @@ basicDataProvider(); + return self::basicDataProvider(); } - /** - * @dataProvider pushDataProvider - */ + #[DataProvider('pushDataProvider')] public function testPushVariadic(array $values, array $expected) { - $instance = $this->getInstance(); + $instance = static::getInstance(); $instance->push(...$values); $this->assertToArray($expected, $instance); $this->assertCount(count($expected), $instance); } - /** - * @dataProvider pushDataProvider - */ + #[DataProvider('pushDataProvider')] public function testPush(array $values, array $expected) { - $instance = $this->getInstance(); + $instance = static::getInstance(); foreach ($values as $value) { $instance->push($value); @@ -35,12 +33,10 @@ public function testPush(array $values, array $expected) $this->assertCount(count($expected), $instance); } - /** - * @dataProvider pushDataProvider - */ + #[DataProvider('pushDataProvider')] public function testArrayAccessPush(array $values, array $expected) { - $instance = $this->getInstance(); + $instance = static::getInstance(); foreach ($values as $value) { $instance[] = $value; @@ -50,12 +46,10 @@ public function testArrayAccessPush(array $values, array $expected) $this->assertCount(count($expected), $instance); } - /** - * @dataProvider pushDataProvider - */ + #[DataProvider('pushDataProvider')] public function testArrayAccessPushByMethod(array $values, array $expected) { - $instance = $this->getInstance(); + $instance = static::getInstance(); foreach ($values as $value) { $instance->offsetSet(null, $value); @@ -67,7 +61,7 @@ public function testArrayAccessPushByMethod(array $values, array $expected) public function testPushCircularReference() { - $instance = $this->getInstance(); + $instance = static::getInstance(); $instance->push($instance); $this->assertToArray([$instance], $instance); } diff --git a/tests/Stack/toArray.php b/tests/Stack/toArray.php index fd3a883..ffaafbd 100644 --- a/tests/Stack/toArray.php +++ b/tests/Stack/toArray.php @@ -1,14 +1,14 @@ getInstance($values); + $instance = static::getInstance($values); $this->assertToArray($expected, $instance); } } diff --git a/tests/StackTest.php b/tests/StackTest.php index 3f8e582..5636460 100644 --- a/tests/StackTest.php +++ b/tests/StackTest.php @@ -4,7 +4,7 @@ use ArrayAccess; use Ds\Collection; -class StackTest extends CollectionTest +class StackTest extends CollectionTestCase { use Stack\__construct; use Stack\_clone; @@ -30,12 +30,12 @@ class StackTest extends CollectionTest use Stack\push; use Stack\toArray; - public function getInstance(array $values = []) + public static function getInstance(array $values = []) { return new \Ds\Stack($values); } - public function basicDataProvider() + public static function basicDataProvider() { // Stack should produce values in reverse order. return array_map(function($data) { @@ -52,13 +52,13 @@ public function serializeDataProvider() public function testArrayAccessSet() { - $set = $this->getInstance(); + $set = static::getInstance(); $this->expectArrayAccessUnsupportedException(); $set['a'] = 1; } public function testImplementsArrayAccess() { - $this->assertInstanceOf(ArrayAccess::class, $this->getInstance()); + $this->assertInstanceOf(ArrayAccess::class, static::getInstance()); } } diff --git a/tests/Vector/__construct.php b/tests/Vector/__construct.php index 33c9e8d..17c76d2 100644 --- a/tests/Vector/__construct.php +++ b/tests/Vector/__construct.php @@ -1,33 +1,31 @@ sample(), + self::sample(), range(1, self::MANY), ]); } - /** - * @dataProvider constructDataProvider - */ + #[DataProvider('constructDataProvider')] public function testConstruct($values, array $expected) { $this->assertToArray($expected, new Vector($values)); } - /** - * @dataProvider constructDataProvider - */ + #[DataProvider('constructDataProvider')] public function testConstructUsingNonArrayIterable(array $values, array $expected) { $this->assertToArray($expected, new Vector(new \ArrayIterator($values))); diff --git a/tests/Vector/allocate.php b/tests/Vector/allocate.php index 0cc525f..1072101 100644 --- a/tests/Vector/allocate.php +++ b/tests/Vector/allocate.php @@ -1,9 +1,11 @@ getInstance(); + $instance = static::getInstance(); $instance->allocate($initial); $instance->allocate($allocate); diff --git a/tests/Vector/capacity.php b/tests/Vector/capacity.php index ff710f8..6dc41b6 100644 --- a/tests/Vector/capacity.php +++ b/tests/Vector/capacity.php @@ -7,7 +7,7 @@ public function testCapacity() { $min = \Ds\Vector::MIN_CAPACITY; - $instance = $this->getInstance(); + $instance = static::getInstance(); $this->assertEquals($min, $instance->capacity()); for ($i = 0; $i < $min; $i++) { @@ -42,7 +42,7 @@ public function testAutoTruncate() 0 => 8, ]; - $instance = $this->getInstance(range(1, array_keys($boundaries)[0])); + $instance = static::getInstance(range(1, array_keys($boundaries)[0])); for (;;) { if ( ! is_null(($expected = $boundaries[$instance->count()] ?? null))) { @@ -61,7 +61,7 @@ public function testClearResetsCapacity() { $min = \Ds\Vector::MIN_CAPACITY; - $instance = $this->getInstance(range(1, self::MANY)); + $instance = static::getInstance(range(1, self::MANY)); $instance->clear(); $this->assertEquals($min, $instance->capacity()); } diff --git a/tests/VectorTest.php b/tests/VectorTest.php index 7290be0..1a8fe6e 100644 --- a/tests/VectorTest.php +++ b/tests/VectorTest.php @@ -3,7 +3,7 @@ use ArrayAccess; -class VectorTest extends CollectionTest +class VectorTest extends CollectionTestCase { use Sequence\_clone; use Sequence\_echo; @@ -51,13 +51,13 @@ class VectorTest extends CollectionTest use Sequence\toArray; use Sequence\unshift; - public function getInstance(array $values = []) + public static function getInstance(array $values = []) { return new \Ds\Vector($values); } public function testImplementsArrayAccess() { - $this->assertInstanceOf(ArrayAccess::class, $this->getInstance()); + $this->assertInstanceOf(ArrayAccess::class, static::getInstance()); } }