|
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
|
|
|
|