Exemple #1
0
 public function test__toString()
 {
     $score = new \mock\mageekguy\atoum\score();
     $scoreController = $score->getMockController();
     $scoreController->getAssertionNumber = 1;
     $scoreController->getFailNumber = 0;
     $scoreController->getErrorNumber = 0;
     $scoreController->getExceptionNumber = 0;
     $runner = new \mock\mageekguy\atoum\runner();
     $runnerController = $runner->getMockController();
     $runnerController->getScore = $score;
     $runnerController->getTestNumber = 1;
     $runnerController->getTestMethodNumber = 1;
     $this->startCase('Success with one test, one method and one assertion, no fail, no error, no exception');
     $this->if($field = new testedClass())->and($field->handleEvent(atoum\runner::runStop, $runner))->then->castToString($field)->isEqualTo("\n                                                   \n                                                    \n                                                    \n                                                    \n                                                    \n\t                                            \n                                                   \n                                          \n                                           \n                                             \n                                             \n                                          \n                                        \n                                        \n                                        \n                                      \n                                    \n            " . PHP_EOL);
     $this->startCase('Failure with several tests, several methods and several assertions, one fail, one error, one exception');
     $scoreController->getFailNumber = 1;
     $scoreController->getErrorNumber = 1;
     $scoreController->getExceptionNumber = 1;
     $scoreController->getUncompletedMethodNumber = 1;
     $this->if($field = new testedClass())->and($field->handleEvent(atoum\runner::runStop, $runner))->then->castToString($field)->isEqualTo("\n                                                   \n                                                    \n                                                    \n                                                    \n                                                    \n                                                    \n                                                    \n                                          \n                                           \n                                             \n                                             \n                                          \n                                        \n                                        \n                                        \n                                      \n                                    \n            " . PHP_EOL);
 }
Exemple #2
0
 public function test__toString()
 {
     $this->if($score = new \mock\mageekguy\atoum\score())->and($score->getMockController()->getTotalMemoryUsage = $totalMemoryUsage = rand(0, PHP_INT_MAX))->and($adapter = new atoum\test\adapter())->and($adapter->class_exists = true)->and($testController = new atoum\mock\controller())->and($testController->getTestedClassName = uniqid())->and($test = new \mock\mageekguy\atoum\test($adapter))->and($test->getMockController()->getScore = $score)->and($defaultField = new test\memory\cli())->and($customField = new test\memory\cli())->and($customField->setPrompt($prompt = new prompt(uniqid())))->and($customField->setTitleColorizer($titleColorizer = new colorizer(uniqid(), uniqid())))->and($customField->setMemoryColorizer($memoryColorizer = new colorizer(uniqid(), uniqid())))->and($customField->setLocale($locale = new locale()))->then->castToString($defaultField)->isEqualTo($defaultField->getPrompt() . $defaultField->getLocale()->_('Memory usage: unknown.') . PHP_EOL)->castToString($customField)->isEqualTo($prompt . sprintf($locale->_('%1$s: %2$s.'), $titleColorizer->colorize($locale->_('Memory usage')), $memoryColorizer->colorize($locale->_('unknown'))) . PHP_EOL)->if($defaultField->handleEvent(atoum\test::runStart, $test))->then->castToString($defaultField)->isEqualTo($defaultField->getPrompt() . $defaultField->getLocale()->_('Memory usage: unknown.') . PHP_EOL)->if($customField->handleEvent(atoum\test::runStart, $test))->then->castToString($customField)->isEqualTo($prompt . sprintf($locale->_('%1$s: %2$s.'), $titleColorizer->colorize($locale->_('Memory usage')), $memoryColorizer->colorize($locale->_('unknown'))) . PHP_EOL)->if($defaultField->handleEvent(atoum\test::runStop, $test))->then->castToString($defaultField)->isEqualTo($defaultField->getPrompt() . sprintf($defaultField->getLocale()->_('Memory usage: %4.2f Mb.'), $totalMemoryUsage / 1048576) . PHP_EOL)->if($customField->handleEvent(atoum\test::runStop, $test))->then->castToString($customField)->isEqualTo($prompt . sprintf($locale->_('%1$s: %2$s.'), $titleColorizer->colorize($locale->_('Memory usage')), $memoryColorizer->colorize(sprintf($locale->_('%4.2f Mb'), $totalMemoryUsage / 1048576))) . PHP_EOL);
 }
Exemple #3
0
 public function test__toString()
 {
     $score = new \mock\mageekguy\atoum\score();
     $scoreController = $score->getMockController();
     $scoreController->getAssertionNumber = 1;
     $scoreController->getFailNumber = 0;
     $scoreController->getErrorNumber = 0;
     $scoreController->getExceptionNumber = 0;
     $runner = new \mock\mageekguy\atoum\runner();
     $runnerController = $runner->getMockController();
     $runnerController->getScore = $score;
     $runnerController->getTestNumber = 1;
     $runnerController->getTestMethodNumber = 1;
     $locale = new \mock\mageekguy\atoum\locale();
     $localeController = $locale->getMockController();
     $localeController->_ = function ($string) use(&$noTestRunningString, &$successString, &$failureString) {
         switch ($string) {
             case 'No test running.':
                 return $noTestRunningString = uniqid();
             case 'Success (%s, %s, %s, %s, %s) !':
                 return $successString = uniqid();
             case 'Failure (%s, %s, %s, %s, %s, %s, %s, %s) !':
                 return $failureString = uniqid();
             default:
                 return uniqid();
         }
     };
     $localeController->__ = function ($singularString, $pluralString, $number) use(&$testString, &$testMethodString, &$assertionString, &$errorString, &$exceptionString) {
         switch ($singularString) {
             case '%s test':
                 return $testString = uniqid();
             case '%s method':
                 return $testMethodString = uniqid();
             case '%s assertion':
                 return $assertionString = uniqid();
             case '%s error':
                 return $errorString = uniqid();
             case '%s exception':
                 return $exceptionString = uniqid();
             default:
                 return uniqid();
         }
     };
     $prompt = new \mock\mageekguy\atoum\cli\prompt();
     $promptController = $prompt->getMockController();
     $promptController->__toString = $promptString = uniqid();
     $successColorizer = new \mock\mageekguy\atoum\cli\colorizer();
     $successColorizerController = $successColorizer->getMockController();
     $successColorizerController->colorize = $colorizedSuccessString = uniqid();
     $failureColorizer = new \mock\mageekguy\atoum\cli\colorizer();
     $failureColorizerController = $failureColorizer->getMockController();
     $failureColorizerController->colorize = $colorizedFailureString = uniqid();
     $this->startCase('Success with one test, one method and one assertion, no fail, no error, no exception');
     $this->if($field = new runner\result\cli())->and($field->setPrompt($prompt))->and($field->setSuccessColorizer($successColorizer))->and($field->setFailureColorizer($failureColorizer))->and($field->setLocale($locale))->then->castToString($field)->isEqualTo($promptString . $noTestRunningString . PHP_EOL)->mock($locale)->call('_')->withArguments('No test running.')->once()->mock($successColorizer)->call('colorize')->withArguments($noTestRunningString)->never()->mock($failureColorizer)->call('colorize')->never()->mock($prompt)->call('__toString')->once()->if($locale->getMockController()->resetCalls())->and($prompt->getMockController()->resetCalls())->and($field->handleEvent(atoum\runner::runStart, $runner))->then->castToString($field)->isEqualTo($promptString . $noTestRunningString . PHP_EOL)->mock($locale)->call('_')->withArguments('No test running.')->once()->mock($successColorizer)->call('colorize')->withArguments($noTestRunningString)->never()->mock($failureColorizer)->call('colorize')->never()->mock($prompt)->call('__toString')->once()->if($locale->getMockController()->resetCalls())->and($prompt->getMockController()->resetCalls())->and($field->handleEvent(atoum\runner::runStop, $runner))->then->castToString($field)->isEqualTo($promptString . $colorizedSuccessString . PHP_EOL)->mock($locale)->call('__')->withArguments('%s test', '%s tests', 1)->once()->call('__')->withArguments('%s/%s method', '%s/%s methods', 1)->once()->call('__')->withArguments('%s skipped method', '%s skipped methods', 0)->once()->call('__')->withArguments('%s assertion', '%s assertions', 1)->once()->call('_')->withArguments('Success (%s, %s, %s, %s, %s) !')->once()->mock($successColorizer)->call('colorize')->withArguments($noTestRunningString)->never()->call('colorize')->withArguments($successString)->once()->mock($failureColorizer)->call('colorize')->never()->mock($prompt)->call('__toString')->once();
     $this->startCase('Success with several tests, several methods and several assertions,  no fail, no error, no exception');
     $runnerController->getTestNumber = $testNumber = rand(2, PHP_INT_MAX);
     $runnerController->getTestMethodNumber = $testMethodNumber = rand(2, PHP_INT_MAX);
     $scoreController->getAssertionNumber = $assertionNumber = rand(2, PHP_INT_MAX);
     $this->if($field = new runner\result\cli())->and($field->setPrompt($prompt))->and($field->setSuccessColorizer($successColorizer))->and($field->setFailureColorizer($failureColorizer))->and($field->setLocale($locale))->then->castToString($field)->isEqualTo($promptString . $noTestRunningString . PHP_EOL)->mock($locale)->call('_')->withArguments('No test running.')->once()->mock($successColorizer)->call('colorize')->withArguments($noTestRunningString)->never()->mock($failureColorizer)->call('colorize')->never()->mock($prompt)->call('__toString')->once()->if($locale->getMockController()->resetCalls())->and($prompt->getMockController()->resetCalls())->and($field->handleEvent(atoum\runner::runStart, $runner))->then->castToString($field)->isEqualTo($promptString . $noTestRunningString . PHP_EOL)->mock($locale)->call('_')->withArguments('No test running.')->once()->mock($successColorizer)->call('colorize')->withArguments($noTestRunningString)->never()->mock($failureColorizer)->call('colorize')->never()->mock($prompt)->call('__toString')->once()->if($locale->getMockController()->resetCalls())->and($prompt->getMockController()->resetCalls())->and($field->handleEvent(atoum\runner::runStop, $runner))->castToString($field)->isEqualTo($promptString . $colorizedSuccessString . PHP_EOL)->mock($locale)->call('__')->withArguments('%s test', '%s tests', $testNumber)->once()->call('__')->withArguments('%s/%s method', '%s/%s methods', $testMethodNumber)->once()->call('__')->withArguments('%s skipped method', '%s skipped methods', 0)->once()->call('__')->withArguments('%s assertion', '%s assertions', $assertionNumber)->once()->call('_')->withArguments('Success (%s, %s, %s, %s, %s) !')->once()->mock($successColorizer)->call('colorize')->withArguments($noTestRunningString)->never()->call('colorize')->withArguments($successString)->once()->mock($failureColorizer)->call('colorize')->never()->mock($prompt)->call('__toString')->once();
     $this->startCase('Failure with several tests, several methods and several assertions, one fail, one error, one exception');
     $scoreController->getFailNumber = 1;
     $scoreController->getErrorNumber = 1;
     $scoreController->getExceptionNumber = 1;
     $scoreController->getUncompletedMethodNumber = 1;
     $this->if($field = new runner\result\cli())->and($field->setPrompt($prompt))->and($field->setSuccessColorizer($successColorizer))->and($field->setFailureColorizer($failureColorizer))->and($field->setLocale($locale))->then->castToString($field)->isEqualTo($promptString . $noTestRunningString . PHP_EOL)->mock($locale)->call('_')->withArguments('No test running.')->once()->mock($successColorizer)->call('colorize')->withArguments($noTestRunningString)->never()->mock($failureColorizer)->call('colorize')->never()->mock($prompt)->call('__toString')->once()->if($locale->getMockController()->resetCalls())->and($prompt->getMockController()->resetCalls())->and($field->handleEvent(atoum\runner::runStart, $runner))->then->castToString($field)->isEqualTo($promptString . $noTestRunningString . PHP_EOL)->mock($locale)->call('_')->withArguments('No test running.')->once()->mock($successColorizer)->call('colorize')->withArguments($noTestRunningString)->never()->mock($failureColorizer)->call('colorize')->never()->mock($prompt)->call('__toString')->once()->if($locale->getMockController()->resetCalls())->and($prompt->getMockController()->resetCalls())->and($field->handleEvent(atoum\runner::runStop, $runner))->then->castToString($field)->isEqualTo($promptString . $colorizedFailureString . PHP_EOL)->mock($locale)->call('__')->withArguments('%s test', '%s tests', $testNumber)->once()->call('__')->withArguments('%s/%s method', '%s/%s methods', $testMethodNumber)->once()->call('__')->withArguments('%s skipped method', '%s skipped methods', 0)->once()->call('__')->withArguments('%s uncompleted method', '%s uncompleted methods', 1)->once()->call('__')->withArguments('%s failure', '%s failures', 1)->once()->call('__')->withArguments('%s error', '%s errors', 1)->once()->call('__')->withArguments('%s exception', '%s exceptions', 1)->once()->call('_')->withArguments('Failure (%s, %s, %s, %s, %s, %s, %s, %s) !')->once()->mock($failureColorizer)->call('colorize')->withArguments($noTestRunningString)->never()->call('colorize')->withArguments($failureString)->once()->mock($successColorizer)->call('colorize')->never()->mock($prompt)->call('__toString')->once();
     $this->startCase('Failure with several tests, several methods and several assertions, several fails, several errors, several exceptions');
     $scoreController->getFailNumber = $failNumber = rand(2, PHP_INT_MAX);
     $scoreController->getErrorNumber = $errorNumber = rand(2, PHP_INT_MAX);
     $scoreController->getExceptionNumber = $exceptionNumber = rand(2, PHP_INT_MAX);
     $scoreController->getUncompletedMethodNumber = $uncompletedTestNumber = rand(2, PHP_INT_MAX);
     $this->if($field = new runner\result\cli())->and($field->setPrompt($prompt))->and($field->setSuccessColorizer($successColorizer))->and($field->setFailureColorizer($failureColorizer))->and($field->setLocale($locale))->then->castToString($field)->isEqualTo($promptString . $noTestRunningString . PHP_EOL)->mock($locale)->call('_')->withArguments('No test running.')->once()->mock($successColorizer)->call('colorize')->withArguments($noTestRunningString)->never()->mock($failureColorizer)->call('colorize')->never()->mock($prompt)->call('__toString')->once()->if($locale->getMockController()->resetCalls())->and($prompt->getMockController()->resetCalls())->and($field->handleEvent(atoum\runner::runStart, $runner))->then->castToString($field)->isEqualTo($promptString . $noTestRunningString . PHP_EOL)->mock($locale)->call('_')->withArguments('No test running.')->once()->mock($successColorizer)->call('colorize')->withArguments($noTestRunningString)->never()->mock($failureColorizer)->call('colorize')->never()->mock($prompt)->call('__toString')->once()->if($locale->getMockController()->resetCalls())->and($prompt->getMockController()->resetCalls())->and($field->handleEvent(atoum\runner::runStop, $runner))->then->castToString($field)->isEqualTo($promptString . $colorizedFailureString . PHP_EOL)->mock($locale)->call('__')->withArguments('%s test', '%s tests', $testNumber)->once()->call('__')->withArguments('%s/%s method', '%s/%s methods', $testMethodNumber)->once()->call('__')->withArguments('%s failure', '%s failures', $failNumber)->once()->call('__')->withArguments('%s error', '%s errors', $errorNumber)->once()->call('__')->withArguments('%s exception', '%s exceptions', $exceptionNumber)->once()->call('_')->withArguments('Failure (%s, %s, %s, %s, %s, %s, %s, %s) !')->once()->mock($failureColorizer)->call('colorize')->withArguments($noTestRunningString)->never()->call('colorize')->withArguments($failureString)->once()->mock($successColorizer)->call('colorize')->never()->mock($prompt)->call('__toString')->once();
 }
Exemple #4
0
 public function testReset()
 {
     $this->given($mockController = new \mock\mageekguy\atoum\mock\controller(), $asserter = $this->newTestedInstance)->then->object($asserter->reset())->isIdenticalTo($asserter)->variable($asserter->getAdapter())->isNull()->if($asserter->setWith($mock = new \mock\mageekguy\atoum\score()), $mock->setMockController($mockController), $this->resetMock($mockController))->then->object($asserter->reset())->isIdenticalTo($asserter)->object($asserter->getAdapter())->isIdenticalTo($mock->getMockController())->mock($mockController)->call('resetCalls')->once();
 }
Exemple #5
0
 public function testReset()
 {
     $this->if($mockController = new \mock\mageekguy\atoum\mock\controller())->and($asserter = new sut($generator = new asserter\generator()))->then->variable($asserter->getAdapter())->isNull()->object($asserter->reset())->isIdenticalTo($asserter)->variable($asserter->getAdapter())->isNull()->if($asserter->setWith($mock = new \mock\mageekguy\atoum\score()))->and($mock->setMockController($mockController))->and($this->resetMock($mockController))->then->object($asserter->getAdapter())->isIdenticalTo($mock->getMockController())->object($asserter->reset())->isIdenticalTo($asserter)->object($asserter->getAdapter())->isIdenticalTo($mock->getMockController())->mock($mockController)->call('resetCalls')->once();
 }