testInvalidArgumentExceptionBubblesUpFromKeyExists()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 12
rs 10
c 0
b 0
f 0
1
<?php namespace Unit\Chekote\NounStore\Assert;
2
3
use Chekote\NounStore\AssertionFailedException;
4
use InvalidArgumentException;
5
use OutOfBoundsException;
6
use Unit\Chekote\NounStore\Key\KeyTestCase;
7
use Unit\Chekote\Phake\Phake;
8
9
/**
10
 * @covers \Chekote\NounStore\Assert::keyValueIs()
11
 */
12
class KeyValueIsTest extends AssertTestCase
13
{
14
    public function setUp(): void
15
    {
16
        parent::setUp();
17
18
        /* @noinspection PhpUndefinedMethodInspection */
19
        Phake::when($this->assert)->keyValueIs(Phake::anyParameters())->thenCallParent();
20
    }
21
22
    public function testInvalidArgumentExceptionBubblesUpFromKeyExists(): void
23
    {
24
        $value = 'Another Value';
25
        $exception = new InvalidArgumentException('Key syntax is invalid');
26
27
        /* @noinspection PhpUndefinedMethodInspection */
28
        Phake::expect($this->assert, 1)->keyExists(KeyTestCase::INVALID_KEY)->thenThrow($exception);
0 ignored issues
show
Bug introduced by
The method keyExists() does not exist on Unit\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(KeyTestCase::INVALID_KEY)->thenThrow($exception);
Loading history...
29
30
        $this->expectException(get_class($exception));
31
        $this->expectExceptionMessage($exception->getMessage());
32
33
        $this->assert->keyValueIs(KeyTestCase::INVALID_KEY, $value);
0 ignored issues
show
Bug introduced by
The method keyValueIs() does not exist on Unit\Chekote\NounStore\Assert\AssertPhake. ( 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(KeyTestCase::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...
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(KeyTestCase::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(): void
37
    {
38
        $key = '16th Thing';
39
        $value = 'Kiwi';
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);
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(): void
52
    {
53
        $key = '17th Thing';
54
        $value = 'Orange';
55
        $exception = new AssertionFailedException("Entry '$key' does not match '$value'");
56
57
        /* @noinspection PhpUndefinedMethodInspection */
58
        Phake::expect($this->assert, 1)->keyExists($key)->thenReturn('Some Other Value');
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(): void
67
    {
68
        $key = '18th Thing';
69
        $value = 'Pear';
70
71
        /* @noinspection PhpUndefinedMethodInspection */
72
        Phake::expect($this->assert, 1)->keyExists($key)->thenReturn($value);
73
74
        $this->assert->keyValueIs($key, $value);
75
    }
76
}
77