|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the Cubiche package. |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright (c) Cubiche |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
namespace Cubiche\Core\Collections\Tests\Units; |
|
11
|
|
|
|
|
12
|
|
|
use Cubiche\Core\Collections\DataSource\ArrayDataSource; |
|
13
|
|
|
use Cubiche\Core\Collections\DataSourceHashMap; |
|
14
|
|
|
use Cubiche\Core\Specification\Criteria; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* DataSourceHashMapTests class. |
|
18
|
|
|
* |
|
19
|
|
|
* @author Ivannis Suárez Jerez <[email protected]> |
|
20
|
|
|
* @author Karel Osorio Ramírez <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
class DataSourceHashMapTests extends HashMapTestCase |
|
23
|
|
|
{ |
|
24
|
|
|
use DataSourceCollectionTestCase; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* {@inheritdoc} |
|
28
|
|
|
*/ |
|
29
|
|
|
protected function randomCollection($size = null) |
|
30
|
|
|
{ |
|
31
|
|
|
return new DataSourceHashMap(new ArrayDataSource($this->randomValues($size))); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* {@inheritdoc} |
|
36
|
|
|
*/ |
|
37
|
|
|
protected function emptyCollection() |
|
38
|
|
|
{ |
|
39
|
|
|
return new DataSourceHashMap(new ArrayDataSource([])); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Test find. |
|
44
|
|
|
*/ |
|
45
|
|
|
public function testFind() |
|
46
|
|
|
{ |
|
47
|
|
|
$this |
|
48
|
|
|
->given( |
|
49
|
|
|
$unique = $this->uniqueValue(), |
|
50
|
|
|
$criteria = Criteria::same($unique), |
|
51
|
|
|
$emptyCollection = $this->emptyCollection() |
|
52
|
|
|
) |
|
53
|
|
|
->when($findResult = $emptyCollection->find($criteria)) |
|
54
|
|
|
->then() |
|
55
|
|
|
->hashmap($findResult) |
|
56
|
|
|
->isEmpty() |
|
57
|
|
|
->and() |
|
58
|
|
|
->when($emptyCollection->set('foo', $unique)) |
|
59
|
|
|
->and($findResult = $emptyCollection->find($criteria)) |
|
60
|
|
|
->then() |
|
61
|
|
|
->hashmap($findResult) |
|
62
|
|
|
->size() |
|
63
|
|
|
->isEqualTo(1) |
|
64
|
|
|
->array($findResult->toArray()) |
|
65
|
|
|
->contains($unique) |
|
66
|
|
|
; |
|
67
|
|
|
|
|
68
|
|
|
$this |
|
69
|
|
|
->given( |
|
70
|
|
|
$unique = $this->uniqueValue(), |
|
71
|
|
|
$criteria = Criteria::same($unique), |
|
72
|
|
|
$randomCollection = $this->randomCollection() |
|
73
|
|
|
) |
|
74
|
|
|
->when($findResult = $randomCollection->find($criteria)) |
|
75
|
|
|
->then() |
|
76
|
|
|
->hashmap($findResult) |
|
77
|
|
|
->isEmpty() |
|
78
|
|
|
->and() |
|
79
|
|
|
->when($randomCollection->set('bar', $unique)) |
|
80
|
|
|
->and($findResult = $randomCollection->find($criteria)) |
|
81
|
|
|
->then() |
|
82
|
|
|
->array($findResult->toArray()) |
|
83
|
|
|
->contains($unique) |
|
84
|
|
|
; |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|