-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollectionEqualsOperationTest.php
More file actions
88 lines (73 loc) · 2.91 KB
/
CollectionEqualsOperationTest.php
File metadata and controls
88 lines (73 loc) · 2.91 KB
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
<?php
declare(strict_types=1);
namespace Test\TinyBlocks\Collection\Operations\Compare;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use stdClass;
use Test\TinyBlocks\Collection\Models\CryptoCurrency;
use TinyBlocks\Collection\Collection;
final class CollectionEqualsOperationTest extends TestCase
{
#[DataProvider('collectionsEqualDataProvider')]
public function testCollectionsAreEqual(iterable $elementsA, iterable $elementsB): void
{
/** @Given two collections */
$collectionA = Collection::createFrom(elements: $elementsA);
$collectionB = Collection::createFrom(elements: $elementsB);
/** @When comparing the collections */
$actual = $collectionA->equals(other: $collectionB);
/** @Then the collections should be equal */
self::assertTrue($actual);
}
#[DataProvider('collectionsNotEqualDataProvider')]
public function testCollectionsAreNotEqual(iterable $elementsA, iterable $elementsB): void
{
/** @Given two collections */
$collectionA = Collection::createFrom(elements: $elementsA);
$collectionB = Collection::createFrom(elements: $elementsB);
/** @When comparing the collections */
$actual = $collectionA->equals(other: $collectionB);
/** @Then the collections should not be equal */
self::assertFalse($actual);
}
public static function collectionsEqualDataProvider(): iterable
{
yield 'Collections are equal' => [
'elementsA' => [
new CryptoCurrency(name: 'Bitcoin', price: 60000.0, symbol: 'BTC'),
new CryptoCurrency(name: 'Ethereum', price: 40000.0, symbol: 'ETH')
],
'elementsB' => [
new CryptoCurrency(name: 'Bitcoin', price: 60000.0, symbol: 'BTC'),
new CryptoCurrency(name: 'Ethereum', price: 40000.0, symbol: 'ETH')
]
];
yield 'Collections with mixed keys and values' => [
'elementsA' => [1, 'key' => 'value', 3.5],
'elementsB' => [1, 'key' => 'value', 3.5]
];
}
public static function collectionsNotEqualDataProvider(): iterable
{
yield 'Collections are not equal' => [
'elementsA' => [
new CryptoCurrency(name: 'Bitcoin', price: 60000.0, symbol: 'BTC')
],
'elementsB' => [
new CryptoCurrency(name: 'Ethereum', price: 40000.0, symbol: 'ETH')
]
];
yield 'Scalar and non-scalar comparison' => [
'elementsA' => [1],
'elementsB' => [new stdClass()]
];
yield 'Collections with different null handling' => [
'elementsA' => [null],
'elementsB' => []
];
yield 'Same elements in different order are not equal' => [
'elementsA' => [1, 2, 3],
'elementsB' => [3, 2, 1]
];
}
}