/** * Tests whether getContent() / setContent() / appendContent() work as expected. * * @return void */ public function testContentHandling() { $message = new HttpRequest(); $this->assertSame('', $message->getContent()); $message->setContent('foo'); $this->assertSame('foo', $message->getContent()); $message->appendContent('foo'); $this->assertSame('foofoo', $message->getContent()); $message->appendContent('bar'); $this->assertSame('foofoobar', $message->getContent()); $message->setContent(null); $this->assertSame(null, $message->getContent()); }
/** * Tests whether __construct() sets provided values correctly. * * @return void */ public function testConstructWithOptionalParameters() { $request = new HttpRequest(new Uri('http://example.com/foo'), HttpRequest::METHOD_POST, AbstractHttpMessage::HTTP_VERSION_1_0, array(new GenericHeaderField('X-Test', 'Foo')), array('a' => '1'), array('b' => '2'), array(new HttpCookie('test'))); $this->assertSame('', $request->getContent()); $this->assertSame('text/plain; charset=utf-8', $request->getContentType()->toString()); $this->assertFalse($request->getContentType()->hasBinaryContent()); $this->assertSame('X-Test: Foo', $request->getHeaderFields()->get('x-test')->toString()); $this->assertTrue($request->getCookies()->containsKey('test')); $this->assertSame('1', $request->getQueryParameters()->get('a')); $this->assertSame(array('b' => '2'), $request->getPostParameters()->toArray()); $this->assertSame('http://example.com/foo', $request->getUri()->toString()); $this->assertSame(HttpRequest::METHOD_POST, $request->getMethod()); }