summaryrefslogtreecommitdiff
path: root/tests/Unit/Http
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Unit/Http')
-rw-r--r--tests/Unit/Http/LegacyUrlGeneratorTest.php54
-rw-r--r--tests/Unit/Http/RequestServiceProviderTest.php46
-rw-r--r--tests/Unit/Http/UrlGeneratorServiceProviderTest.php2
-rw-r--r--tests/Unit/Http/UrlGeneratorTest.php2
4 files changed, 95 insertions, 9 deletions
diff --git a/tests/Unit/Http/LegacyUrlGeneratorTest.php b/tests/Unit/Http/LegacyUrlGeneratorTest.php
new file mode 100644
index 00000000..2c087f8f
--- /dev/null
+++ b/tests/Unit/Http/LegacyUrlGeneratorTest.php
@@ -0,0 +1,54 @@
+<?php
+
+namespace Engelsystem\Test\Unit\Http;
+
+use Engelsystem\Application;
+use Engelsystem\Container\Container;
+use Engelsystem\Http\Request;
+use Engelsystem\Http\LegacyUrlGenerator;
+use Engelsystem\Http\UrlGeneratorInterface;
+use PHPUnit\Framework\TestCase;
+
+class LegacyUrlGeneratorTest extends TestCase
+{
+ public function provideLinksTo()
+ {
+ return [
+ ['/', 'http://foo.bar/index.php', [], 'http://foo.bar/'],
+ ['/foo-path', 'http://foo.bar/index.php/index.php', [], 'http://foo.bar/index.php?p=foo_path'],
+ ['/foo', 'http://foo.bar/index.php/index.php', [], 'http://foo.bar/index.php?p=foo'],
+ ['foo', 'http://foo.bar/index.php', ['test' => 'abc'], 'http://foo.bar/index.php?p=foo&test=abc'],
+ ];
+ }
+
+ /**
+ * @dataProvider provideLinksTo
+ * @covers \Engelsystem\Http\LegacyUrlGenerator::to
+ *
+ * @param string $urlToPath
+ * @param string $willReturn
+ * @param string[] $arguments
+ * @param string $expectedUrl
+ */
+ public function testTo($urlToPath, $willReturn, $arguments, $expectedUrl)
+ {
+ $app = new Container();
+ Application::setInstance($app);
+
+ $request = $this->getMockBuilder(Request::class)
+ ->getMock();
+
+ $request->expects($this->once())
+ ->method('getUriForPath')
+ ->with('/index.php')
+ ->willReturn($willReturn);
+
+ $app->instance('request', $request);
+
+ $urlGenerator = new LegacyUrlGenerator();
+ $this->assertInstanceOf(UrlGeneratorInterface::class, $urlGenerator);
+
+ $url = $urlGenerator->to($urlToPath, $arguments);
+ $this->assertEquals($expectedUrl, $url);
+ }
+}
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();
}
}
diff --git a/tests/Unit/Http/UrlGeneratorServiceProviderTest.php b/tests/Unit/Http/UrlGeneratorServiceProviderTest.php
index 787789fe..720af631 100644
--- a/tests/Unit/Http/UrlGeneratorServiceProviderTest.php
+++ b/tests/Unit/Http/UrlGeneratorServiceProviderTest.php
@@ -1,6 +1,6 @@
<?php
-namespace Engelsystem\Test\Unit\Routing;
+namespace Engelsystem\Test\Unit\Http;
use Engelsystem\Http\UrlGenerator;
use Engelsystem\Http\UrlGeneratorServiceProvider;
diff --git a/tests/Unit/Http/UrlGeneratorTest.php b/tests/Unit/Http/UrlGeneratorTest.php
index 89ffa7dd..fa2ec36e 100644
--- a/tests/Unit/Http/UrlGeneratorTest.php
+++ b/tests/Unit/Http/UrlGeneratorTest.php
@@ -1,6 +1,6 @@
<?php
-namespace Engelsystem\Test\Unit\Routing;
+namespace Engelsystem\Test\Unit\Http;
use Engelsystem\Application;
use Engelsystem\Container\Container;