Passed
Push — master ( 9b6c63...c5ec64 )
by Ole
05:50
created

LegacyRouteLoaderTest::createsHelloPhpRoute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 0
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