Issues (43)

tests/src/CollectionTest.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace Nip\Collections\Tests;
4
5
use Nip\Collections\Collection as Collection;
6
use stdClass;
7
8
/**
9
 * Class CollectionTest.
10
 */
11
class CollectionTest extends AbstractTest
12
{
13
    /**
14
     * @var Collection
15
     */
16
    protected $collection;
17
18
    public function testAdd()
19
    {
20
        static::assertEquals(0, count($this->collection));
21
22
        $this->collection['first'] = new stdClass();
23
        static::assertEquals(1, count($this->collection));
24
25
        $this->collection['luke'] = 'Luke Skywalker';
26
        static::assertEquals('Luke Skywalker', $this->collection['luke']);
27
28
        $this->collection['third'] = new stdClass();
29
        static::assertEquals(3, count($this->collection));
30
    }
31
32
    public function testRemove()
33
    {
34
        $this->collection[] = 'Darth Vader';
35
        $this->collection[] = 'Luke Skywalker';
36
        $this->collection[] = 'Han Solo';
37
38
        static::assertEquals(3, count($this->collection));
39
40
        unset($this->collection[1]);
41
        static::assertEquals(2, count($this->collection));
42
    }
43
44
    public function testIterate()
45
    {
46
        $items = [
47
            'darth' => 'Darth Vader',
48
            'luke'  => 'Luke Skywalker',
49
            'han'   => 'Han Solo',
50
        ];
51
        foreach ($items as $key => $value) {
52
            $this->collection[$key] = $value;
53
        }
54
55
        foreach ($this->collection as $key => $item) {
56
            static::assertEquals($items[$key], $item);
57
        }
58
    }
59
60
    public function testArrayAccess()
61
    {
62
        $this->collection[] = 'Darth Vader';
63
        $this->collection[] = 'Luke Skywalker';
64
        $this->collection[] = 'Han Solo';
65
66
        static::assertEquals('Darth Vader', $this->collection->rewind());
0 ignored issues
show
Are you sure the usage of $this->collection->rewind() targeting Nip\Collections\AbstractCollection::rewind() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
67
        static::assertEquals('Luke Skywalker', $this->collection->next());
68
        static::assertEquals('Han Solo', $this->collection->end());
69
    }
70
71
    protected function setUp(): void
72
    {
73
        $this->collection = new Collection();
74
    }
75
}
76