-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollectionContainsOperationTest.php
More file actions
87 lines (71 loc) · 2.91 KB
/
CollectionContainsOperationTest.php
File metadata and controls
87 lines (71 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
<?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 CollectionContainsOperationTest extends TestCase
{
#[DataProvider('containsElementDataProvider')]
public function testContainsElement(iterable $elements, mixed $element): void
{
/** @Given a collection */
$collection = Collection::createFrom(elements: $elements);
/** @When checking if the element is contained in the collection */
$actual = $collection->contains(element: $element);
/** @Then the collection should contain the element */
self::assertTrue($actual);
}
#[DataProvider('doesNotContainElementDataProvider')]
public function testDoesNotContainElement(iterable $elements, mixed $element): void
{
/** @Given a collection */
$collection = Collection::createFrom(elements: $elements);
/** @When checking if the element is contained in the collection */
$actual = $collection->contains(element: $element);
/** @Then the collection should not contain the element */
self::assertFalse($actual);
}
public static function containsElementDataProvider(): iterable
{
yield 'Collection contains null' => [
'elements' => [1, null, 3],
'element' => null
];
yield 'Collection contains element' => [
'elements' => [
new CryptoCurrency(name: 'Bitcoin', price: 60000.0, symbol: 'BTC'),
new CryptoCurrency(name: 'Ethereum', price: 40000.0, symbol: 'ETH')
],
'element' => new CryptoCurrency(name: 'Bitcoin', price: 60000.0, symbol: 'BTC')
];
yield 'Collection contains scalar value' => [
'elements' => [1, 'key' => 'value', 3.5],
'element' => 'value'
];
}
public static function doesNotContainElementDataProvider(): iterable
{
yield 'Empty collection' => [
'elements' => [],
'element' => 1
];
yield 'Collection does not contain object' => [
'elements' => [new stdClass()],
'element' => new CryptoCurrency(name: 'Bitcoin', price: 60000.0, symbol: 'BTC')
];
yield 'Collection does not contain element' => [
'elements' => [
new CryptoCurrency(name: 'Bitcoin', price: 60000.0, symbol: 'BTC'),
new CryptoCurrency(name: 'Ethereum', price: 40000.0, symbol: 'ETH')
],
'element' => new CryptoCurrency(name: 'Ripple', price: 1.0, symbol: 'XRP')
];
yield 'Collection does not contain scalar value' => [
'elements' => [1, 'key' => 'value', 3.5],
'element' => 42
];
}
}