Skip to content

Commit

Permalink
fix deprecation notice when running test (exception tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
raoul2000 committed May 29, 2018
1 parent ea2822b commit fb5b2c1
Show file tree
Hide file tree
Showing 13 changed files with 200 additions and 134 deletions.
7 changes: 4 additions & 3 deletions CHANGE.md
@@ -1,6 +1,7 @@
# version 1.2.0_WIP
- upgrade to Yii 2.0.13 dependency
- **about Events** : Since Yii v2.0.14 it is possible to *specify event name as a wildcard pattern*
# version 1.2.0
- upgrade to Yii 2.0.13 dependency : if you are using a version of Yii 2.0.13 or greater you must use this version (or greater).

**about Events** : Since Yii v2.0.14 it is possible to *specify event name as a wildcard pattern*
```PHP
$component->on('event.group.*', function ($event) {
Yii::trace($event->name . ' is triggered.');
Expand Down
18 changes: 12 additions & 6 deletions tests/codeception/unit/workflow/base/StatusObjectTest.php
Expand Up @@ -105,8 +105,10 @@ public function testNullId()
{
$this->specify('status creation fails when empty id is provided', function ()
{
$this->setExpectedException(
'yii\base\InvalidConfigException',
$this->expectException(
'yii\base\InvalidConfigException'
);
$this->expectExceptionMessage(
'missing status id'
);

Expand All @@ -121,8 +123,10 @@ public function testMissingWorkflowId()
{
$this->specify('create a status instance with no workflow id', function ()
{
$this->setExpectedException(
'yii\base\InvalidConfigException',
$this->expectException(
'yii\base\InvalidConfigException'
);
$this->expectExceptionMessage(
'missing workflow id'
);
new Status([
Expand All @@ -134,8 +138,10 @@ public function testNullWorkflowId()
{
$this->specify('create a status instance with empty workflow id', function ()
{
$this->setExpectedException(
'yii\base\InvalidConfigException',
$this->expectException(
'yii\base\InvalidConfigException'
);
$this->expectExceptionMessage(
'missing workflow id'
);
new Status([
Expand Down
12 changes: 8 additions & 4 deletions tests/codeception/unit/workflow/base/TransitionObjectTest.php
Expand Up @@ -111,8 +111,10 @@ public function testEmptyEndStatusFails()
{
$this->specify('create transition with empty end status fails', function ()
{
$this->setExpectedException(
'yii\base\InvalidConfigException',
$this->expectException(
'yii\base\InvalidConfigException'
);
$this->expectExceptionMessage(
'missing end status'
);
new Transition([
Expand All @@ -129,8 +131,10 @@ public function testNotStatusEndStatusFails()

$this->specify('create transition with end status not Status instance fails ', function ()
{
$this->setExpectedException(
'raoul2000\workflow\base\WorkflowException',
$this->expectException(
'raoul2000\workflow\base\WorkflowException'
);
$this->expectExceptionMessage(
'End status object must implement raoul2000\workflow\base\StatusInterface'
);
new Transition([
Expand Down
64 changes: 38 additions & 26 deletions tests/codeception/unit/workflow/base/WorkflowObjectTest.php
Expand Up @@ -31,8 +31,10 @@ public function testWorkflowCreationSuccess()
public function testMissingIdFails()
{
$this->specify('create a workflow instance with no id', function () {
$this->setExpectedException(
'yii\base\InvalidConfigException',
$this->expectException(
'yii\base\InvalidConfigException'
);
$this->expectExceptionMessage(
'missing workflow id'
);
new Workflow([
Expand All @@ -44,8 +46,10 @@ public function testMissingIdFails()
public function testEmptyIdFails()
{
$this->specify('create a workflow instance with invalid id', function () {
$this->setExpectedException(
'yii\base\InvalidConfigException',
$this->expectException(
'yii\base\InvalidConfigException'
);
$this->expectExceptionMessage(
'missing workflow id'
);
new Workflow([
Expand All @@ -58,8 +62,10 @@ public function testEmptyIdFails()
public function testMissingInitialStatusIdFails()
{
$this->specify('create a workflow instance with no initial status id', function () {
$this->setExpectedException(
'yii\base\InvalidConfigException',
$this->expectException(
'yii\base\InvalidConfigException'
);
$this->expectExceptionMessage(
'missing initial status id'
);
new Workflow([
Expand All @@ -70,8 +76,10 @@ public function testMissingInitialStatusIdFails()
public function testEmptyInitialStatusIdFails()
{
$this->specify('create a workflow instance with empty initial status id', function () {
$this->setExpectedException(
'yii\base\InvalidConfigException',
$this->expectException(
'yii\base\InvalidConfigException'
);
$this->expectExceptionMessage(
'missing initial status id'
);
new Workflow([
Expand All @@ -80,33 +88,37 @@ public function testEmptyInitialStatusIdFails()
]);
});
}

public function testAccessorFails()
{
// creating a Workflow with 'new' will not allow to use some accessors

$w = new Workflow([
'id' => 'wid',
'initialStatusId' => 'A'
]);

$this->specify('fails to get initial status if no source component is available', function () use ($w) {
$this->setExpectedException(
'raoul2000\workflow\base\WorkflowException',
$this->expectException(
'raoul2000\workflow\base\WorkflowException'
);
$this->expectExceptionMessage(
'no workflow source component available'
);
$w->getInitialStatus();
});
});

$this->specify('fails to get all statues if no source component is available', function () use ($w) {
$this->setExpectedException(
'raoul2000\workflow\base\WorkflowException',
$this->expectException(
'raoul2000\workflow\base\WorkflowException'
);
$this->expectExceptionMessage(
'no workflow source component available'
);
$w->getAllStatuses();
});
}

public function testWorkflowAccessorSuccess()
{
$src = new WorkflowFileSource();
Expand All @@ -123,22 +135,22 @@ public function testWorkflowAccessorSuccess()
]);
$w = $src->getWorkflow('wid');
verify_that($w != null);

$this->specify('initial status can be obtained through workflow',function() use($w) {

expect_that($w->getInitialStatus() instanceof StatusInterface);
expect_that($w->getInitialStatus()->getId() == $w->getInitialStatusId());

});
});

$this->specify('all statuses can be obtained through workflow',function() use($w) {

$statuses = $w->getAllStatuses();

expect_that(is_array($statuses) && count($statuses) == 3);
expect_that($statuses['wid/A'] instanceof StatusInterface );
expect_that($statuses['wid/B'] instanceof StatusInterface );
expect_that($statuses['wid/C'] instanceof StatusInterface );
expect_that($statuses['wid/C'] instanceof StatusInterface );
});
}
}
}
14 changes: 9 additions & 5 deletions tests/codeception/unit/workflow/behavior/ChangeStatusTest.php
Expand Up @@ -27,7 +27,7 @@ protected function setup()
'definitionLoader' => [
'class' => 'raoul2000\workflow\source\file\PhpClassLoader',
'namespace' => 'tests\codeception\unit\models'
]
]
]);
}

Expand All @@ -41,8 +41,10 @@ public function testChangeStatusOnSaveFailed()
$item = $this->items('item1');
$this->assertTrue($item->workflowStatus->getId() == 'Item04Workflow/B');

$this->setExpectedException(
'raoul2000\workflow\base\WorkflowException',
$this->expectException(
'raoul2000\workflow\base\WorkflowException'
);
$this->expectExceptionMessage(
'No status found with id Item04Workflow/Z'
);

Expand All @@ -55,8 +57,10 @@ public function testChangeStatusByMethodFailed()
$item = $this->items('item1');
$this->assertTrue($item->workflowStatus->getId() == 'Item04Workflow/B');

$this->setExpectedException(
'raoul2000\workflow\base\WorkflowException',
$this->expectException(
'raoul2000\workflow\base\WorkflowException'
);
$this->expectExceptionMessage(
'No status found with id Item04Workflow/Z'
);

Expand Down
Expand Up @@ -79,8 +79,10 @@ public function testEnterWorkflowFails2()
$item = new Item04();
$this->specify('enterWorkflow fails if workflow not found for ID',function() use($item) {

$this->setExpectedException(
'raoul2000\workflow\base\WorkflowException',
$this->expectException(
'raoul2000\workflow\base\WorkflowException'
);
$this->expectExceptionMessage(
'failed to load workflow definition : Class tests\codeception\unit\models\INVALIDID does not exist'
);

Expand Down
14 changes: 8 additions & 6 deletions tests/codeception/unit/workflow/behavior/GetNextStatusTest.php
Expand Up @@ -29,7 +29,7 @@ protected function setup()
'definitionLoader' => [
'class' => 'raoul2000\workflow\source\file\PhpClassLoader',
'namespace' => 'tests\codeception\unit\models'
]
]
]);
}

Expand Down Expand Up @@ -89,10 +89,12 @@ public function testGetNextStatusFails()
]);

$this->specify('getNextStatus throws exception if default workflow Id is invalid',function() use ($item) {
$this->setExpectedException(
'raoul2000\workflow\base\WorkflowException',
"Invalid workflow Id : 'INVALID_ID'"
);
$this->expectException(
'raoul2000\workflow\base\WorkflowException'
);
$this->expectExceptionMessage(
"Invalid workflow Id : 'INVALID_ID'"
);
$item->getNextStatuses();
});
}
Expand Down Expand Up @@ -120,7 +122,7 @@ function($event) {
0 => [
'name' => SimpleWorkflowBehavior::EVENT_BEFORE_CHANGE_STATUS,
'success' => null
],
],
1 => [
'name' => 'beforeEnterWorkflow{Item04Workflow}',
'success' => null
Expand Down
24 changes: 14 additions & 10 deletions tests/codeception/unit/workflow/behavior/InitStatusTest.php
Expand Up @@ -21,7 +21,7 @@ protected function setup()
'definitionLoader' => [
'class' => 'raoul2000\workflow\source\file\PhpClassLoader',
'namespace' => 'tests\codeception\unit\models'
]
]
]);

}
Expand Down Expand Up @@ -53,8 +53,10 @@ public function testInitStatusOnAttachFails()
$this->specify('status initialisation fails when status not found', function(){
$model = new Item01();
$model->status = 'Workflow1/X';
$this->setExpectedException(
'raoul2000\workflow\base\WorkflowException',
$this->expectException(
'raoul2000\workflow\base\WorkflowException'
);
$this->expectExceptionMessage(
'No status found with id Workflow1/X'
);
$model->attachBehavior('workflow', [
Expand Down Expand Up @@ -98,7 +100,7 @@ public function testInitStatusAfterFindSuccess()
verify('current model status is "B"',$model->getWorkflowStatus()->getId())->equals('Workflow1/B');
});
}

public function testInitStatusAfterFindFails()
{
$this->specify('status initialisation success when saving model', function(){
Expand All @@ -110,29 +112,31 @@ public function testInitStatusAfterFindFails()
$model->status = 'Workflow1/X';
$model->save(false);

$this->setExpectedException(
'raoul2000\workflow\base\WorkflowException',
$this->expectException(
'raoul2000\workflow\base\WorkflowException'
);
$this->expectExceptionMessage(
'No status found with id Workflow1/X'
);

$model = Item01::findOne(1);

});
}

// public function testAutoInsertSuccess()
// {
// $this->specify('autoInsert feature works ok', function() {

// $model = new Item01();
// $model->attachBehavior('workflow', [
// 'class' => SimpleWorkflowBehavior::className(),
// 'defaultWorkflowId' => 'Workflow1',
// 'autoInsert' => true
// ]);

// expect('', $model->hasWorkflowStatus())->false();
// expect_that(' status attribute is not null', $model->status != null);
// });
// }
// }
}
16 changes: 13 additions & 3 deletions tests/codeception/unit/workflow/behavior/StatusAccessorTest.php
Expand Up @@ -26,7 +26,7 @@ protected function setup()
'definitionLoader' => [
'class' => 'raoul2000\workflow\source\file\PhpClassLoader',
'namespace' => 'tests\codeception\unit\models'
]
]
]);


Expand Down Expand Up @@ -55,7 +55,12 @@ public function testOnConstructSuccess()
public function testOnConstructFails()
{
$this->statusAccessor->statusToReturnOnGet = 'NOT FOUND';
$this->setExpectedException('raoul2000\workflow\base\WorkflowException',"Not a valid status id format: failed to get workflow id - status = 'NOT FOUND'");
$this->expectException(
'raoul2000\workflow\base\WorkflowException'
);
$this->expectExceptionMessage(
"Not a valid status id format: failed to get workflow id - status = 'NOT FOUND'"
);
new Item07();
}
public function testOnEnterWorkflowByMethodSuccess()
Expand Down Expand Up @@ -109,7 +114,12 @@ public function testOnEnterWorkflowFails()
verify('item status is Item07Workflow/B', $item->getworkflowStatus()->getId())->equals('Item07Workflow/B');
verify('getStatus has been called ',$this->statusAccessor->callGetStatusCount)->equals(1);

$this->setExpectedException('raoul2000\workflow\base\WorkflowException',"Model already in a workflow");
$this->expectException(
'raoul2000\workflow\base\WorkflowException'
);
$this->expectExceptionMessage(
"Model already in a workflow"
);

$item->enterWorkflow();
}
Expand Down

0 comments on commit fb5b2c1

Please sign in to comment.