public function phpFuncitons(CodeGuy $I) { $I->execute(function () { return strtoupper('hello'); }); $I->seeResultEquals('HELLO'); }
public function testParallelExec() { $result = $this->taskParallelExec()->process('ls 1')->process('ls 2')->process('ls 3')->run(); $this->process->verifyInvokedMultipleTimes('start', 3); verify($result->getExitCode())->equals(0); $this->guy->seeInOutput("3 processes ended in 0.00 s"); }
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 testAddCodeRollbackAndCompletion() { $collection = new Collection(); $rollback1 = new CountingTask(); $rollback2 = new CountingTask(); $completion1 = new CountingTask(); $completion2 = new CountingTask(); $collection->progressMessage("start collection tasks")->rollback($rollback1)->completion($completion1)->rollbackCode(function () use($rollback1) { $rollback1->run(); })->completionCode(function () use($completion1) { $completion1->run(); })->addCode(function () { return 42; })->progressMessage("not reached")->rollback($rollback2)->completion($completion2)->addCode(function () { return 13; }); $collection->setLogger($this->guy->logger()); $result = $collection->run(); // Execution stops on the first error. // Confirm that status code is converted to a Result object. verify($result->getExitCode())->equals(42); verify($rollback1->getCount())->equals(2); verify($rollback2->getCount())->equals(0); verify($completion1->getCount())->equals(2); verify($completion2->getCount())->equals(0); $this->guy->seeInOutput('start collection tasks'); $this->guy->doNotSeeInOutput('not reached'); }
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); } }
protected function send() { /** @var EEmailManager $emailManager */ $emailManager = Yii::app()->emailManager; $emailManager->email($emailManager->fromEmail, 'EmailManager subject', 'EmailManager message'); $this->codeGuy->seeInDatabase('email_spool', array('subject' => 'EmailManager subject')); $this->assertEquals(EmailSpool::model()->unpack(EmailSpool::model()->pack('EmailManager message')), 'EmailManager message'); }
public function addWrongLogstashLog(\CodeGuy $I, \Codeception\Scenario $scenario) { if ($scenario->running() === false) { return; } $I->removeEmergencyLog(); $I->addWrongLogstashLog('WrongLogstashLog'); $I->seeEmergencyLog('WrongLogstashLog'); }
public function testParallelExec() { $task = new \Robo\Task\Base\ParallelExec(); $task->setLogger($this->guy->logger()); $result = $task->process('ls 1')->process('ls 2')->process('ls 3')->run(); $this->process->verifyInvokedMultipleTimes('start', 3); verify($result->getExitCode())->equals(0); $this->guy->seeInOutput("3 processes finished"); }
public function addLogstashLogToFile(\CodeGuy $I, \Codeception\Scenario $scenario) { if ($scenario->running() === false) { return; } $I->removeLogstashFile(); $I->addLogstashFileLog('logstashFileLog_array', 'array'); $I->addLogstashFileLog('logstashFileLog_stdClass', 'stdClass'); $I->seeLogstashFile(); }
public function testAddWrongSignature(CodeGuy $I) { $I->createExamplePhar(\Yii::getAlias('@tests/_runtime/yii2-phar')); try { $I->addWrongSignature(); $I->fail("signature with wrong params didn't fire exception"); } catch (InvalidConfigException $error) { // Exception must fire. } }
protected function _before() { $this->codeGuy->createConsoleYiiApp(); require_once MOCKED_DIR . 'Migrator.php'; $this->codeGuy->setDbConnectionOptionsFromYiiConfig(APPLICATION_DIR . 'config/db-test.php'); $this->codeGuy->setDbDumpOptions(array('dump' => 'tests/_data/convert_to_ns.sql', 'populate' => true)); $this->command = new \MigrateToNestedSetsCommand('migratetonestedsets', null); $this->command->init(); $this->command->actionUnlock(); }
public function update() { $emailTemplate = EmailTemplate::model()->findByPk($this->emailTemplate->id); $emailTemplate->name = 'the name changed'; $emailTemplate->subject = 'the subject changed'; $emailTemplate->heading = 'the heading changed'; $emailTemplate->message = 'the message changed'; $save = $emailTemplate->save(); $this->assertTrue($save); $this->codeGuy->seeInDatabase('email_template', array('name' => 'the name changed', 'subject' => 'the subject changed', 'heading' => 'the heading changed', 'message' => 'the message changed')); }
/** * @dataProvider casesArgs * * @covers ::args * * @param string $expected * @param array $args */ public function testArgs($expected, $args) { $commandArguments = new CommandArgumentsHost(); $commandArguments->args($args); $this->guy->assertEquals($expected, $commandArguments->getArguments()); if ($args) { $commandArguments = new CommandArgumentsHost(); call_user_func_array([$commandArguments, 'args'], $args); $this->guy->assertEquals($expected, $commandArguments->getArguments()); } }
public function testBasics() { $task = new ResultDummyTask(); $result = new Result($task, 1, 'The foo barred', ['time' => 0]); $this->guy->seeInOutput('The foo barred'); $this->guy->seeInOutput('Error'); $this->guy->seeInOutput('[ResultDummyTask]'); $this->assertSame($task, $result->getTask()); $this->assertEquals(1, $result->getExitCode()); $this->assertEquals('The foo barred', $result->getMessage()); $this->assertEquals(['time' => 0], $result->getData()); $taskClone = $result->cloneTask(); $this->assertNotSame($task, $taskClone); $this->assertInstanceOf('Robo\\Task\\Shared\\TaskInterface', $taskClone); }
public function testTasksStopOnFail() { $argv = ['placeholder', 'test:stop-on-fail']; $result = $this->runner->execute($argv, Robo::output()); $this->guy->seeInOutput('['); $this->assertTrue($result > 0); }
public function testRunnerDebugOutput() { $argv = ['placeholder', 'test:verbosity', '-vvv']; $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream()); $this->guy->seeInOutput('This command will print more information at higher verbosity levels'); $this->guy->seeInOutput('This is a verbose message (-v).'); $this->guy->seeInOutput('This is a very verbose message (-vv).'); $this->guy->seeInOutput('This is a debug message (-vvv).'); $this->guy->seeInOutput(' [warning] This is a warning log message.'); $this->guy->seeInOutput(' [notice] This is a notice log message.'); $this->guy->seeInOutput(' [debug] This is a debug log message.'); $this->assertEquals(0, $result); }
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 generateFilename(CodeGuy $I) { $I->haveFakeClass($stub = Stub::make($this->class, array('test' => Stub::makeEmpty('\\Codeception\\TestCase\\Cept', array('getFileName' => function () { return 'testtest'; }))))); $I->executeTestedMethod($stub); $I->seeResultEquals(\Codeception\Configuration::logDir() . 'debug' . DIRECTORY_SEPARATOR . 'testtest - 1'); $I->executeTestedMethod($stub, 'mytest'); $I->seeResultEquals(\Codeception\Configuration::logDir() . 'debug' . DIRECTORY_SEPARATOR . 'testtest - 2 - mytest'); }
protected function update() { $date = time(); $emailSpool = EmailSpool::model()->findByPk($this->emailSpool->id); $emailSpool->transport = 'the transport changed'; $emailSpool->template = 'the template changed'; $emailSpool->priority = 100; $emailSpool->status = 'the status changed'; $emailSpool->model_name = 'the model_name changed'; $emailSpool->model_id = 'the model_id changed'; $emailSpool->to_address = 'the to_address changed'; $emailSpool->from_address = 'the from_address changed'; $emailSpool->subject = 'the subject changed'; $emailSpool->message = 'the message changed'; $emailSpool->sent = $date; $emailSpool->created = $date; $save = $emailSpool->save(); $this->assertTrue($save); $this->codeGuy->seeInDatabase('email_spool', array('transport' => 'the transport changed', 'template' => 'the template changed', 'priority' => 100, 'status' => 'the status changed', 'model_name' => 'the model_name changed', 'model_id' => 'the model_id changed', 'to_address' => 'the to_address changed', 'from_address' => 'the from_address changed', 'subject' => 'the subject changed', 'message' => 'the message changed', 'sent' => $date, 'created' => $date)); }
function testExceptions() { $I = new CodeGuy($this->scenario); $I->testMethod('UserModel.get'); $user = new UserModel(); $I->executeTestedMethodOn($user, 'name'); $I->seeExceptionThrown('Exception'); $this->runSteps(); }
public function testAllFilesFound(CodeGuy $I) { $module = $I->createModuleForIterator(); $actual = $I->getAllFilesFromIteratorByModule($module); $I->seeAllFilesFoundByIterator($actual); }
public function shouldUseCest(CodeGuy $I) { $I->haveFakeClass($scenario = \Codeception\Util\Stub::makeEmptyExcept('Codeception\\Scenario', 'comment')); $I->executeMethod($scenario, 'comment', 'cool, that works!'); $I->seeMethodInvoked($scenario, 'addStep'); }
public function testYell() { $this->yell('Buuuu!'); $this->guy->seeInOutput('Buuuu!'); }
<?php $I = new CodeGuy($scenario); $I->wantTo('drink beer, actually...');
public function testRunYiiApplication(CodeGuy $I) { $I->runPharCommand(); $I->extractPharFile(); $I->seeAllFilesCompiled(); }
public function goodByeWorld(\CodeGuy $I) { $I->executeTestedMethodOn(new $this->class())->seeResultNotEquals('hello world'); }
public function shouldTryWritingShoulds(CodeGuy $I) { $I->seeFeaturesEquals('try writing shoulds'); }
public function testFileHelper(\CodeGuy $I) { $I->seeRightPathConvert(); }
public function goodByeWorld(\CodeGuy $I) { $I->execute(function () { return 2 + 2; })->seeResultNotEquals('3'); }