Skip to content

Commit f2d512d

Browse files
committed
Finish phpunit v12 migration
1 parent 0235e65 commit f2d512d

File tree

199 files changed

+1182
-1360
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

199 files changed

+1182
-1360
lines changed
Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,23 @@
1010
use function strpos;
1111
use function var_dump;
1212

13-
abstract class CollectionTest extends TestCase
13+
abstract class CollectionTestCase extends TestCase
1414
{
1515
/**
1616
* Sample sizes.
1717
*/
1818
const MANY = 65;
1919
const SOME = 17;
2020

21+
/**
22+
* Create an instance of the data structure being tested.
23+
*/
24+
abstract public static function getInstance(array $values = []);
25+
2126
/**
2227
* Generic mixed value sample array.
2328
*/
24-
public function sample()
29+
public static function sample()
2530
{
2631
return array_merge(
2732
[[]], // empty
@@ -38,23 +43,23 @@ public function sample()
3843
/**
3944
* @return array provides two equal values for each test.
4045
*/
41-
public function basicDataProvider()
46+
public static function basicDataProvider()
4247
{
4348
$values = [
4449
[],
4550
['a'],
4651
['a', 'b'],
4752
['a', 'b', 'c'],
48-
$this->sample(),
53+
self::sample(),
4954
];
5055

51-
return array_map(function($a) { return [$a, $a]; }, $values);
56+
return array_map(fn($a) => [$a, $a], $values);
5257
}
5358

5459
/**
5560
* @return array a data provider for Sequence and Set to test out of range.
5661
*/
57-
public function outOfRangeDataProvider()
62+
public static function outOfRangeDataProvider()
5863
{
5964
return [
6065
[[ ], -1],
@@ -64,7 +69,7 @@ public function outOfRangeDataProvider()
6469
];
6570
}
6671

67-
public function badIndexDataProvider()
72+
public static function badIndexDataProvider()
6873
{
6974
return [
7075
[[], 'a'],
@@ -250,7 +255,7 @@ protected function cleanVarDump($expression)
250255
*/
251256
public function testConvertingToBoolean()
252257
{
253-
$instance = $this->getInstance();
258+
$instance = static::getInstance();
254259
$this->assertTrue((bool) $instance);
255260
}
256261
}
@@ -268,9 +273,9 @@ public function __construct($test) {
268273
$this->test = $test;
269274
}
270275

271-
public function getInstance(array $values = null)
276+
public function getInstance(array|null $values = null)
272277
{
273-
return $this->test->getInstance($values);
278+
return $this->test::getInstance($values);
274279
}
275280
}
276281

tests/Deque/__construct.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,31 @@
11
<?php
22
namespace Ds\Tests\Deque;
33

4+
use PHPUnit\Framework\Attributes\DataProvider;
5+
46
use Ds\Deque;
57

68
trait __construct
79
{
8-
public function constructDataProvider()
10+
public static function constructDataProvider()
911
{
1012
return array_map(function($a) { return [$a, $a]; }, [
1113
[],
1214
['a'],
1315
['a', 'b'],
1416
['a', 'b', 'c'],
15-
$this->sample(),
17+
self::sample(),
1618
range(1, self::MANY),
1719
]);
1820
}
1921

20-
/**
21-
* @dataProvider constructDataProvider
22-
*/
22+
#[DataProvider('constructDataProvider')]
2323
public function testConstruct($values, array $expected)
2424
{
2525
$this->assertToArray($expected, new Deque($values));
2626
}
2727

28-
/**
29-
* @dataProvider constructDataProvider
30-
*/
28+
#[DataProvider('constructDataProvider')]
3129
public function testConstructUsingNonArrayIterable(array $values, array $expected)
3230
{
3331
$this->assertToArray($expected, new Deque(new \ArrayIterator($values)));

tests/Deque/allocate.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<?php
22
namespace Ds\Tests\Deque;
33

4+
use PHPUnit\Framework\Attributes\DataProvider;
5+
46
trait allocate
57
{
6-
public function allocateDataProvider()
8+
public static function allocateDataProvider()
79
{
810
$m = \Ds\Deque::MIN_CAPACITY;
911

@@ -22,12 +24,10 @@ public function allocateDataProvider()
2224
];
2325
}
2426

25-
/**
26-
* @dataProvider allocateDataProvider
27-
*/
27+
#[DataProvider('allocateDataProvider')]
2828
public function testAllocate(int $initial, int $allocate, int $expected)
2929
{
30-
$instance = $this->getInstance();
30+
$instance = static::getInstance();
3131

3232
$instance->allocate($initial);
3333
$instance->allocate($allocate);

tests/Deque/capacity.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public function testCapacity()
77
{
88
$min = \Ds\Deque::MIN_CAPACITY;
99

10-
$instance = $this->getInstance();
10+
$instance = static::getInstance();
1111
$this->assertEquals($min, $instance->capacity());
1212

1313
for ($i = 0; $i < $min; $i++) {
@@ -42,7 +42,7 @@ public function testAutoTruncate()
4242
0 => 8,
4343
];
4444

45-
$instance = $this->getInstance(range(1, array_keys($boundaries)[0]));
45+
$instance = static::getInstance(range(1, array_keys($boundaries)[0]));
4646

4747
for (;;) {
4848
if ( ! is_null(($expected = $boundaries[$instance->count()] ?? null))) {
@@ -61,7 +61,7 @@ public function testClearResetsCapacity()
6161
{
6262
$min = \Ds\Deque::MIN_CAPACITY;
6363

64-
$instance = $this->getInstance(range(1, self::MANY));
64+
$instance = static::getInstance(range(1, self::MANY));
6565
$instance->clear();
6666
$this->assertEquals($min, $instance->capacity());
6767
}

tests/Deque/insert.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ trait insert
99
*/
1010
public function testInsertExtended()
1111
{
12-
$instance = $this->getInstance();
12+
$instance = static::getInstance();
1313

1414
// The head of the deque will wrap around if all items are unshifted.
1515

@@ -32,7 +32,7 @@ public function testInsertExtended()
3232

3333
public function testInsertingIntoAnIsland()
3434
{
35-
$instance = $this->getInstance();
35+
$instance = static::getInstance();
3636

3737
// It's possible that the head of the deque comes before the tail, but
3838
// is not at zero. This could overflow the buffer.
@@ -59,7 +59,7 @@ public function testInsertingIntoAnIsland()
5959

6060
public function testInsertAtBoundaryWithMoreOnTheLeft()
6161
{
62-
$instance = $this->getInstance();
62+
$instance = static::getInstance();
6363
$instance->push(3, 4, 5, 6);
6464
$instance->unshift(1, 2);
6565

@@ -74,7 +74,7 @@ public function testInsertAtBoundaryWithMoreOnTheLeft()
7474

7575
public function testInsertAtBoundaryWithMoreOnTheRight()
7676
{
77-
$instance = $this->getInstance();
77+
$instance = static::getInstance();
7878
$instance->push(5, 6);
7979
$instance->unshift(1, 2, 3, 4);
8080

@@ -89,7 +89,7 @@ public function testInsertAtBoundaryWithMoreOnTheRight()
8989

9090
public function testInsertAtBoundaryWithEqualOnBothSides()
9191
{
92-
$instance = $this->getInstance();
92+
$instance = static::getInstance();
9393
$instance->push(4, 5, 6);
9494
$instance->unshift(1, 2, 3);
9595

@@ -103,7 +103,7 @@ public function testInsertAtBoundaryWithEqualOnBothSides()
103103

104104
public function testAlmostFullInsertAtZero()
105105
{
106-
$instance = $this->getInstance();
106+
$instance = static::getInstance();
107107
$instance->push(...range(1, 6));
108108
$instance->insert(0, 0);
109109

tests/Deque/remove.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ trait remove
99
*/
1010
public function testRemoveExtended()
1111
{
12-
$instance = $this->getInstance();
12+
$instance = static::getInstance();
1313

1414
/* HEAD WRAPPED AROUND, TAIL = 0 */
1515
// The head of the deque will wrap around if all items are unshifted.
@@ -25,7 +25,7 @@ public function testRemoveExtended()
2525
$this->assertTrue($instance->isEmpty());
2626

2727
/* HEAD WRAPPED AROUND, TAIL > 0 */
28-
$instance = $this->getInstance();
28+
$instance = static::getInstance();
2929

3030
$instance->unshift('b'); // [_, _, ..., _, b] tail = 0, head = 3
3131
$instance->unshift('a'); // [_, _, ..., a, b] tail = 0, head = 2
@@ -38,7 +38,7 @@ public function testRemoveExtended()
3838
$this->assertTrue($instance->isEmpty());
3939

4040
/* HEAD NOT WRAPPED, TAIL > 0 */
41-
$instance = $this->getInstance();
41+
$instance = static::getInstance();
4242

4343
$instance->push('a'); // [a, _, _, ..., _] tail = 1, head = 0
4444
$instance->push('b'); // [a, b, _, ..., _] tail = 2, head = 0

tests/Deque/slice.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ trait slice
99
*/
1010
public function testSliceExtended()
1111
{
12-
$instance = $this->getInstance();
12+
$instance = static::getInstance();
1313

1414
$instance->unshift('c'); // [_, _, _, _, _, _, _, c] tail = 0, head = 7
1515
$instance->unshift('b'); // [_, _, _, _, _, _, b, c] tail = 0, head = 6
@@ -30,7 +30,7 @@ public function testSliceExtended()
3030
/* If only some values have wrapped around, slice would have to copy
3131
from both the wrapped and not-wrapped values */
3232

33-
$instance = $this->getInstance();
33+
$instance = static::getInstance();
3434

3535
$instance->push('b'); // [b, _, _, _, _, _, _, _] tail = 1, head = 0
3636
$instance->push('c'); // [b, c, _, _, _, _, _, _] tail = 2, head = 1

tests/DequeTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use ArrayAccess;
55

6-
class DequeTest extends CollectionTest
6+
class DequeTest extends CollectionTestCase
77
{
88
use Sequence\_clone;
99
use Sequence\_echo;
@@ -54,14 +54,14 @@ class DequeTest extends CollectionTest
5454
use Sequence\toArray;
5555
use Sequence\unshift;
5656

57-
public function getInstance(array $values = [])
57+
public static function getInstance(array $values = [])
5858
{
5959
return new \Ds\Deque($values);
6060
}
6161

6262
public function testReallocatingWhenHeadNotAtZero()
6363
{
64-
$instance = $this->getInstance();
64+
$instance = static::getInstance();
6565

6666
$instance->push('a', 'b', 'c', 'd');
6767
$instance->shift();
@@ -81,7 +81,7 @@ public function testReallocatingWhenHeadNotAtZero()
8181

8282
public function testReallocatingWhenHeadHasWrapped()
8383
{
84-
$instance = $this->getInstance();
84+
$instance = static::getInstance();
8585

8686
$instance->push('a');
8787
$instance->push('b');
@@ -106,7 +106,7 @@ public function testReallocatingWhenHeadHasWrapped()
106106

107107
public function testRealignmentOfWrappedBufferWithLargeTempSpace()
108108
{
109-
$instance = $this->getInstance(); // [_, _, _, _, _, _, _, _]
109+
$instance = static::getInstance(); // [_, _, _, _, _, _, _, _]
110110

111111
$instance->push('c', 'd');
112112
$instance->unshift('a', 'b'); // [c, d, _, _, _, _, a, b]
@@ -132,7 +132,7 @@ public function testRealignmentOfWrappedBufferWithLargeTempSpace()
132132
// Also test the boundary case, where the number of wrapped values
133133
// equals the amount of free space in the buffer.
134134

135-
$instance = $this->getInstance(); // [_, _, _, _, _, _, _, _]
135+
$instance = static::getInstance(); // [_, _, _, _, _, _, _, _]
136136

137137
$instance->push('c', 'd', 'e', 'f');
138138
$instance->unshift('a', 'b'); // [c, d, e, f, _, _, a, b]
@@ -149,7 +149,7 @@ public function testRealignmentOfWrappedBufferWithLargeTempSpace()
149149
////////////////////////////////////////////////////////////////
150150
// Also test for assurance when there isn't enough space.
151151

152-
$instance = $this->getInstance(); // [_, _, _, _, _, _, _, _]
152+
$instance = static::getInstance(); // [_, _, _, _, _, _, _, _]
153153

154154
$instance->push('c', 'd', 'e', 'f', 'g');
155155
$instance->unshift('a', 'b'); // [c, d, e, f, g, _, a, b]
@@ -166,6 +166,6 @@ public function testRealignmentOfWrappedBufferWithLargeTempSpace()
166166

167167
public function testImplementsArrayAccess()
168168
{
169-
$this->assertInstanceOf(ArrayAccess::class, $this->getInstance());
169+
$this->assertInstanceOf(ArrayAccess::class, static::getInstance());
170170
}
171171
}

tests/Map/__construct.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,30 @@
11
<?php
22
namespace Ds\Tests\Map;
33

4+
use PHPUnit\Framework\Attributes\DataProvider;
5+
46
use Ds\Map;
57

68
trait __construct
79
{
8-
public function constructDataProvider()
10+
public static function constructDataProvider()
911
{
1012
return array_map(function($a) { return [$a, $a]; }, [
1113
[],
1214
['a' => 1],
1315
['a' => 1, 'b' => 2],
1416
['a' => 1, 'b' => 2, 'c' => 3],
15-
$this->sample(),
17+
self::sample(),
1618
]);
1719
}
1820

19-
/**
20-
* @dataProvider constructDataProvider
21-
*/
21+
#[DataProvider('constructDataProvider')]
2222
public function testConstruct(array $values, array $expected)
2323
{
2424
$this->assertToArray($expected, new Map($values));
2525
}
2626

27-
/**
28-
* @dataProvider constructDataProvider
29-
*/
27+
#[DataProvider('constructDataProvider')]
3028
public function testConstructUsingNonArrayIterable(array $values, array $expected)
3129
{
3230
$this->assertToArray($expected, new Map(new \ArrayIterator($values)));

0 commit comments

Comments
 (0)