/** * @group reports * * @param CliGuy $I */ public function runReportMode(\CliGuy $I) { $I->wantTo('try the reporting mode'); $I->executeCommand('run dummy --report'); $I->seeInShellOutput('FileExistsCept'); $I->seeInShellOutput('........Ok'); }
public function useTheMirrorDirShortcut(CliGuy $I) { $I->wantTo('mirror dir with _mirrorDir shortcut'); $I->shortcutMirrorDir('box', 'bin'); $I->seeDirFound('bin'); $I->seeFileFound('robo.txt', 'bin'); }
public function configStartWithWrongPath(CliGuy $I) { $I->wantTo('start codeception with wrong path to a codeception.yml file'); $I->amInPath('tests/data/register_command/'); $I->executeFailCommand('-c no/exists/codeception.yml'); $I->seeInShellOutput('Your configuration file `no/exists/codeception.yml` could not be found.'); }
public function runTestForMultipleEnvironments(CliGuy $I) { $I->wantTo('check that multiple required environments are taken into account'); $I->amInPath('tests/data/sandbox'); $I->executeCommand('run messages MessageCest.php:multipleEnvRequired -vv --env env1'); $I->dontSeeInShellOutput('Multiple env given'); $I->executeCommand('run messages MessageCest.php:multipleEnvRequired -vv --env env2'); $I->dontSeeInShellOutput('Multiple env given'); $I->executeCommand('run messages MessageCest.php:multipleEnvRequired -vv --env env1,env2'); $I->seeInShellOutput('Multiple env given'); $I->executeCommand('run messages MessageCest.php:multipleEnvRequired -vv --env env2,env1'); $I->seeInShellOutput('Multiple env given'); }
public function appendIfMatch(CliGuy $I) { $I->wantTo('append lines with WriteToFile task, but only if pattern does not match'); $I->taskWriteToFile('blogpost.md')->line('****')->line('hello world')->line('****')->appendUnlessMatches('/hello/', 'Should not add this')->appendUnlessMatches('/goodbye/', 'Should add this')->appendIfMatches('/hello/', ' and should also add this')->appendIfMatches('/goodbye/', ' but should not add this')->appendIfMatches('/should/', '!')->run(); $I->seeFileFound('blogpost.md'); $I->seeFileContentsEqual(<<<HERE **** hello world **** Should add this and should also add this! HERE ); }
public function writeFewLines(CliGuy $I) { $I->wantTo('write lines with WriteToFile task'); $I->taskWriteToFile('blogpost.md')->line('****')->line('hello world')->line('****')->run(); $I->seeFileFound('blogpost.md'); $I->seeFileContentsEqual(<<<HERE **** hello world **** HERE ); }
public function checkIfExtensionsReceiveCorrectOptions(CliGuy $I) { $I->wantTo('check if extensions receive correct options'); $I->amInPath('tests/data/sandbox'); $I->executeCommand('run tests/dummy/AnotherCest.php:optimistic -c codeception_extended.yml'); $I->seeInShellOutput('Low verbosity'); $I->executeCommand('run tests/dummy/AnotherCest.php:optimistic -c codeception_extended.yml -v'); $I->seeInShellOutput('Medium verbosity'); $I->executeCommand('run tests/dummy/AnotherCest.php:optimistic -c codeception_extended.yml -vv'); $I->seeInShellOutput('High verbosity'); $I->executeCommand('run tests/dummy/AnotherCest.php:optimistic -c codeception_extended.yml -vvv'); $I->seeInShellOutput('Extreme verbosity'); }
/** * @group reports * * @param CliGuy $I */ public function runCustomReport(\CliGuy $I) { $I->wantTo('try the reporting mode'); $I->executeCommand('run dummy --report -c codeception_custom_report.yml'); $I->seeInShellOutput('✔ check config exists (FileExistsCept)'); $I->dontSeeInShellOutput('Ok'); }
<?php $I = new CliGuy($scenario); $I->wantTo('use alternative formatter delivered through extensions'); $I->amInPath('tests/data/sandbox'); $I->executeCommand('run tests/skipped/CommentsCept.php -c codeception_extended.yml'); $I->dontSeeInShellOutput("Trying to talk, just talk"); $I->dontSeeInShellOutput('As a very lazy qa'); $I->seeInShellOutput('[+] talk, just talk');
<?php $I = new CliGuy($scenario); $I->wantTo('archive directory and then extract it again with Archive and Extract tasks'); $I->amInPath(codecept_data_dir() . 'sandbox'); $I->seeDirFound('some/deeply/nested'); $I->seeFileFound('structu.re', 'some/deeply/nested'); $I->seeFileFound('existing_file', 'some/deeply'); // Test a bunch of archive types that we support foreach (['zip', 'tar', 'tar.gz', 'tar.bz2', 'tgz'] as $archiveType) { // First, take everything from the folder 'some/deeply' and make // an archive for it located in 'deep' $I->taskPack("deeply.{$archiveType}")->add(['deep' => 'some/deeply'])->run(); $I->seeFileFound("deeply.{$archiveType}"); // We are next going to extract the archive we created, this time // putting it into a folder called "extracted-$archiveType" (different // for each archive type we test). We rely on the default behavior // of our extractor to remove the top-level directory in the archive // ("deeply"). $I->taskExtract("deeply.{$archiveType}")->to("extracted-{$archiveType}")->preserveTopDirectory(false)->run(); $I->seeDirFound("extracted-{$archiveType}"); $I->seeDirFound("extracted-{$archiveType}/nested"); $I->seeFileFound('structu.re', "extracted-{$archiveType}/nested"); // Next, we'll extract the same archive again, this time preserving // the top-level folder. $I->taskExtract("deeply.{$archiveType}")->to("preserved-{$archiveType}")->preserveTopDirectory()->run(); $I->seeDirFound("preserved-{$archiveType}"); $I->seeDirFound("preserved-{$archiveType}/deep/nested"); $I->seeFileFound('structu.re', "preserved-{$archiveType}/deep/nested"); // Make another archive, this time composed of fanciful locations $I->taskPack("composed.{$archiveType}")->add(['a/b/existing_file' => 'some/deeply/existing_file'])->add(['x/y/z/structu.re' => 'some/deeply/nested/structu.re'])->run();
<?php $I = new CliGuy($scenario); $I->wantTo('overwrite a file with CopyDir task'); $I->amInPath(codecept_data_dir() . 'sandbox'); $I->seeDirFound('some'); $I->seeFileFound('existing_file', 'some'); $I->taskCopyDir(['some' => 'some_destination'])->run(); $I->seeFileFound('existing_file', 'some_destination/deeply'); $I->openFile('some_destination/deeply/existing_file'); $I->seeInThisFile('some existing file');
<?php $I = new CliGuy($scenario); $I->wantTo('execute incomplete test'); $I->amInPath('tests/data/sandbox'); $I->executeCommand('run skipped IncompleteMeCept.php'); $I->seeInShellOutput("I IncompleteMeCept: Make it incomplete"); $I->seeInShellOutput('OK, but incomplete, skipped, or risky tests!');
<?php $I = new CliGuy($scenario); $I->wantTo('run skipped test'); $I->amInPath('tests/data/sandbox'); $I->executeCommand('run skipped SkipMeCept.php'); $I->seeShellOutputMatches("~\\(SkipMeCept\\)\\s*?Skipped~"); $I->seeInShellOutput('OK, but incomplete, skipped, or risky tests!');
<?php $I = new CliGuy($scenario); $I->wantTo('generate gherkin steps'); $I->amInPath('tests/data/sandbox'); $I->executeCommand('generate:feature scenario Login'); $I->seeInShellOutput('Feature was created'); $I->seeFileFound('Login.feature', 'tests/scenario'); $I->seeInThisFile('Feature: Login'); $I->deleteThisFile(); $I->executeCommand('generate:feature scenario dummy/Login'); $I->seeFileFound('Login.feature', 'tests/scenario/dummy'); $I->seeInThisFile('Feature: Login');
<?php $I = new CliGuy($scenario); $I->wantTo('copy dir recursively with CopyDir task'); $I->amInPath(codecept_data_dir() . 'sandbox'); $I->seeDirFound('some/deeply/nested'); $I->seeFileFound('structu.re', 'some/deeply/nested'); $I->taskCopyDir(['some/deeply' => 'some_destination/deeply'])->run(); $I->seeDirFound('some_destination/deeply/nested'); $I->seeFileFound('structu.re', 'some_destination/deeply/nested');
<?php $I = new CliGuy($scenario); $I->wantTo('see that my group events fire only once'); $I->amInPath('tests/data/claypit'); $I->executeCommand('run dummy -g countevents -c codeception_grouped.yml'); $I->seeInShellOutput('Group Before Events: 1'); $I->dontSeeInShellOutput('Group Before Events: 2'); $I->seeInShellOutput('Group After Events: 1'); $I->dontSeeInShellOutput('Group After Events: 2');
<?php $I = new CliGuy($scenario); $I->wantTo('generate sample Cept'); $I->amInPath('tests/data/sandbox'); $I->executeCommand('generate:cept dummy DummyCept'); $I->seeFileFound('DummyCept.php', 'tests/dummy'); $I->seeInThisFile('$I = new DumbGuy($scenario);'); $I->deleteThisFile(); $I->amGoingTo('create scenario in folder'); $I->executeCommand('generate:cept dummy path/DummyCept'); $I->seeFileFound('DummyCept.php', 'tests/dummy/path'); $I->deleteThisFile(); $I->amGoingTo('create file with Cept.php suffix'); $I->executeCommand('generate:cept dummy DummyCept.php'); $I->seeFileFound('DummyCept.php'); $I->deleteThisFile(); $I->amGoingTo('create file without any suffix'); $I->executeCommand('generate:cept dummy Dummy'); $I->seeFileFound('DummyCept.php');
<?php $I = new CliGuy($scenario); $I->wantTo('generate sample Test'); $I->amInPath('tests/data/sandbox'); $I->executeCommand('generate:phpunit dummy Dummy'); $I->seeFileFound('DummyTest.php'); $I->seeInThisFile('class DummyTest extends \\PHPUnit_Framework_TestCase'); $I->seeInThisFile('function setUp()');
<?php $I = new CliGuy($scenario); $I->wantTo('perform actions and see result'); $I->amInPath('tests/data/sandbox'); $I->executeCommand('run skipped SkipMeCept.php'); $I->seeInShellOutput('(SkipMeCept.php) SKIPPED'); $I->seeInShellOutput('OK, but incomplete or skipped tests!');
<?php $I = new CliGuy($scenario); $I->wantTo('change configs and check that Guy is rebuilt'); $I->amInPath('tests/data/sandbox'); $I->writeToFile('tests/unit.suite.yml', <<<EOF class_name: CodeGuy modules: enabled: [Cli, CodeHelper] EOF ); $I->executeCommand('run unit PassingTest.php --debug'); $I->seeInShellOutput('Cli'); $I->seeFileFound('tests/_support/_generated/CodeGuyActions.php'); $I->seeInThisFile('public function seeInShellOutput'); $I->seeInThisFile('public function runShellCommand');
<?php $I = new CliGuy($scenario); $I->am('developer who likes testing'); $I->wantTo('generate sample Suite'); $I->lookForwardTo('have a better tests categorization'); $I->amInPath('tests/data/sandbox'); $I->executeCommand('generate:suite house HouseGuy'); $I->seeFileFound('house.suite.yml', 'tests'); $I->expect('guy class is generated'); $I->seeInThisFile('class_name: HouseGuy'); $I->seeInThisFile('- \\Helper\\House'); $I->seeFileFound('House.php', 'tests/_support/Helper'); $I->seeInThisFile('namespace Helper;'); $I->seeFileFound('_bootstrap.php', 'tests/house'); $I->expect('suite is not created due to dashes'); $I->executeCommand('generate:suite invalid-dash-suite'); $I->seeInShellOutput('contains invalid characters');
<?php $I = new CliGuy($scenario); $I->wantTo('see that comments can be easily added to test'); $I->amInPath('tests/data/sandbox'); $I->executeCommand('run tests/skipped/CommentsCept.php --steps'); $I->seeInShellOutput('* As a very lazy qa'); $I->seeInShellOutput('* So that I not do anything at all'); $I->seeInShellOutput('* have a comment for you'); $I->seeInShellOutput('* but I am too lazy to do any job'); $I->seeInShellOutput('* so please do that yourself'); $I->seeInShellOutput('I am going to leave that to you'); $I->seeInShellOutput('I expect you forgive me');
<?php $I = new CliGuy($scenario); $I->wantTo('copy dir with CopyDir task'); $I->amInPath(codecept_data_dir() . 'sandbox'); $I->taskCopyDir(['box' => 'bin'])->run(); $I->seeDirFound('bin'); $I->seeFileFound('robo.txt', 'bin');
<?php $I = new CliGuy($scenario); $I->wantTo('generate test scenario'); $I->amInPath('tests/data/sandbox'); $I->executeCommand('generate:scenarios dummy'); $I->seeFileFound('File_Exists.txt', 'tests/_data/scenarios'); $I->seeFileContentsEqual(<<<EOF I WANT TO CHECK CONFIG EXISTS I see file found "\$codeception" EOF );
<?php $testsPath = __DIR__ . '/../'; $I = new CliGuy($scenario); $I->wantTo('generate xml reports for unit tests'); $I->amInPath('tests/data/sandbox'); $I->executeCommand('run unit --xml --no-exit'); $I->seeFileFound('report.xml', 'tests/_output'); $I->seeInThisFile('<?xml'); $I->seeInThisFile('<testsuite name="unit"'); $I->seeInThisFile('<testcase name="testMe" class="PassingTest"'); $I->seeInThisFile('<testcase name="testIsTriangle with data set #0" class="DataProvidersTest" ' . 'file="' . realpath($testsPath . '/data/sandbox/tests/unit/DataProvidersTest.php') . '" '); $I->seeInThisFile('<testcase name="testOne" class="DependsTest"'); $I->seeInThisFile('<failure type="PHPUnit_Framework_ExpectationFailedException">FailingTest::testMe');
<?php $I = new CliGuy($scenario); $I->wantTo('see that my group extension works'); $I->amInPath('tests/data/sandbox'); $I->executeCommand('run skipped -g notorun -c codeception_grouped.yml'); $I->dontSeeInShellOutput("======> Entering NoGroup Test Scope\nMake it incomplete"); $I->dontSeeInShellOutput('<====== Ending NoGroup Test Scope'); $I->executeCommand('run dummy -g ok -c codeception_grouped.yml'); $I->dontSeeInShellOutput("======> Entering Ok Test Scope\nMake it incomplete"); $I->dontSeeInShellOutput('<====== Ending Ok Test Scope');
<?php $I = new CliGuy($scenario); $I->wantTo('flatten dir with FlattenDir task'); $I->amInPath(codecept_data_dir() . 'sandbox'); $I->taskFlattenDir(['some/deeply/nested/*.re' => 'flattened', '*.txt' => 'flattened'])->run(); $I->seeDirFound('flattened'); $I->seeFileFound('structu.re', 'flattened'); $I->seeFileFound('a.txt', 'flattened'); $I->seeFileFound('b.txt', 'flattened');
<?php $I = new CliGuy($scenario); $I->wantTo('delete dir with DeleteDirTask'); $I->amInPath(codecept_data_dir()); $I->seeFileFound('robo.txt', 'sandbox'); $I->taskDeleteDir(['sandbox/box'])->run(); $I->dontSeeFileFound('box', 'sandbox'); $I->dontSeeFileFound('robo.txt', 'sandbox');
<?php $I = new CliGuy($scenario); $I->wantTo('generate scenarios сценарий'); $I->amInPath('tests/data/sandbox'); $I->executeCommand('generate:scenarios dummy'); $I->seeFileFound('File_Exists.txt', 'tests/_data/scenarios'); $I->seeFileContentsEqual(<<<EOF I WANT TO CHECK CONFIG EXISTS I see file found "codeception.yml" EOF );
<?php $I = new CliGuy($scenario); $I->wantTo('concat files using Concat Task'); $I->amInPath(codecept_data_dir() . 'sandbox'); $I->taskConcat(['a.txt', 'b.txt'])->to('merged.txt')->run(); $I->seeFileFound('merged.txt'); $I->seeFileContentsEqual('AB');