engelsystem/tests/Unit/Routing/RoutingServiceProviderTest.php

65 lines
2.2 KiB
PHP
Raw Normal View History

2017-10-31 13:40:13 +01:00
<?php
namespace Engelsystem\Test\Unit\Routing;
2017-10-31 13:40:13 +01:00
2018-03-31 05:19:49 +02:00
use Engelsystem\Config\Config;
use Engelsystem\Routing\LegacyUrlGenerator;
2017-10-31 13:40:13 +01:00
use Engelsystem\Routing\RoutingServiceProvider;
use Engelsystem\Routing\UrlGenerator;
2018-03-31 05:19:49 +02:00
use Engelsystem\Routing\UrlGeneratorInterface;
2017-10-31 14:15:19 +01:00
use Engelsystem\Test\Unit\ServiceProviderTest;
2018-03-31 05:19:49 +02:00
use PHPUnit_Framework_MockObject_MockObject as MockObject;
2017-10-31 13:40:13 +01:00
2017-10-31 14:15:19 +01:00
class RoutingServiceProviderTest extends ServiceProviderTest
2017-10-31 13:40:13 +01:00
{
/**
* @covers \Engelsystem\Routing\RoutingServiceProvider::register()
*/
public function testRegister()
{
2018-03-31 05:19:49 +02:00
$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);
2017-10-31 13:40:13 +01:00
2018-03-31 05:19:49 +02:00
$config->expects($this->atLeastOnce())
->method('get')
->with('rewrite_urls')
->willReturnOnConsecutiveCalls(
true,
false
);
2017-10-31 13:40:13 +01:00
2018-03-31 05:19:49 +02:00
$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()
);
2017-10-31 13:40:13 +01:00
$serviceProvider = new RoutingServiceProvider($app);
$serviceProvider->register();
2018-03-31 05:19:49 +02:00
$serviceProvider->register();
2017-10-31 13:40:13 +01:00
}
}