Remove all sleep statements in tests.

This commit is contained in:
Benoît Burnichon
2016-01-22 18:55:10 +01:00
parent fafabf3e9e
commit b4555a696a
4 changed files with 47 additions and 20 deletions

View File

@@ -99,16 +99,16 @@ class Bridge_Api
} }
/** /**
* * @param null|DateTime $checkDate
* @return boolean * @return bool
*/ */
public function is_disabled() public function is_disabled(DateTime $checkDate = null)
{ {
if ($this->disable_time === null) { if ($this->disable_time === null) {
return false; return false;
} }
$date_obj = new DateTime(); $date_obj = $checkDate ?: new DateTime();
if ($date_obj > $this->disable_time) { if ($date_obj > $this->disable_time) {
$this->enable(); $this->enable();

View File

@@ -104,10 +104,10 @@ class Bridge_AccountTest extends \PhraseanetTestCase
$this->assertTrue(self::$object->get_updated_on() <= new DateTime()); $this->assertTrue(self::$object->get_updated_on() <= new DateTime());
$this->assertTrue(self::$object->get_updated_on() >= self::$object->get_created_on()); $this->assertTrue(self::$object->get_updated_on() >= self::$object->get_created_on());
$this->backDateObjectUpdatedOnField();
$update1 = self::$object->get_updated_on(); $update1 = self::$object->get_updated_on();
sleep(2);
self::$object->set_name('prout');
self::$object->set_name('prout');
$update2 = self::$object->get_updated_on(); $update2 = self::$object->get_updated_on();
$this->assertTrue($update2 > $update1); $this->assertTrue($update2 > $update1);
} }
@@ -117,9 +117,14 @@ class Bridge_AccountTest extends \PhraseanetTestCase
$new_name = 'YODELALI &é"\'(-è_çà)'; $new_name = 'YODELALI &é"\'(-è_çà)';
self::$object->set_name($new_name); self::$object->set_name($new_name);
$this->assertEquals($new_name, self::$object->get_name()); $this->assertEquals($new_name, self::$object->get_name());
$this->backDateObjectUpdatedOnField();
$update1 = self::$object->get_updated_on();
$new_name = 'BACHI BOUZOUKS'; $new_name = 'BACHI BOUZOUKS';
self::$object->set_name($new_name); self::$object->set_name($new_name);
$this->assertEquals($new_name, self::$object->get_name()); $this->assertEquals($new_name, self::$object->get_name());
$update2 = self::$object->get_updated_on();
$this->assertTrue($update2 > $update1);
} }
public function testGet_accounts_by_api() public function testGet_accounts_by_api()
@@ -156,4 +161,17 @@ class Bridge_AccountTest extends \PhraseanetTestCase
$account = Bridge_Account::load_account(self::$DI['app'], self::$object->get_id()); $account = Bridge_Account::load_account(self::$DI['app'], self::$object->get_id());
$this->assertEquals(self::$object->get_id(), $account->get_id()); $this->assertEquals(self::$object->get_id(), $account->get_id());
} }
private function backDateObjectUpdatedOnField()
{
static $reflection;
if (null === $reflection) {
$reflection = new ReflectionProperty(Bridge_Account::class, 'updated_on');
$reflection->setAccessible(true);
}
$reflection->setValue(self::$object, new DateTime('yesterday'));
}
} }

View File

@@ -60,26 +60,22 @@ class Bridge_ApiTest extends \PhraseanetTestCase
public function testenable() public function testenable()
{ {
$this->assertTrue(is_bool($this->object->is_disabled())); $this->assertInternalType('bool', $this->object->is_disabled());
$this->assertFalse($this->object->is_disabled()); $this->assertFalse($this->object->is_disabled());
sleep(1); $this->backDateObjectUpdatedOnField();
$update1 = $this->object->get_updated_on(); $update1 = $this->object->get_updated_on();
$this->object->disable(new DateTime('+2 seconds')); $this->object->disable(new DateTime('+2 seconds'));
$this->assertTrue($this->object->is_disabled()); $this->assertTrue($this->object->is_disabled());
sleep(3);
$update2 = $this->object->get_updated_on(); $update2 = $this->object->get_updated_on();
$this->assertTrue($update2 > $update1, $update2->format('Y-m-d, H:i:s') ." sould be > to " . $update1->format('Y-m-d, H:i:s')); $this->assertTrue($update2 > $update1, $update2->format('Y-m-d, H:i:s') ." sould be > to " . $update1->format('Y-m-d, H:i:s'));
$this->assertFalse($this->object->is_disabled());
$this->assertFalse($this->object->is_disabled(new DateTime('+10 seconds')));
$this->object->enable(); $this->object->enable();
$this->assertFalse($this->object->is_disabled()); $this->assertFalse($this->object->is_disabled());
} }
public function testdisable()
{
$this->testenable();
}
public function testGet_created_on() public function testGet_created_on()
{ {
$this->assertInstanceOf('DateTime', $this->object->get_created_on()); $this->assertInstanceOf('DateTime', $this->object->get_created_on());
@@ -92,4 +88,17 @@ class Bridge_ApiTest extends \PhraseanetTestCase
$this->assertTrue($this->object->get_updated_on() <= new DateTime()); $this->assertTrue($this->object->get_updated_on() <= new DateTime());
$this->assertTrue($this->object->get_updated_on() >= $this->object->get_created_on()); $this->assertTrue($this->object->get_updated_on() >= $this->object->get_created_on());
} }
private function backDateObjectUpdatedOnField()
{
static $reflection;
if (null === $reflection) {
$reflection = new ReflectionProperty(Bridge_Api::class, 'updated_on');
$reflection->setAccessible(true);
}
$reflection->setValue($this->object, new DateTime('yesterday'));
}
} }

View File

@@ -90,7 +90,7 @@ class Bridge_ElementTest extends \PhraseanetTestCase
$this->object->set_status($new_status); $this->object->set_status($new_status);
$this->assertEquals($new_status, $this->object->get_status()); $this->assertEquals($new_status, $this->object->get_status());
$this->BackDateObjectUpdatedOnField(); $this->backDateObjectUpdatedOnField();
$update1 = $this->object->get_updated_on(); $update1 = $this->object->get_updated_on();
$new_status = '&é"0687345àç_)à)'; $new_status = '&é"0687345àç_)à)';
@@ -107,7 +107,7 @@ class Bridge_ElementTest extends \PhraseanetTestCase
public function testSet_title() public function testSet_title()
{ {
$this->BackDateObjectUpdatedOnField(); $this->backDateObjectUpdatedOnField();
$update1 = $this->object->get_updated_on(); $update1 = $this->object->get_updated_on();
$new_title = 'Cigares du pharaon'; $new_title = 'Cigares du pharaon';
@@ -119,7 +119,7 @@ class Bridge_ElementTest extends \PhraseanetTestCase
public function testSet_distid() public function testSet_distid()
{ {
$this->BackDateObjectUpdatedOnField(); $this->backDateObjectUpdatedOnField();
$update1 = $this->object->get_updated_on(); $update1 = $this->object->get_updated_on();
$this->object->set_dist_id($this->dist_id); $this->object->set_dist_id($this->dist_id);
@@ -149,12 +149,12 @@ class Bridge_ElementTest extends \PhraseanetTestCase
} }
} }
private function BackDateObjectUpdatedOnField() private function backDateObjectUpdatedOnField()
{ {
static $reflection; static $reflection;
if (null === $reflection) { if (null === $reflection) {
$reflection = new ReflectionProperty(Bridge_Element::class, 'updatedAt'); $reflection = new ReflectionProperty(Bridge_Element::class, 'uploaded_on');
$reflection->setAccessible(true); $reflection->setAccessible(true);
} }