Passed
Branch scrutinizer_new_php_analysis (b739aa)
by Donald
02:21
created

SetTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
dl 0
loc 46
c 1
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testSetOnceStoresValue() 0 13 1
A setUp() 0 6 1
A testSetTwiceForSameKeyStoresMultipleValues() 0 15 1
1
<?php namespace Chekote\NounStore\Store;
2
3
use Chekote\NounStore\Store;
4
use Chekote\Phake\Phake;
5
use ReflectionClass;
6
7
class SetTest extends StoreTest
8
{
9
    public function setUp()
10
    {
11
        parent::setUp();
12
13
        /* @noinspection PhpUndefinedMethodInspection */
14
        Phake::when($this->store)->set(Phake::anyParameters())->thenCallParent();
0 ignored issues
show
Bug introduced by
It seems like $this->store can also be of type Chekote\NounStore\Store; however, parameter $mock of Phake::when() does only seem to accept Phake_IMock, maybe add an additional type check? ( Ignorable by Annotation )

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

14
        Phake::when(/** @scrutinizer ignore-type */ $this->store)->set(Phake::anyParameters())->thenCallParent();
Loading history...
15
    }
16
17
    /**
18
     * Tests that calling store::set once stores the value correctly.
19
     */
20
    public function testSetOnceStoresValue()
21
    {
22
        $key = 'My Key';
23
        $value = 'My Value';
24
25
        $class = new ReflectionClass(Store::class);
26
        $nouns = $class->getProperty('nouns');
27
        $nouns->setAccessible(true);
28
29
        $this->store->set($key, $value);
0 ignored issues
show
Bug introduced by
The method set() does not exist on Phake_IMock. ( Ignorable by Annotation )

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

29
        $this->store->/** @scrutinizer ignore-call */ 
30
                      set($key, $value);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
30
31
        $this->assertCount(1, $nouns->getValue($this->store)[$key]);
32
        $this->assertEquals($value, $nouns->getValue($this->store)[$key][0]);
33
    }
34
35
    /**
36
     * Tests that calling store::set twice for the same key stores both values correctly.
37
     */
38
    public function testSetTwiceForSameKeyStoresMultipleValues()
39
    {
40
        $key = 'My Key';
41
        $value1 = 'My Value';
42
        $value2 = 'My Second Value';
43
44
        $this->store->set($key, $value1);
45
        $this->store->set($key, $value2);
46
47
        $store = Phake::makeVisible($this->store);
0 ignored issues
show
Bug introduced by
It seems like $this->store can also be of type Chekote\NounStore\Store; however, parameter $mock of Chekote\Phake\Phake::makeVisible() does only seem to accept Phake_IMock, maybe add an additional type check? ( Ignorable by Annotation )

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

47
        $store = Phake::makeVisible(/** @scrutinizer ignore-type */ $this->store);
Loading history...
48
        /* @noinspection PhpUndefinedFieldInspection */
49
        {
50
            $this->assertCount(2, $store->nouns[$key]);
0 ignored issues
show
Bug Best Practice introduced by
The property nouns does not exist on Chekote\Phake\Proxies\VisibilityProxy. Since you implemented __get, consider adding a @property annotation.
Loading history...
51
            $this->assertEquals($value1, $store->nouns[$key][0]);
52
            $this->assertEquals($value2, $store->nouns[$key][1]);
53
        }
54
    }
55
}
56