Passed
Pull Request — 2.0 (#36)
by Donald
02:59 queued 01:27
created

testInvalidArgumentExceptionBubblesUpFromKeyExists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 12
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php namespace Chekote\NounStore\Assert;
2
3
use Chekote\NounStore\Key\KeyTest;
4
use Chekote\Phake\Phake;
5
use InvalidArgumentException;
6
use OutOfBoundsException;
7
use RuntimeException;
8
9
/**
10
 * @covers \Chekote\NounStore\Assert::keyValueIs()
11
 */
12
class KeyValueIsTest extends AssertTest
13
{
14
    public function setUp()
15
    {
16
        parent::setUp();
17
18
        /* @noinspection PhpUndefinedMethodInspection */
19
        Phake::when($this->assert)->keyValueIs(Phake::anyParameters())->thenCallParent();
0 ignored issues
show
Bug introduced by
It seems like $this->assert can also be of type Chekote\NounStore\Assert; 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

19
        Phake::when(/** @scrutinizer ignore-type */ $this->assert)->keyValueIs(Phake::anyParameters())->thenCallParent();
Loading history...
20
    }
21
22
    public function testInvalidArgumentExceptionBubblesUpFromKeyExists()
23
    {
24
        $value = 'Some Value';
25
        $exception = new InvalidArgumentException('Key syntax is invalid');
26
27
        /* @noinspection PhpUndefinedMethodInspection */
28
        Phake::expect($this->assert, 1)->keyExists(KeyTest::INVALID_KEY)->thenThrow($exception);
0 ignored issues
show
Bug introduced by
The method keyExists() does not exist on Chekote\Phake\Expectation. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

28
        Phake::expect($this->assert, 1)->/** @scrutinizer ignore-call */ keyExists(KeyTest::INVALID_KEY)->thenThrow($exception);
Loading history...
Bug introduced by
It seems like $this->assert can also be of type Chekote\NounStore\Assert; however, parameter $mock of Chekote\Phake\Phake::expect() 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

28
        Phake::expect(/** @scrutinizer ignore-type */ $this->assert, 1)->keyExists(KeyTest::INVALID_KEY)->thenThrow($exception);
Loading history...
29
30
        $this->expectException(get_class($exception));
31
        $this->expectExceptionMessage($exception->getMessage());
32
33
        $this->assert->keyValueIs(KeyTest::INVALID_KEY, $value);
0 ignored issues
show
Bug introduced by
The method keyValueIs() 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

33
        $this->assert->/** @scrutinizer ignore-call */ 
34
                       keyValueIs(KeyTest::INVALID_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...
34
    }
35
36
    public function testMissingKeyThrowsOutOfBoundsException()
37
    {
38
        $key = '10th Thing';
39
        $value = 'Some Value';
40
        $exception = new OutOfBoundsException("Entry '$key' was not found in the store.");
41
42
        /* @noinspection PhpUndefinedMethodInspection */
43
        Phake::expect($this->assert, 1)->keyExists($key)->thenThrow($exception);
0 ignored issues
show
Bug introduced by
It seems like $this->assert can also be of type Chekote\NounStore\Assert; however, parameter $mock of Chekote\Phake\Phake::expect() 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

43
        Phake::expect(/** @scrutinizer ignore-type */ $this->assert, 1)->keyExists($key)->thenThrow($exception);
Loading history...
44
45
        $this->expectException(get_class($exception));
46
        $this->expectExceptionMessage($exception->getMessage());
47
48
        $this->assert->keyValueIs($key, $value);
49
    }
50
51
    public function testFailedMatchThrowsRuntimeException()
52
    {
53
        $key = '10th Thing';
54
        $value = 'Some Value';
55
        $exception = new RuntimeException("Entry '$key' does not match '$value'");
56
57
        /* @noinspection PhpUndefinedMethodInspection */
58
        Phake::expect($this->assert, 1)->keyExists($key)->thenReturn('Some Other Value');
0 ignored issues
show
Bug introduced by
It seems like $this->assert can also be of type Chekote\NounStore\Assert; however, parameter $mock of Chekote\Phake\Phake::expect() 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

58
        Phake::expect(/** @scrutinizer ignore-type */ $this->assert, 1)->keyExists($key)->thenReturn('Some Other Value');
Loading history...
59
60
        $this->expectException(get_class($exception));
61
        $this->expectExceptionMessage($exception->getMessage());
62
63
        $this->assert->keyValueIs($key, $value);
64
    }
65
66
    public function testSuccessfulMatchThrowsNoException()
67
    {
68
        $key = '10th Thing';
69
        $value = 'Some Value';
70
71
        /* @noinspection PhpUndefinedMethodInspection */
72
        Phake::expect($this->assert, 1)->keyExists($key)->thenReturn($value);
0 ignored issues
show
Bug introduced by
It seems like $this->assert can also be of type Chekote\NounStore\Assert; however, parameter $mock of Chekote\Phake\Phake::expect() 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

72
        Phake::expect(/** @scrutinizer ignore-type */ $this->assert, 1)->keyExists($key)->thenReturn($value);
Loading history...
73
74
        $this->assert->keyValueIs($key, $value);
75
    }
76
}
77