-
Notifications
You must be signed in to change notification settings - Fork 409
/
Copy pathMapTest.php
75 lines (55 loc) · 1.48 KB
/
MapTest.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
declare(strict_types=1);
namespace tests;
use Exception;
use flight\Engine;
use tests\classes\Hello;
use PHPUnit\Framework\TestCase;
class MapTest extends TestCase
{
private Engine $app;
protected function setUp(): void
{
$this->app = new Engine();
}
// Map a closure
public function testClosureMapping()
{
$this->app->map('map1', function () {
return 'hello';
});
$result = $this->app->map1();
self::assertEquals('hello', $result);
}
// Map a function
public function testFunctionMapping()
{
$this->app->map('map2', function () {
return 'hello';
});
$result = $this->app->map2();
self::assertEquals('hello', $result);
}
// Map a class method
public function testClassMethodMapping()
{
$h = new Hello();
$this->app->map('map3', [$h, 'sayHi']);
$result = $this->app->map3();
self::assertEquals('hello', $result);
}
// Map a static class method
public function testStaticClassMethodMapping()
{
$this->app->map('map4', [Hello::class, 'sayBye']);
$result = $this->app->map4();
self::assertEquals('goodbye', $result);
}
// Unmapped method
public function testUnmapped()
{
$this->expectException(Exception::class);
$this->expectExceptionMessage('doesNotExist must be a mapped method.');
$this->app->doesNotExist();
}
}