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\DataSource; |
11
|
|
|
|
12
|
|
|
use Cubiche\Core\Collections\DataSource\ArrayDataSource; |
13
|
|
|
use Cubiche\Core\Comparable\ComparatorInterface; |
14
|
|
|
use Cubiche\Core\Equatable\Tests\Fixtures\Value; |
15
|
|
|
use Cubiche\Core\Specification\SpecificationInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* ArrayDataSourceTests class. |
19
|
|
|
* |
20
|
|
|
* @author Ivannis Suárez Jerez <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class ArrayDataSourceTests extends IteratorDataSourceTests |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* {@inheritdoc} |
26
|
|
|
*/ |
27
|
|
|
protected function randomDataSource( |
28
|
|
|
SpecificationInterface $searchCriteria = null, |
29
|
|
|
ComparatorInterface $sortCriteria = null, |
30
|
|
|
$offset = null, |
31
|
|
|
$length = null |
32
|
|
|
) { |
33
|
|
|
$items = array(); |
34
|
|
|
foreach (range(0, rand(10, 20)) as $value) { |
35
|
|
|
$items[] = new Value($value); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
return new ArrayDataSource($items, $searchCriteria, $sortCriteria, $offset, $length); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
*/ |
44
|
|
|
protected function emptyDataSource() |
45
|
|
|
{ |
46
|
|
|
return new ArrayDataSource(array()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* {@inheritdoc} |
51
|
|
|
*/ |
52
|
|
|
protected function uniqueValue() |
53
|
|
|
{ |
54
|
|
|
return new Value(1000); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Test create. |
59
|
|
|
*/ |
60
|
|
|
public function testCreate() |
61
|
|
|
{ |
62
|
|
|
parent::testCreate(); |
63
|
|
|
|
64
|
|
|
$this |
65
|
|
|
->given($datasource = $this->randomDataSource()) |
66
|
|
|
->then |
67
|
|
|
->datasource($datasource) |
68
|
|
|
->isInstanceOf(ArrayDataSource::class) |
69
|
|
|
; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|