forked from Astrotomic/phpunit-assertions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArrayAssertionsTest.php
105 lines (84 loc) · 2.8 KB
/
ArrayAssertionsTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
namespace Astrotomic\PhpunitAssertions\Tests;
use Astrotomic\PhpunitAssertions\ArrayAssertions;
final class ArrayAssertionsTest extends TestCase
{
/**
* @test
* @dataProvider hundredTimes
*/
public static function it_can_validate_array_is_indexed(): void
{
$actual = self::randomArray(self::randomInt(5, 20), false);
ArrayAssertions::assertIndexed($actual);
}
/**
* @test
* @dataProvider hundredTimes
*/
public static function it_can_validate_array_is_associative(): void
{
$actual = self::randomArray(self::randomInt(5, 20), true);
ArrayAssertions::assertAssociative($actual);
}
/**
* @test
* @dataProvider hundredTimes
*/
public static function it_can_validate_indexed_array_equality(): void
{
$array = self::randomArray(self::randomInt(5, 20), false);
$actual = $array;
$expected = $array;
shuffle($actual);
ArrayAssertions::assertEquals($expected, $actual);
}
/**
* @test
* @dataProvider hundredTimes
*/
public static function it_can_validate_associative_array_equality(): void
{
$array = self::randomArray(self::randomInt(5, 20), true);
$actual = $array;
$expected = $array;
uksort($actual, fn (): int => self::randomInt() <=> self::randomInt());
ArrayAssertions::assertEquals($expected, $actual);
}
/**
* @test
* @dataProvider hundredTimes
*/
public static function it_can_validate_associative_array_subset(): void
{
$array = self::randomArray(self::randomInt(5, 20), true);
$actual = $array;
$expected = array_slice($array, 0, ceil(count($array) / self::randomInt(2, 4)), true);
uksort($expected, fn (): int => self::randomInt() <=> self::randomInt());
ArrayAssertions::assertSubset($expected, $actual);
}
/**
* @test
* @dataProvider hundredTimes
*/
public static function it_can_validate_indexed_array_contains_all(): void
{
$array = self::randomArray(self::randomInt(5, 20), false);
$actual = $array;
$expected = array_slice($array, 0, ceil(count($array) / self::randomInt(2, 4)), true);
shuffle($actual);
ArrayAssertions::assertContainsAll($expected, $actual);
}
/**
* @test
* @dataProvider hundredTimes
*/
public static function it_can_validate_associative_array_contains_all(): void
{
$array = self::randomArray(self::randomInt(5, 20), true);
$actual = $array;
$expected = array_slice($array, 0, ceil(count($array) / self::randomInt(2, 4)), true);
uksort($actual, fn (): int => self::randomInt() <=> self::randomInt());
ArrayAssertions::assertContainsAll($expected, $actual);
}
}