You must’ve heard of Unit testing… If not, then this talk is definitely for you! If you do know Unit testing, you probably ran at some point into a hurdle: “Where do I start?” And despite your best efforts, you end up not having enough tests for your application – Then that change request comes in, requiring you to change that very same complex piece of code for which you are lacking tests! How do you going refactor while maintaining all those ‘undocumented’ business rules? This talk will show how Codeception can be leveraged to refactor the visuals aspects of an application, maintaining backwards compatibility on API changes and even assist in moving to a whole different server infrastructure.
19. CODECEPT GENERATE:CEST ACCEPTANCE HOME
public function seeIfNameExists(AcceptanceTester $I)
{
$I->wantTo('see if conference name exists');
$I->amOnPage(‘/');
$I->click(‘#rt-logo‘);
$I->see('zendcon');
}
22. REUSE CODE FOR DIFFERENT TESTS
class CompareSteps extends AcceptanceTester {
public function seeIfNameExists()
{
$I = $this;
$I->amOnPage('/');
$I->see('zendcon');
}
}
class MenuCest {
public function seeIfNameExistsViaCCStep(CompareSteps $I)
{
$I->seeIfNameExists();
}
}
33. GET HTML OF BOTH VERSIONS
public function getHtml($page, $path)
{
$I = $this;
$I->amOnPage($page);
return $this->getHtmlFromContent(
$I->fetchModule('PhpBrowser'), $path);
}
public function getAlternateHtml($page, $path)
{
return $this->getHtmlFromContent(
$this->getPhpBrowserByPage($page), $path);
}
35. COMPARING 2 VERSIONS IN 1 RUN
public function seeSameOnVersions($page, $path, $altPath, $message)
{
$I = $this;
list($left, $right) = $this->getContentFromVersions(
$page, $path, $altPath);
$I->seeEquals($left, $right, $message);
}
public function getContentFromVersions($page, $path, $altPath)
{
return array(
$this->getHtml($page, $path),
$this->getAlternateHtml($page, $altPath)
);
}
36. TEST PAGE HEADER
public function seeIfPageHeaderIsIdentical(CompareSteps $I)
{
$I->seeSameOnVersions(
HomePage::$URL,
'h2',
'h2',
'Homepage header not identical'
);
}
37. TEST SIGNUP FORM
public function seeIfFormActionIsIdentical(CompareSteps $I)
{
$I->seeSameOnVersions(
HomePage::$URL,
'.rsformbox1',
'.rsformbox1',
'Homepage signup form not identical'
);
}
38. TEST SIGNUP FORM
public function seeIfFormActionIsIdentical(CompareSteps $I)
{
$I->seeSameOnVersions(
HomePage::$URL,
'.rsformbox1',
'.rsformbox1',
'Homepage signup form not identical'
);
}
<div class="rsformbox1 title3">
- <form method=“post" id="userForm" action="http://www.zendcon.com/">
+ <form method="post" id="userForm" action="http://zendcon.com/">
45. public function testGetGists(ApiTester $I) {
$I->wantTo('see if we can get the gists listing');
$I->haveHttpHeader('Accept', 'application/vnd.github.beta+json');
$I->sendGet('/users/weierophinney/gists');
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
}
public function testGetGist(ApiTester $I) {
$I->wantTo('see if we can get a gist');
$I->haveHttpHeader('Accept', 'application/vnd.github.beta+json');
$I->sendGet('/gists/2c47c9d59f4a5214f0c3');
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
}
47. /**
* @env beta
*/
public function testGetOldVersionGist(ApiTester $I) {
$I->wantTo('see if we can get a gist');
$I->haveHttpHeader('Accept', $I->getAcceptHeader());
$I->sendGet('/gists/2c47c9d59f4a5214f0c3');
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContainsJson(
array('user' => array('login' => ‘weierophinney')
));
}
48. SPOT THE DIFFERENCE
/**
* @env version3
*/
public function testGetOldVersionGist(ApiTester $I) {
$I->wantTo('see if we can get a gist');
$I->haveHttpHeader('Accept', $I->getAcceptHeader());
$I->sendGet('/gists/2c47c9d59f4a5214f0c3');
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContainsJson(
array('owner' => array('login' => ‘weierophinney')
));
}