summaryrefslogtreecommitdiff
path: root/tests/Unit/Http
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2017-10-31 17:17:32 +0100
committerIgor Scheller <igor.scheller@igorshp.de>2017-10-31 17:17:32 +0100
commit8c703e12029c2170ced5cafe4c91e9fd5f8414d9 (patch)
tree31233077208a7c1eb66a76e5087a26c226045828 /tests/Unit/Http
parenta7d2bcf88b855af7fb101f2388f9f4a3d2cf0281 (diff)
Added request test
Diffstat (limited to 'tests/Unit/Http')
-rw-r--r--tests/Unit/Http/RequestTest.php98
1 files changed, 98 insertions, 0 deletions
diff --git a/tests/Unit/Http/RequestTest.php b/tests/Unit/Http/RequestTest.php
new file mode 100644
index 00000000..3f317367
--- /dev/null
+++ b/tests/Unit/Http/RequestTest.php
@@ -0,0 +1,98 @@
+<?php
+
+namespace Engelsystem\Test\Unit\Http;
+
+use Engelsystem\Http\Request;
+use PHPUnit\Framework\TestCase;
+use PHPUnit_Framework_MockObject_MockObject as MockObject;
+
+class RequestTest extends TestCase
+{
+ /**
+ * @covers \Engelsystem\Http\Request::postData
+ */
+ public function testPostData()
+ {
+ $request = new Request(
+ ['foo' => 'I\'m a test!'],
+ ['foo' => 'bar']
+ );
+
+ $this->assertEquals('bar', $request->postData('foo'));
+ $this->assertEquals('LoremIpsum', $request->postData('test-key', 'LoremIpsum'));
+ }
+
+ /**
+ * @covers \Engelsystem\Http\Request::input
+ */
+ public function testInput()
+ {
+ $request = new Request(
+ ['foo' => 'I\'m a test!'],
+ ['foo' => 'bar']
+ );
+
+ $this->assertEquals('I\'m a test!', $request->input('foo'));
+ $this->assertEquals('LoremIpsum', $request->input('test-key', 'LoremIpsum'));
+ }
+
+ /**
+ * @covers \Engelsystem\Http\Request::has
+ */
+ public function testHas()
+ {
+ $request = new Request([
+ 'foo' => 'I\'m a test!',
+ 'bar' => '',
+ ]);
+
+ $this->assertTrue($request->has('foo'));
+ $this->assertFalse($request->has('bar'));
+ }
+
+ /**
+ * @covers \Engelsystem\Http\Request::path
+ */
+ public function testPath()
+ {
+ /** @var MockObject|Request $request */
+ $request = $this
+ ->getMockBuilder(Request::class)
+ ->setMethods(['getPathInfo'])
+ ->getMock();
+
+ $request
+ ->expects($this->atLeastOnce())
+ ->method('getPathInfo')
+ ->willReturnOnConsecutiveCalls(
+ '/foo',
+ '/'
+ );
+
+ $this->assertEquals('foo', $request->path());
+ $this->assertEquals('/', $request->path());
+ }
+
+ /**
+ * @covers \Engelsystem\Http\Request::url
+ */
+ public function testUrl()
+ {
+ /** @var MockObject|Request $request */
+ $request = $this
+ ->getMockBuilder(Request::class)
+ ->setMethods(['getUri'])
+ ->getMock();
+
+ $request
+ ->expects($this->atLeastOnce())
+ ->method('getUri')
+ ->willReturnOnConsecutiveCalls(
+ 'http://foo.bar/bla/foo/',
+ 'https://lorem.ipsum/dolor/sit?amet=consetetur&sadipscing=elitr'
+ );
+
+ $this->assertEquals('http://foo.bar/bla/foo', $request->url());
+ $this->assertEquals('https://lorem.ipsum/dolor/sit', $request->url());
+ }
+}