-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathNotFoundExceptionTest.php
44 lines (33 loc) · 1.28 KB
/
NotFoundExceptionTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
namespace PHPWatch\SimpleContainer\Tests\Exception;
use PHPWatch\SimpleContainer\Container;
use PHPWatch\SimpleContainer\Exception\NotFoundException;
use PHPUnit\Framework\TestCase;
class NotFoundExceptionTest extends TestCase {
public function testNotFound(): void {
$container = new Container();
$this->expectException(NotFoundException::class);
$container->get('foo');
}
public function testNulledValuesDoNotThrow(): void {
$container = new Container(['foo' => null]);
$this->assertNull($container['foo']);
}
public function testClosureNullReturnsDoNotThrow(): void {
$container = new Container();
$container['foo'] = static fn(): ?string => null;
$this->assertNull($container['foo']);
$this->assertNull($container['foo']); // Trigger cached result
$container['foo'] = null;
$this->assertNull($container['foo']);
}
public function testUnsetTriggersException(): void {
$container = new Container();
$container->set('foo', null);
$this->assertTrue(isset($container['foo']));
unset($container['foo']);
$this->assertFalse(isset($container['foo']));
$this->expectException(NotFoundException::class);
$container['foo'];
}
}