Skip to content

Commit

Permalink
Model: Add tests for HTTP classes
Browse files Browse the repository at this point in the history
  • Loading branch information
SMillerDev committed May 1, 2018
1 parent 8331319 commit 39be46b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/PHPDraft/Model/HTTPRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class HTTPRequest implements Comparable
public function __construct(&$parent)
{
$this->parent = &$parent;
$this->id = md5(microtime());
}

/**
Expand All @@ -90,7 +91,6 @@ public function __construct(&$parent)
*/
public function parse($object)
{
$this->id = md5(microtime());
$this->method = $object->attributes->method;
$this->title = isset($object->meta->title) ? $object->meta->title : NULL;

Expand Down
2 changes: 1 addition & 1 deletion src/PHPDraft/Model/HTTPResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ class HTTPResponse implements Comparable

public function __construct($parent)
{
$this->id = md5(microtime());
$this->parent = &$parent;
$this->id = md5(microtime());
}

/**
Expand Down
20 changes: 17 additions & 3 deletions src/PHPDraft/Model/Tests/HTTPRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public function setUp()
$this->parent = $this->getMockBuilder('\PHPDraft\Model\Transition')
->disableOriginalConstructor()
->getMock();
$this->mock_function('microtime', 'test');
$this->class = new HTTPRequest($parent);
$this->unmock_function('microtime');
$this->reflection = new ReflectionClass('PHPDraft\Model\HTTPRequest');
}

Expand All @@ -54,9 +56,21 @@ public function tearDown()
*/
public function testSetupCorrectly()
{
$property = $this->reflection->getProperty('parent');
$property->setAccessible(TRUE);
$this->assertNull($property->getValue($this->class));
$parent_property = $this->reflection->getProperty('parent');
$parent_property->setAccessible(TRUE);
$this->assertNull($parent_property->getValue($this->class));

$id_property = $this->reflection->getProperty('id');
$id_property->setAccessible(TRUE);
$this->assertSame('098f6bcd4621d373cade4e832627b4f6', $id_property->getValue($this->class));
}

/**
* Tests if get_id returns the correct ID.
*/
public function testGetId()
{
$this->assertSame('098f6bcd4621d373cade4e832627b4f6', $this->class->get_id());
}

/**
Expand Down
14 changes: 14 additions & 0 deletions src/PHPDraft/Model/Tests/HTTPResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public function setUp()
$parent = NULL;
$this->parent = $this->getMockBuilder('\PHPDraft\Model\HierarchyElement')
->getMock();
$this->mock_function('microtime', 'test');
$this->class = new HTTPResponse($parent);
$this->unmock_function('microtime');
$this->reflection = new ReflectionClass('PHPDraft\Model\HTTPResponse');
}

Expand All @@ -54,6 +56,18 @@ public function testSetupCorrectly()
$property = $this->reflection->getProperty('parent');
$property->setAccessible(TRUE);
$this->assertNull($property->getValue($this->class));

$id_property = $this->reflection->getProperty('id');
$id_property->setAccessible(TRUE);
$this->assertSame('098f6bcd4621d373cade4e832627b4f6', $id_property->getValue($this->class));
}

/**
* Tests if get_id returns the correct ID.
*/
public function testGetId()
{
$this->assertSame('098f6bcd4621d373cade4e832627b4f6', $this->class->get_id());
}

/**
Expand Down

0 comments on commit 39be46b

Please sign in to comment.