Passed
Push — master ( 639b92...a2ec98 )
by Donald
13:52
created

AssertHasTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testKeyWithNonExistingNthThrowsException() 0 7 1
A testNonExistentNthParameterThrowsException() 0 7 1
A testKeyWithExistingNthReturnsValue() 0 4 1
A testExistingNthParameterReturnsValue() 0 4 1
A testMismatchedNthInKeyAndParamAreRejected() 0 6 1
1
<?php namespace Chekote\NounStore\Store;
2
3
use InvalidArgumentException;
4
use OutOfBoundsException;
5
6
/**
7
 * @covers Store::assertHas()
8
 */
9
class AssertHasTest extends StoreTest
10
{
11
    public function testMismatchedNthInKeyAndParamAreRejected()
12
    {
13
        $this->expectException(InvalidArgumentException::class);
14
15
        /* @noinspection PhpUnhandledExceptionInspection */
16
        $this->store->assertHas('1st Thing', 1);
17
    }
18
19
    public function testKeyWithExistingNthReturnsValue()
20
    {
21
        /* @noinspection PhpUnhandledExceptionInspection */
22
        $this->assertEquals(self::FIRST_VALUE, $this->store->assertHas('1st ' . self::KEY));
23
    }
24
25
    public function testKeyWithNonExistingNthThrowsException()
26
    {
27
        $this->expectException(OutOfBoundsException::class);
28
        $this->expectExceptionMessage("Entry '3rd " . self::KEY . "' was not found in the store.");
29
30
        /* @noinspection PhpUnhandledExceptionInspection */
31
        $this->store->assertHas('3rd ' . self::KEY);
32
    }
33
34
    public function testExistingNthParameterReturnsValue()
35
    {
36
        /* @noinspection PhpUnhandledExceptionInspection */
37
        $this->assertEquals(self::FIRST_VALUE, $this->store->assertHas(self::KEY, 0));
38
    }
39
40
    public function testNonExistentNthParameterThrowsException()
41
    {
42
        $this->expectException(OutOfBoundsException::class);
43
        $this->expectExceptionMessage("Entry '3rd " . self::KEY . "' was not found in the store.");
44
45
        /* @noinspection PhpUnhandledExceptionInspection */
46
        $this->store->assertHas(self::KEY, 2);
47
    }
48
}
49