Completed
Branch release/v1.0.0 (b932d7)
by Edward
03:07 queued 40s
created

SearchableTraitTest::testIndexOf()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4286
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
/**
3
 * File SearchableTraitTest.php
4
 *
5
 * @author Edward Pfremmer <[email protected]>
6
 */
7
namespace Epfremme\Tests\Collection\Traits;
8
9
use Epfremme\Collection\Collection;
10
11
/**
12
 * Class SearchableTraitTest
13
 *
14
 * @package Epfremme\Tests\Collection\Traits
15
 */
16
class SearchableTraitTest extends \PHPUnit_Framework_TestCase
17
{
18
    /**
19
     * @var Collection
20
     */
21
    private $collection;
22
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function setUp()
27
    {
28
        parent::setUp();
29
30
        $this->collection = new Collection([1, 2, 3, 'a' => 4, 'b' => 5]);
31
    }
32
33
    /**
34
     * Test getting index of an element
35
     *
36
     * @return void
37
     */
38
    public function testIndexOf()
39
    {
40
        $this->assertEquals(1, $this->collection->indexOf(2));
41
        $this->assertEquals('a', $this->collection->indexOf(4));
42
        $this->assertFalse($this->collection->indexOf(7));
43
    }
44
45
    /**
46
     * Test validating collection elements exist
47
     *
48
     * @return void
49
     */
50
    public function testContains()
51
    {
52
        $this->assertTrue($this->collection->contains(3));
53
        $this->assertFalse($this->collection->contains(7));
54
    }
55
56
    /**
57
     * Test validating collection key exists
58
     *
59
     * @return void
60
     */
61
    public function testKeyExists()
62
    {
63
        $this->assertTrue($this->collection->keyExists(2));
64
        $this->assertFalse($this->collection->keyExists('noop'));
65
    }
66
67
    /**
68
     * Test filtering collection elements
69
     *
70
     * @return void
71
     */
72
    public function testFilter()
73
    {
74
        $filtered = $this->collection->filter(function($value, $key) {
75
            return is_string($key);
76
        });
77
78
        $this->assertAttributeNotEmpty('elements', $filtered);
79
        $this->assertAttributeCount(2, 'elements', $filtered);
80
    }
81
}
82