public function run(CodeGuy $I) { $I->wantTo('run steps from scenario'); $I->haveStub($test = Stub::makeEmpty('\\Codeception\\TestCase\\Cept')); $I->haveStub($scenario = Stub::make('\\Codeception\\Scenario', array('test' => $test, 'steps' => Stub::factory('\\Codeception\\Step', 2)))); $I->executeTestedMethodOn($scenario)->seeMethodInvoked($test, 'runStep')->seePropertyEquals($scenario, 'currentStep', 1); }
public function loadScenario() { if (file_exists($this->bootstrap)) { require $this->bootstrap; } $unit = $this->testClass; if (isset($this->testClass->class)) { if (!class_exists($this->testClass->class, true)) { throw new \Exception("Tested class '{$unit->class}' can't be loaded."); } } // executing test $I = new \CodeGuy($this->scenario); if ($this->getCoveredMethod()) { $I->testMethod($this->signature); } if ($spec = $this->getSpecFromMethod()) { $I->wantTo($spec); } if ($this->static) { $class = $unit->class; if (!is_callable(array($class, $this->testMethod))) { throw new \Exception("Method {$this->specName} can't be found in tested class"); } call_user_func(array(get_class($unit), $this->testMethod), $I); } else { if (!is_callable(array($unit, $this->testMethod))) { throw new \Exception("Method {$this->specName} can't be found in tested class"); } call_user_func(array($this->testClass, $this->testMethod), $I); } }
public function convertWithException(\CodeGuy $I) { $I->wantTo("test if converting of different measure types fails."); $I->haveStub($converter = Stub::make($this->class)); $I->amTestingMethod('\\Measure\\Converter.convert'); $I->executeTestedMethodOn($converter, 1, 'liter', 'kg'); $I->seeExceptionThrown('\\ErrorException'); }
public function makeAScreenshot(CodeGuy $I) { $I->wantTo('save screenshot'); $I->haveStub($selenium = Stub::makeEmpty('\\Codeception\\Module\\Selenium')); $I->haveFakeClass($stub = Stub::make($this->class, array('test' => Stub::makeEmpty('\\Codeception\\TestCase\\Cept', array('getFileName' => function () { return 'testtest'; })), 'module' => $selenium))); $I->executeTestedMethodOn($stub); $I->seeMethodInvoked($selenium, '_saveScreenshot'); $I->seeMethodNotInvoked($stub, 'debug'); }
<?php $I = new CodeGuy($scenario); $I->wantTo('drink beer, actually...');