1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AbterPhp\Framework\Bootstrappers\Http; |
4
|
|
|
|
5
|
|
|
use Opulence\Framework\Configuration\Config; |
6
|
|
|
use Opulence\Ioc\Container; |
7
|
|
|
use Opulence\Routing\Dispatchers\IRouteDispatcher; |
8
|
|
|
use Opulence\Routing\Router; |
9
|
|
|
use Opulence\Routing\Routes\Caching\ICache; |
10
|
|
|
use Opulence\Routing\Routes\Compilers\ICompiler; |
11
|
|
|
use Opulence\Routing\Urls\UrlGenerator; |
12
|
|
|
use org\bovigo\vfs\vfsStream; |
13
|
|
|
use PHPUnit\Framework\TestCase; |
14
|
|
|
|
15
|
|
|
class RouterBootstrapperTest extends TestCase |
16
|
|
|
{ |
17
|
|
|
private const ROOT_PATH = 'exampleDir'; |
18
|
|
|
|
19
|
|
|
/** @var RouterBootstrapper */ |
20
|
|
|
private RouterBootstrapper $sut; |
21
|
|
|
|
22
|
|
|
public function setUp(): void |
23
|
|
|
{ |
24
|
|
|
$this->sut = new RouterBootstrapper(); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
protected function tearDown(): void |
28
|
|
|
{ |
29
|
|
|
Config::set('paths', 'config.http', null); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testRegisterBindings() |
33
|
|
|
{ |
34
|
|
|
vfsStream::setup(static::ROOT_PATH); |
35
|
|
|
$exampleDir = vfsStream::url(static::ROOT_PATH); |
36
|
|
|
|
37
|
|
|
Config::set('paths', 'config.http', $exampleDir); |
38
|
|
|
|
39
|
|
|
file_put_contents($exampleDir . DIRECTORY_SEPARATOR . 'routes.php', '<?php return 1;'); |
40
|
|
|
file_put_contents($exampleDir . DIRECTORY_SEPARATOR . 'module.php', '<?php return 2;'); |
41
|
|
|
|
42
|
|
|
$this->sut->setRoutePaths([$exampleDir . DIRECTORY_SEPARATOR . 'module.php']); |
43
|
|
|
|
44
|
|
|
$container = new Container(); |
45
|
|
|
|
46
|
|
|
$this->sut->registerBindings($container); |
47
|
|
|
|
48
|
|
|
$cache = $container->resolve(ICache::class); |
49
|
|
|
$this->assertInstanceOf(ICache::class, $cache); |
50
|
|
|
|
51
|
|
|
$routeDispatcher = $container->resolve(IRouteDispatcher::class); |
52
|
|
|
$this->assertInstanceOf(IRouteDispatcher::class, $routeDispatcher); |
53
|
|
|
|
54
|
|
|
$compiler = $container->resolve(ICompiler::class); |
55
|
|
|
$this->assertInstanceOf(ICompiler::class, $compiler); |
56
|
|
|
|
57
|
|
|
$router = $container->resolve(Router::class); |
58
|
|
|
$this->assertInstanceOf(Router::class, $router); |
59
|
|
|
|
60
|
|
|
$urlGenerator = $container->resolve(UrlGenerator::class); |
61
|
|
|
$this->assertInstanceOf(UrlGenerator::class, $urlGenerator); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|