Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge pull request zendframework/zendframework#1383 from EvanDotPro/h…
Browse files Browse the repository at this point in the history
…otfix/zend-feed-tests

Utilize getter/setter in Subscription model for now() to prevent test failure
  • Loading branch information
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
32 changes: 31 additions & 1 deletion src/PubSubHubbub/Model/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
*/
class Subscription extends AbstractModel implements SubscriptionPersistenceInterface
{
/**
* Common Date\Date object to assist with unit testing
*
* @var Date\Date
*/
protected $now;

/**
* Save subscription to RDMBS
Expand All @@ -50,7 +56,7 @@ public function setSubscription(array $data)
$result = $this->_db->select(array('id' => $data['id']));
if ($result && (0 < count($result))) {
$data['created_time'] = $result->current()->created_time;
$now = new Date\Date;
$now = $this->getNow();
if (array_key_exists('lease_seconds', $data)
&& $data['lease_seconds']
) {
Expand Down Expand Up @@ -126,4 +132,28 @@ public function deleteSubscription($key)
return false;
}

/**
* Get a new Date\Date or the one injected for testing
*
* @return Date\Date
*/
public function getNow()
{
if (null === $this->now) {
return new Date\Date;
}
return $this->now;
}

/**
* Set a Date\Date instance for assisting with unit testing
*
* @param Date\Date $now
* @return Subscription
*/
public function setNow(Date\Date $now)
{
$this->now = $now;
return $this;
}
}
13 changes: 11 additions & 2 deletions test/PubSubHubbub/Model/SubscriptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
namespace ZendTest\Feed\PubSubHubbub\Model;

use Zend\Feed\PubSubHubbub\Model\Subscription;
use \Zend\Db\Adapter\Adapter as DbAdapter;
use \Zend\Db\TableGateway\TableGateway;
use Zend\Db\Adapter\Adapter as DbAdapter;
use Zend\Db\TableGateway\TableGateway;
use Zend\Date;

/**
* @category Zend
Expand Down Expand Up @@ -73,6 +74,14 @@ public function testImpemetsSubscriptionInterface()
unset($reflection);
}

public function testCurrentTimeSetterAndGetter()
{
$now = new Date\Date;
$subscription = new Subscription(new TableGateway('subscription', $this->initDb()));
$subscription->setNow($now);
$this->assertSame($subscription->getNow(), $now);
}

protected function initDb()
{
if (!extension_loaded('pdo')
Expand Down
9 changes: 6 additions & 3 deletions test/PubSubHubbub/Subscriber/CallbackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public function setUp()
$this->_tableGateway->expects($this->any())->method('getAdapter')
->will($this->returnValue($this->_adapter));
$storage = new Model\Subscription($this->_tableGateway);

$this->now = new Date\Date;
$storage->setNow(clone $this->now);

$this->_callback->setStorage($storage);

$this->_get = array(
Expand Down Expand Up @@ -268,7 +272,7 @@ public function testRespondsToValidConfirmationWith200Response()
->with($this->equalTo(array('id' => 'verifytokenkey')))
->will($this->returnValue($this->_rowset));

$t = new Date\Date;
$t = clone $this->now;
$rowdata = array(
'id' => 'verifytokenkey',
'verify_token' => hash('sha256', 'cba'),
Expand Down Expand Up @@ -305,7 +309,7 @@ public function testRespondsToValidConfirmationWithBodyContainingHubChallenge()
->with($this->equalTo(array('id' => 'verifytokenkey')))
->will($this->returnValue($this->_rowset));

$t = new Date\Date;
$t = clone $this->now;
$rowdata = array(
'id' => 'verifytokenkey',
'verify_token' => hash('sha256', 'cba'),
Expand Down Expand Up @@ -348,7 +352,6 @@ public function testRespondsToValidFeedUpdateRequestWith200Response()
->with($this->equalTo(array('id' => 'verifytokenkey')))
->will($this->returnValue($this->_rowset));

$t = new Date\Date;
$rowdata = array(
'id' => 'verifytokenkey',
'verify_token' => hash('sha256', 'cba'),
Expand Down

0 comments on commit 8e7172b

Please sign in to comment.