Skip to content

Instantly share code, notes, and snippets.

@DavertMik
Created February 19, 2012 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavertMik/1862951 to your computer and use it in GitHub Desktop.
Save DavertMik/1862951 to your computer and use it in GitHub Desktop.
Codeception Spec BDD
<?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