ArrayDataSourceTests::testCreate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
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