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

SearchableTraitTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 5
c 2
b 0
f 1
lcom 1
cbo 2
dl 0
loc 66
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A testIndexOf() 0 6 1
A testContains() 0 5 1
A testKeyExists() 0 5 1
A testFilter() 0 9 1
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