Created
February 19, 2012 10:14
-
-
Save DavertMik/1862951 to your computer and use it in GitHub Desktop.
Codeception Spec BDD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class EventMachineCest { | |
// Thus, a BDD goes this way: | |
// create a Cest class | |
// define features with should* methods | |
// define specifications in methods | |
// use wantTo or expect to define wider descriptions. | |
// use @doc annotations to assign this scenario to method in documentation. | |
function _before() | |
{ | |
$this->em = new EventMachine; | |
} | |
/** | |
* @doc: EventMachine.getState | |
**/ | |
function shouldHaveInitialState($I) | |
{ | |
$I->execute(function () use ($em) { | |
return $em->getState(); | |
}); | |
$I->seeResultEquals('initial'); | |
$I->execute(function () use ($em)){ | |
$em->addState('submitted', 'review', 'edited', 'published' ,'rejected'); | |
return $em->getStates(); | |
}) | |
$I->seeResultContains('sibmitted'); | |
$I->seeResultContains('edited'); | |
} | |
/** | |
* @doc: EventMachine.getState | |
* @doc: EventMachine.fireEvent | |
**/ | |
function shouldMoveBetweenTransitions($I) { | |
$I->wantTo('define transitions and move between them'); | |
$this->em->setTransition('approve','submitted','review'); | |
$I->executeMethod($this->em, 'fireEvent', 'approve'); | |
$I->executeMethod($this->em, 'getState'); | |
$I->seeResultEquals('review'); | |
} | |
function shouldMoveBetweenTransitionsOnCondition($I) { | |
$I->executeMethod($this->em, 'setTransition','approve','submitted','review', function ($obj) { return is_obj($obj); }); | |
$I->expect('transition wont be performed for non-object') | |
->executeMethod($this->em, 'fireEvent', 'approve', 'not an object'); | |
->executeMethod($this->em, 'getState') | |
->seeResultEquals('submitted'); | |
$I->expect('transition will be performed for object') | |
->executeMethod($this->em, 'fireEvent', 'approve', new stdClass); | |
->executeMethod($this->em, 'getState') | |
->seeResultEquals('submitted'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment