2017-11-01 14:47:09 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Engelsystem\Test\Unit\Http;
|
|
|
|
|
2018-08-13 16:30:27 +02:00
|
|
|
use Engelsystem\Config\Config;
|
|
|
|
use Engelsystem\Container\ServiceProvider;
|
2017-11-01 14:47:09 +01:00
|
|
|
use Engelsystem\Http\Request;
|
|
|
|
use Engelsystem\Http\RequestServiceProvider;
|
|
|
|
use Engelsystem\Test\Unit\ServiceProviderTest;
|
2019-04-24 10:45:00 +02:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2018-09-02 02:09:56 +02:00
|
|
|
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
|
2017-11-01 14:47:09 +01:00
|
|
|
|
|
|
|
class RequestServiceProviderTest extends ServiceProviderTest
|
|
|
|
{
|
|
|
|
/**
|
2018-08-13 16:30:27 +02:00
|
|
|
* @return array
|
2017-11-01 14:47:09 +01:00
|
|
|
*/
|
2018-08-13 16:30:27 +02:00
|
|
|
public function provideRegister()
|
2017-11-01 14:47:09 +01:00
|
|
|
{
|
2018-08-13 16:30:27 +02:00
|
|
|
return [
|
|
|
|
['', []],
|
|
|
|
[[], []],
|
|
|
|
['192.168.10.99', ['192.168.10.99']],
|
|
|
|
[' 234.234.234.234 ', ['234.234.234.234']],
|
|
|
|
['123.234.123.234,10.0.0.0/8', ['123.234.123.234', '10.0.0.0/8']],
|
|
|
|
['123.123.234.234 , ' . PHP_EOL . ' 11.22.33.44/22 ', ['123.123.234.234', '11.22.33.44/22']],
|
|
|
|
[['10.100.20.0/24'], ['10.100.20.0/24']],
|
|
|
|
];
|
|
|
|
}
|
2017-11-01 14:47:09 +01:00
|
|
|
|
2018-08-13 16:30:27 +02:00
|
|
|
/**
|
|
|
|
* @dataProvider provideRegister
|
|
|
|
* @covers \Engelsystem\Http\RequestServiceProvider::register()
|
|
|
|
*
|
|
|
|
* @param string|array $configuredProxies
|
|
|
|
* @param array $trustedProxies
|
|
|
|
*/
|
|
|
|
public function testRegister($configuredProxies, $trustedProxies)
|
|
|
|
{
|
|
|
|
/** @var Config|MockObject $config */
|
|
|
|
$config = $this->getMockBuilder(Config::class)->getMock();
|
|
|
|
/** @var Request|MockObject $request */
|
|
|
|
$request = $this->getMockBuilder(Request::class)->getMock();
|
|
|
|
|
|
|
|
$app = $this->getApp(['call', 'get', 'instance']);
|
2017-11-01 14:47:09 +01:00
|
|
|
|
|
|
|
$this->setExpects($app, 'call', [[Request::class, 'createFromGlobals']], $request);
|
2018-08-13 16:30:27 +02:00
|
|
|
$this->setExpects($app, 'get', ['config'], $config);
|
|
|
|
$this->setExpects($config, 'get', ['trusted_proxies'], $configuredProxies);
|
2017-11-01 14:47:09 +01:00
|
|
|
|
2018-09-02 02:09:56 +02:00
|
|
|
$app->expects($this->exactly(3))
|
|
|
|
->method('instance')
|
|
|
|
->withConsecutive(
|
|
|
|
[Request::class, $request],
|
|
|
|
[SymfonyRequest::class, $request],
|
|
|
|
['request', $request]
|
|
|
|
);
|
2017-11-01 14:47:09 +01:00
|
|
|
|
2018-08-13 16:30:27 +02:00
|
|
|
/** @var ServiceProvider|MockObject $serviceProvider */
|
|
|
|
$serviceProvider = $this->getMockBuilder(RequestServiceProvider::class)
|
|
|
|
->setConstructorArgs([$app])
|
|
|
|
->setMethods(['setTrustedProxies'])
|
|
|
|
->getMock();
|
|
|
|
$serviceProvider->expects($this->once())
|
|
|
|
->method('setTrustedProxies')
|
|
|
|
->with($request, $trustedProxies);
|
2017-11-01 14:47:09 +01:00
|
|
|
$serviceProvider->register();
|
|
|
|
}
|
|
|
|
}
|