ClassCollectionTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 5
eloc 18
c 2
b 0
f 1
dl 0
loc 52
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A typeInvalidValues() 0 3 1
A typeClass() 0 3 1
A typeValidValues() 0 3 1
A newCollection() 0 5 1
A test_serialize() 0 14 1
1
<?php
2
3
namespace Nip\Collections\Tests\Typed;
4
5
use Nip\Collections\Tests\AbstractTest;
6
use Nip\Collections\Tests\Fixtures\BaseClassCollection;
7
use Nip\Collections\Tests\Fixtures\BaseObject;
8
use Nip\Utility\Number;
9
use function PHPUnit\Framework\assertEquals;
0 ignored issues
show
introduced by
The function PHPUnit\Framework\assertEquals was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
10
11
/**
12
 * Class ClassCollectionTest
13
 * @package Nip\Collections\Tests\Typed
14
 */
15
class ClassCollectionTest extends AbstractTest
16
{
17
    use AbstractTypeTraitTest {
18
        newCollection as newCollectionTrait;
19
    }
20
21
    /**
22
     * @dataProvider data_validValues
23
     * @param $value
24
     */
25
    public function test_serialize($value)
26
    {
27
        $collection = $this->newCollection();
28
29
        $collection->add($value);
30
        $collection->set(1, $value);
31
        $collection[] = $value;
32
        $collection[9] = $value;
33
        $collection->unshift($value);
34
        $collection->push($value);
35
36
        $serialized = serialize($collection);
37
        $collectionReturn = unserialize($serialized);
38
        assertEquals($collection->all(), $collectionReturn->all());
39
    }
40
41
    /**
42
     * @return \Nip\Collections\Typed\AbstractTypedCollection
43
     */
44
    protected function newCollection()
45
    {
46
        $collection = $this->newCollectionTrait();
47
        $collection->validClass(BaseObject::class);
0 ignored issues
show
Bug introduced by
The method validClass() does not exist on Nip\Collections\Typed\AbstractTypedCollection. It seems like you code against a sub-type of Nip\Collections\Typed\AbstractTypedCollection such as Nip\Collections\Typed\ClassCollection. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

47
        $collection->/** @scrutinizer ignore-call */ 
48
                     validClass(BaseObject::class);
Loading history...
48
        return $collection;
49
    }
50
51
    /**
52
     * @return string
53
     */
54
    protected function typeClass()
55
    {
56
        return BaseClassCollection::class;
57
    }
58
59
    protected function typeInvalidValues(): array
60
    {
61
        return ['string', new \stdClass(), new Number()];
62
    }
63
64
    protected function typeValidValues(): array
65
    {
66
        return [new BaseObject()];
67
    }
68
}
69