summaryrefslogtreecommitdiff
path: root/tests/Unit/Http/RequestServiceProviderTest.php
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2018-08-13 16:30:27 +0200
committermsquare <msquare@notrademark.de>2018-08-19 16:44:33 +0200
commitbf6efe532c8f2de84e95b090911280a9b1b61ce8 (patch)
tree33f767dc22b8073e1151782b77d1a48b25ff28b0 /tests/Unit/Http/RequestServiceProviderTest.php
parent6415882b1c3c9ead00ccbab09e2292a22ce3d1d2 (diff)
Added trusted proxies
Diffstat (limited to 'tests/Unit/Http/RequestServiceProviderTest.php')
-rw-r--r--tests/Unit/Http/RequestServiceProviderTest.php46
1 files changed, 39 insertions, 7 deletions
diff --git a/tests/Unit/Http/RequestServiceProviderTest.php b/tests/Unit/Http/RequestServiceProviderTest.php
index a137b0ac..eddf7ee5 100644
--- a/tests/Unit/Http/RequestServiceProviderTest.php
+++ b/tests/Unit/Http/RequestServiceProviderTest.php
@@ -2,6 +2,8 @@
namespace Engelsystem\Test\Unit\Http;
+use Engelsystem\Config\Config;
+use Engelsystem\Container\ServiceProvider;
use Engelsystem\Http\Request;
use Engelsystem\Http\RequestServiceProvider;
use Engelsystem\Test\Unit\ServiceProviderTest;
@@ -10,20 +12,50 @@ use PHPUnit_Framework_MockObject_MockObject as MockObject;
class RequestServiceProviderTest extends ServiceProviderTest
{
/**
- * @covers \Engelsystem\Http\RequestServiceProvider::register()
+ * @return array
*/
- public function testRegister()
+ public function provideRegister()
{
- /** @var MockObject|Request $request */
- $request = $this->getMockBuilder(Request::class)
- ->getMock();
+ 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']],
+ ];
+ }
- $app = $this->getApp(['call', 'instance']);
+ /**
+ * @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']);
$this->setExpects($app, 'call', [[Request::class, 'createFromGlobals']], $request);
+ $this->setExpects($app, 'get', ['config'], $config);
$this->setExpects($app, 'instance', ['request', $request]);
+ $this->setExpects($config, 'get', ['trusted_proxies'], $configuredProxies);
- $serviceProvider = new RequestServiceProvider($app);
+ /** @var ServiceProvider|MockObject $serviceProvider */
+ $serviceProvider = $this->getMockBuilder(RequestServiceProvider::class)
+ ->setConstructorArgs([$app])
+ ->setMethods(['setTrustedProxies'])
+ ->getMock();
+ $serviceProvider->expects($this->once())
+ ->method('setTrustedProxies')
+ ->with($request, $trustedProxies);
$serviceProvider->register();
}
}