1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Basster\LegacyBridgeBundle\Tests\Routing; |
4
|
|
|
|
5
|
|
|
use Basster\LegacyBridgeBundle\Routing\LegacyRouteLoader; |
6
|
|
|
use org\bovigo\vfs\vfsStream; |
7
|
|
|
use org\bovigo\vfs\vfsStreamFile; |
8
|
|
|
|
9
|
|
|
class LegacyRouteLoaderTest extends \PHPUnit_Framework_TestCase |
10
|
|
|
{ |
11
|
|
|
/** @var vfsStreamFile */ |
12
|
|
|
private $legacyFile; |
13
|
|
|
|
14
|
|
|
/** @var LegacyRouteLoader */ |
15
|
|
|
private $routeLoader; |
16
|
|
|
|
17
|
|
|
/** @var \org\bovigo\vfs\vfsStreamDirectory */ |
18
|
|
|
private $root; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @test |
22
|
|
|
*/ |
23
|
|
|
public function createsHelloPhpRoute() |
24
|
|
|
{ |
25
|
|
|
$routes = $this->routeLoader->load('.', 'legacy'); |
26
|
|
|
|
27
|
|
|
$legacyRoute = $routes->get('basster.legacy.hello'); |
28
|
|
|
$routePath = '/hello.php'; |
29
|
|
|
|
30
|
|
|
self::assertNotNull($legacyRoute); |
31
|
|
|
self::assertEquals($routePath, $legacyRoute->getPath()); |
32
|
|
|
self::assertEquals($this->legacyFile->url(), |
33
|
|
|
$legacyRoute->getDefault('legacyScript')); |
34
|
|
|
self::assertEquals($routePath, $legacyRoute->getDefault('requestPath')); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @test |
39
|
|
|
* @expectedException \RuntimeException |
40
|
|
|
* @expectedExceptionMessage Do not add the "legacy" loader twice |
41
|
|
|
*/ |
42
|
|
|
public function shouldThrowRuntimeExceptionWhenLoadedMultipleTimes() |
43
|
|
|
{ |
44
|
|
|
$this->routeLoader->load('.', 'legacy'); |
45
|
|
|
$this->routeLoader->load('.', 'legacy'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @test |
50
|
|
|
*/ |
51
|
|
|
public function dontSupportWhenPathIsNotExisting() |
52
|
|
|
{ |
53
|
|
|
$this->routeLoader = new LegacyRouteLoader(__DIR__.'/not_existing'); |
54
|
|
|
self::assertFalse($this->routeLoader->supports('any', 'legacy')); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @test |
59
|
|
|
*/ |
60
|
|
|
public function dontSupportWhenPathIsNotReadable() |
61
|
|
|
{ |
62
|
|
|
$dir = vfsStream::newDirectory('legacy', 0000)->at($this->root); |
63
|
|
|
|
64
|
|
|
$this->routeLoader = new LegacyRouteLoader($dir->url()); |
65
|
|
|
self::assertFalse($this->routeLoader->supports('any', 'legacy')); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @test |
70
|
|
|
*/ |
71
|
|
|
public function supportsLegacyType() |
72
|
|
|
{ |
73
|
|
|
self::assertTrue( |
74
|
|
|
$this->routeLoader->supports("don't mind...", 'legacy') |
75
|
|
|
); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** {@inheritdoc} */ |
79
|
|
|
protected function setUp() |
80
|
|
|
{ |
81
|
|
|
$this->root = vfsStream::setup(); |
82
|
|
|
$this->legacyFile = vfsStream::newFile('hello.php')->at($this->root); |
83
|
|
|
$this->routeLoader = new LegacyRouteLoader($this->root->url()); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|