This repository has been archived by the owner on Jan 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Zend\Http Request and Response refactoring:
- added tests for various objects - moved request line and response line into request and response object out of header object Zend\Stdlib: - refactored Message and Parameters for generalized usage - added tests Zend\Uri\UriFactory - fixed register scheme method to use proper property
- Loading branch information
Showing
5 changed files
with
163 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
/** | ||
* @namespace | ||
*/ | ||
namespace ZendTest\Http; | ||
|
||
use Zend\Stdlib\Message; | ||
|
||
class MessageTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testMessageCanSetAndGetContent() | ||
{ | ||
$message = new Message(); | ||
$ret = $message->setContent('I can set content'); | ||
$this->assertInstanceOf('Zend\Stdlib\Message', $ret); | ||
$this->assertEquals('I can set content', $message->getContent()); | ||
} | ||
|
||
public function testMessageCanSetAndGetMetadataKeyAsString() | ||
{ | ||
$message = new Message(); | ||
$ret = $message->setMetadata('foo', 'bar'); | ||
$this->assertInstanceOf('Zend\Stdlib\Message', $ret); | ||
$this->assertEquals('bar', $message->getMetadata('foo')); | ||
$this->assertEquals(array('foo' => 'bar'), $message->getMetadata()); | ||
} | ||
|
||
public function testMessageCanSetAndGetMetadataKeyAsArray() | ||
{ | ||
$message = new Message(); | ||
$ret = $message->setMetadata(array('foo' => 'bar')); | ||
$this->assertInstanceOf('Zend\Stdlib\Message', $ret); | ||
$this->assertEquals('bar', $message->getMetadata('foo')); | ||
} | ||
|
||
public function testMessageGetMetadataWillUseDefaultValueIfNoneExist() | ||
{ | ||
$message = new Message(); | ||
$this->assertEquals('bar', $message->getMetadata('foo', 'bar')); | ||
} | ||
|
||
public function testMessageThrowsExceptionOnInvalidKeyForMetadataSet() | ||
{ | ||
$message = new Message(); | ||
|
||
$this->setExpectedException('Zend\Stdlib\Exception\InvalidArgumentException'); | ||
$message->setMetadata(new \stdClass()); | ||
} | ||
|
||
public function testMessageThrowsExceptionOnInvalidKeyForMetadataGet() | ||
{ | ||
$message = new Message(); | ||
|
||
$this->setExpectedException('Zend\Stdlib\Exception\InvalidArgumentException'); | ||
$message->getMetadata(new \stdClass()); | ||
} | ||
|
||
public function testMessageToStringWorks() | ||
{ | ||
$message = new Message(); | ||
$message->setMetadata(array('Foo' => 'bar', 'One' => 'Two')); | ||
$message->setContent('This is my content'); | ||
$expected = "Foo: bar\r\nOne: Two\r\n\r\nThis is my content"; | ||
$this->assertEquals($expected, $message->__toString()); | ||
} | ||
|
||
public function testMessageThrowsExceptionOnFromString() | ||
{ | ||
$message = new Message(); | ||
|
||
$this->setExpectedException('Zend\Stdlib\Exception\DomainException'); | ||
$message->fromString('some string'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace ZendTest\Stdlib; | ||
|
||
use Zend\Stdlib\Parameters; | ||
|
||
class ParametersTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
|
||
public function testParametersConstructionAndClassStructure() | ||
{ | ||
$parameters = new Parameters(); | ||
$this->assertInstanceOf('Zend\Stdlib\ParametersDescription', $parameters); | ||
$this->assertInstanceOf('ArrayObject', $parameters); | ||
$this->assertInstanceOf('ArrayAccess', $parameters); | ||
$this->assertInstanceOf('Countable', $parameters); | ||
$this->assertInstanceOf('Serializable', $parameters); | ||
$this->assertInstanceOf('Traversable', $parameters); | ||
} | ||
|
||
public function testParametersPersistNameAndValues() | ||
{ | ||
$parameters = new Parameters(array('foo' => 'bar')); | ||
$this->assertEquals('bar', $parameters['foo']); | ||
$this->assertEquals('bar', $parameters->foo); | ||
$parameters->offsetSet('baz', 5); | ||
$this->assertEquals(5, $parameters->baz); | ||
|
||
$parameters->fromArray(array('bar' => 'foo')); | ||
$this->assertEquals('foo', $parameters->bar); | ||
|
||
$parameters->fromString('bar=foo&five=5'); | ||
$this->assertEquals('foo', $parameters->bar); | ||
$this->assertEquals('5', $parameters->five); | ||
$this->assertEquals(array('bar' => 'foo', 'five' => '5'), $parameters->toArray()); | ||
$this->assertEquals('bar=foo&five=5', $parameters->toString()); | ||
|
||
$parameters->fromArray(array()); | ||
$parameters->set('foof', 'barf'); | ||
$this->assertEquals('barf', $parameters->get('foof')); | ||
$this->assertEquals('barf', $parameters->foof); | ||
|
||
} | ||
|
||
public function testParametersOffsetgetReturnsNullIfNonexistentKeyIsProvided() | ||
{ | ||
$parameters = new Parameters; | ||
$this->assertNull($parameters->foo); | ||
} | ||
|
||
public function testParametersGetReturnsDefaultValueIfNonExistent() | ||
{ | ||
$parameters = new Parameters(); | ||
|
||
$this->assertEquals(5, $parameters->get('nonExistentProp', 5)); | ||
} | ||
|
||
} |