summaryrefslogtreecommitdiff
path: root/tests/Unit/Routing/RoutingServiceProviderTest.php
blob: ce3d729012feb3aeae6993f96c8427ea9b22032a (plain)
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
<?php

namespace Engelsystem\Test\Unit\Routing;

use Engelsystem\Config\Config;
use Engelsystem\Routing\LegacyUrlGenerator;
use Engelsystem\Routing\RoutingServiceProvider;
use Engelsystem\Routing\UrlGenerator;
use Engelsystem\Routing\UrlGeneratorInterface;
use Engelsystem\Test\Unit\ServiceProviderTest;
use PHPUnit_Framework_MockObject_MockObject as MockObject;

class RoutingServiceProviderTest extends ServiceProviderTest
{
    /**
     * @covers \Engelsystem\Routing\RoutingServiceProvider::register()
     */
    public function testRegister()
    {
        $app = $this->getApp(['make', 'instance', 'bind', 'get']);
        /** @var MockObject|Config $config */
        $config = $this->getMockBuilder(Config::class)->getMock();
        /** @var MockObject|UrlGeneratorInterface $urlGenerator */
        $urlGenerator = $this->getMockForAbstractClass(UrlGeneratorInterface::class);
        /** @var MockObject|UrlGeneratorInterface $legacyUrlGenerator */
        $legacyUrlGenerator = $this->getMockForAbstractClass(UrlGeneratorInterface::class);

        $config->expects($this->atLeastOnce())
            ->method('get')
            ->with('rewrite_urls')
            ->willReturnOnConsecutiveCalls(
                true,
                false
            );

        $this->setExpects($app, 'get', ['config'], $config, $this->atLeastOnce());

        $app->expects($this->atLeastOnce())
            ->method('make')
            ->withConsecutive(
                [UrlGenerator::class],
                [LegacyUrlGenerator::class]
            )
            ->willReturnOnConsecutiveCalls(
                $urlGenerator,
                $legacyUrlGenerator
            );
        $app->expects($this->atLeastOnce())
            ->method('instance')
            ->withConsecutive(
                ['routing.urlGenerator', $urlGenerator],
                ['routing.urlGenerator', $legacyUrlGenerator]
            );
        $this->setExpects(
            $app, 'bind',
            [UrlGeneratorInterface::class, 'routing.urlGenerator'], null,
            $this->atLeastOnce()
        );

        $serviceProvider = new RoutingServiceProvider($app);
        $serviceProvider->register();
        $serviceProvider->register();
    }
}