Рефакторинг common unit тестов

This commit is contained in:
ErickSkrauch
2016-10-29 03:23:29 +03:00
parent 0e7013d9f5
commit d0548872f1
12 changed files with 88 additions and 103 deletions

View File

@@ -13,23 +13,19 @@ class DataBehaviorTest extends TestCase {
use ProtectedCaller;
public function testSetKey() {
$this->specify('setting value should change model data field', function() {
$model = $this->createModel();
/** @var DataBehavior $behavior */
$behavior = $model->behaviors['dataBehavior'];
$this->callProtected($behavior, 'setKey', 'my-key', 'my-value');
expect($model->_data)->equals(serialize(['my-key' => 'my-value']));
});
$model = $this->createModel();
/** @var DataBehavior $behavior */
$behavior = $model->behaviors['dataBehavior'];
$this->callProtected($behavior, 'setKey', 'my-key', 'my-value');
$this->assertEquals(serialize(['my-key' => 'my-value']), $model->_data);
}
public function testGetKey() {
$this->specify('getting value from exists data should work', function() {
$model = $this->createModel();
$model->_data = serialize(['some-key' => 'some-value']);
/** @var DataBehavior $behavior */
$behavior = $model->behaviors['dataBehavior'];
expect($this->callProtected($behavior, 'getKey', 'some-key'))->equals('some-value');
});
$model = $this->createModel();
$model->_data = serialize(['some-key' => 'some-value']);
/** @var DataBehavior $behavior */
$behavior = $model->behaviors['dataBehavior'];
$this->assertEquals('some-value', $this->callProtected($behavior, 'getKey', 'some-key'));
}
public function testGetData() {

View File

@@ -12,12 +12,10 @@ class EmailActivationExpirationBehaviorTest extends TestCase {
use ProtectedCaller;
public function testCalculateTime() {
$this->specify('just use create_time and plus passed time', function() {
$behavior = $this->createBehavior();
$time = time();
$behavior->owner->created_at = $time;
expect($this->callProtected($behavior, 'calculateTime', 10))->equals($time + 10);
});
$behavior = $this->createBehavior();
$time = time();
$behavior->owner->created_at = $time;
$this->assertEquals($time + 10, $this->callProtected($behavior, 'calculateTime', 10));
}
public function testCompareTime() {