public function testHandleEvent() { $this->if($adapter = new atoum\test\adapter())->and($adapter->extension_loaded = true)->and($adapter->exec = function ($command) { switch ($command) { case 'git log -1 --pretty=format:\'{"id":"%H","author_name":"%aN","author_email":"%ae","committer_name":"%cN","committer_email":"%ce","message":"%s"}\'': return '{"id":"7282ea7620b45fcba0f9d3bfd484ab146aba2bd0","author_name":"mageekguy","author_email":"*****@*****.**","comitter_name":"mageekguy","comitter_email":"*****@*****.**"}'; case 'git rev-parse --abbrev-ref HEAD': return 'master'; default: return null; } })->and($report = new testedClass($sourceDir = uniqid(), $token = '51bb597d202b4', $adapter))->and($score = new \mock\mageekguy\atoum\score())->and($coverage = new \mock\mageekguy\atoum\score\coverage())->and($writer = new \mock\mageekguy\atoum\writers\http())->and($writer->getMockController()->writeAsynchronousReport = function () use($writer) { return $writer; })->then->when(function () use($report, $writer) { $report->addWriter($writer)->handleEvent(atoum\runner::runStop, new \mageekguy\atoum\runner()); })->mock($writer)->call('writeAsynchronousReport')->withArguments($report)->once()->if($adapter->date = '2013-05-13 10:00:00 +0000')->and($adapter->file_get_contents = '<?php')->and($observable = new \mock\mageekguy\atoum\runner())->and($observable->getMockController()->getScore = $score)->and($score->getMockController()->getCoverage = $coverage)->and($coverage->getMockController()->getClasses = array())->and($filepath = join(DIRECTORY_SEPARATOR, array(__DIR__, 'coveralls', 'resources', '1.json')))->and($report = new testedClass($sourceDir, $token, $adapter))->and($report->addWriter($writer))->then->object($report->handleEvent(atoum\runner::runStop, $observable))->isIdenticalTo($report)->castToString($report)->isEqualToContentsOfFile($filepath)->mock($writer)->call('writeAsynchronousReport')->withArguments($report)->once()->if($coverage->getMockController()->getClasses = array())->and($classController = new mock\controller())->and($classController->disableMethodChecking())->and($classController->__construct = function () { })->and($classController->getName = $className = 'bar')->and($classController->getFileName = $classFile = 'foo/bar.php')->and($classController->getTraits = array())->and($classController->getStartLine = 1)->and($classController->getEndLine = 12)->and($class = new \mock\reflectionClass(uniqid(), $classController))->and($methodController = new mock\controller())->and($methodController->__construct = function () { })->and($methodController->getName = $methodName = 'baz')->and($methodController->isAbstract = false)->and($methodController->getFileName = $classFile)->and($methodController->getDeclaringClass = $class)->and($methodController->getStartLine = 4)->and($methodController->getEndLine = 8)->and($classController->getMethods = array(new \mock\reflectionMethod($className, $methodName, $methodController)))->and($coverage->getMockController()->getClasses = array($className => $classFile, 'foo' => 'bar/foo.php'))->and($xdebugData = array($classFile => array(3 => 1, 4 => 1, 5 => -2, 6 => 0, 7 => -1, 8 => 1, 9 => 1)))->and($filepath = join(DIRECTORY_SEPARATOR, array(__DIR__, 'coveralls', 'resources', '2' . (defined('PHP_WINDOWS_VERSION_MAJOR') === true ? '-windows' : '') . '.json')))->and($coverage->setReflectionClassFactory(function () use($class) { return $class; }))->and($coverage->addXdebugDataForTest($this, $xdebugData))->then->object($report->handleEvent(atoum\runner::runStop, $observable))->isIdenticalTo($report)->castToString($report)->isEqualToContentsOfFile($filepath)->mock($writer)->call('writeAsynchronousReport')->withArguments($report)->twice()->if($finder = function () use(&$branch) { return 'feature'; })->and($report->setBranchFinder($finder))->and($filepath = join(DIRECTORY_SEPARATOR, array(__DIR__, 'coveralls', 'resources', '3' . (defined('PHP_WINDOWS_VERSION_MAJOR') === true ? '-windows' : '') . '.json')))->then->object($report->handleEvent(atoum\runner::runStop, $observable))->isIdenticalTo($report)->castToString($report)->isEqualToContentsOfFile($filepath)->mock($writer)->call('writeAsynchronousReport')->withArguments($report)->thrice()->if($report->setBranchFinder(function () use(&$branch) { return $branch = uniqid(); }))->and($report->handleEvent(atoum\runner::runStop, $observable))->then->castToString($report)->contains('"branch":"' . $branch . '"')->if($report->setBranchFinder(function () { }))->and($report->handleEvent(atoum\runner::runStop, $observable))->then->castToString($report)->notContains('"branch":')->if($report->setBranchFinder(function () { return ''; }))->and($report->handleEvent(atoum\runner::runStop, $observable))->then->castToString($report)->notContains('"branch":'); }
public function testHandleEvent() { $this->if($adapter = new atoum\test\adapter())->if($adapter->extension_loaded = true)->and($report = new testedClass($adapter))->and($score = new \mock\mageekguy\atoum\score())->and($coverage = new \mock\mageekguy\atoum\score\coverage())->and($writer = new \mock\mageekguy\atoum\writers\file())->and($writer->getMockController()->write = $writer)->then->when(function () use($report, $writer) { $report->addWriter($writer)->handleEvent(atoum\runner::runStop, new \mageekguy\atoum\runner()); })->mock($writer)->call('writeAsynchronousReport')->withArguments($report)->once()->and($adapter->time = 762476400)->and($adapter->uniqid = 'foo')->and($observable = new \mock\mageekguy\atoum\runner())->and($observable->getMockController()->getScore = $score)->and($score->getMockController()->getCoverage = $coverage)->and($coverage->getMockController()->getClasses = array())->and($filepath = join(DIRECTORY_SEPARATOR, array(__DIR__, 'clover', 'resources', '1.xml')))->and($report = new testedClass($adapter))->then->object($report->handleEvent(atoum\runner::runStop, $observable))->isIdenticalTo($report)->castToString($report)->isEqualToContentsOfFile($filepath)->if($coverage->getMockController()->getClasses = array())->and($classController = new mock\controller())->and($classController->disableMethodChecking())->and($classController->__construct = function () { })->and($classController->getName = $className = 'bar')->and($classController->getFileName = $classFile = 'foo/bar.php')->and($classController->getTraits = array())->and($classController->getStartLine = 1)->and($classController->getEndLine = 12)->and($class = new \mock\reflectionClass(uniqid(), $classController))->and($methodController = new mock\controller())->and($methodController->__construct = function () { })->and($methodController->getName = $methodName = 'baz')->and($methodController->isAbstract = false)->and($methodController->getFileName = $classFile)->and($methodController->getDeclaringClass = $class)->and($methodController->getStartLine = 4)->and($methodController->getEndLine = 8)->and($classController->getMethods = array(new \mock\reflectionMethod($className, $methodName, $methodController)))->and($coverage->getMockController()->getClasses = array($className => $classFile, 'foo' => 'bar/foo.php'))->and($xdebugData = array($classFile => array(3 => 1, 4 => 1, 5 => 1, 6 => 0, 7 => 1, 8 => 1, 9 => 1)))->and($filepath = join(DIRECTORY_SEPARATOR, array(__DIR__, 'clover', 'resources', '2.xml')))->and($coverage->setReflectionClassFactory(function () use($class) { return $class; }))->and($coverage->addXdebugDataForTest($this, $xdebugData))->then->object($report->handleEvent(atoum\runner::runStop, $observable))->isIdenticalTo($report)->castToString($report)->isEqualToContentsOfFile($filepath); }
public function test__toString() { $this->if($scoreCoverage = new score\coverage())->and($score = new \mock\mageekguy\atoum\runner\score())->and($score->getMockController()->getCoverage = function () use($scoreCoverage) { return $scoreCoverage; })->and($runner = new atoum\runner())->and($runner->setScore($score))->and($defaultField = new tests\coverage\cli())->and($customField = new tests\coverage\cli())->and($customField->setTitlePrompt($titlePrompt = new prompt(uniqid())))->and($customField->setTitleColorizer($titleColorizer = new colorizer(uniqid(), uniqid())))->and($customField->setClassPrompt($classPrompt = new prompt(uniqid())))->and($customField->setMethodPrompt($methodPrompt = new prompt(uniqid())))->and($customField->setCoverageColorizer($coverageColorizer = new colorizer(uniqid(), uniqid())))->and($customField->setLocale($locale = new locale()))->then->castToString($defaultField)->isEmpty()->castToString($customField)->isEmpty()->if($defaultField->handleEvent(atoum\runner::runStart, $runner))->and($customField->handleEvent(atoum\runner::runStart, $runner))->then->castToString($defaultField)->isEmpty()->castToString($customField)->isEmpty()->if($defaultField->handleEvent(atoum\runner::runStop, $runner))->and($customField->handleEvent(atoum\runner::runStop, $runner))->then->castToString($defaultField)->isEmpty()->castToString($customField)->isEmpty()->if($classController = new mock\controller())->and($classController->disableMethodChecking())->and($classController->__construct = function () { })->and($classController->getName = function () use(&$className) { return $className; })->and($classController->getFileName = function () use(&$classFile) { return $classFile; })->and($classController->getTraits = array())->and($classController->getStartLine = 1)->and($classController->getEndLine = 12)->and($class = new \mock\reflectionClass(uniqid(), $classController))->and($methodController = new mock\controller())->and($methodController->__construct = function () { })->and($methodController->isAbstract = false)->and($methodController->getFileName = function () use(&$classFile) { return $classFile; })->and($methodController->getDeclaringClass = $class)->and($methodController->getName = function () use(&$methodName) { return $methodName; })->and($methodController->getStartLine = 6)->and($methodController->getEndLine = 8)->and($classController->getMethods = array(new \mock\reflectionMethod(uniqid(), uniqid(), $methodController)))->and($className = uniqid())->and($methodName = uniqid())->and($scoreCoverage->setReflectionClassFactory(function () use($class) { return $class; }))->and($scoreCoverage->addXdebugDataForTest($this, $xdebugData = array($classFile = uniqid() => array(5 => 1, 6 => 2, 7 => 3, 8 => 2, 9 => 1), uniqid() => array(5 => 2, 6 => 3, 7 => 4, 8 => 3, 9 => 2))))->and($defaultField = new tests\coverage\cli())->and($customField = new tests\coverage\cli())->and($customField->setTitlePrompt($titlePrompt = new prompt(uniqid())))->and($customField->setTitleColorizer($titleColorizer = new colorizer(uniqid(), uniqid())))->and($customField->setClassPrompt($classPrompt = new prompt(uniqid())))->and($customField->setMethodPrompt($methodPrompt = new prompt(uniqid())))->and($customField->setCoverageColorizer($coverageColorizer = new colorizer(uniqid(), uniqid())))->and($customField->setLocale($locale = new locale()))->then->castToString($defaultField)->isEmpty()->castToString($customField)->isEmpty()->if($defaultField->handleEvent(atoum\runner::runStart, $runner))->and($customField->handleEvent(atoum\runner::runStart, $runner))->then->castToString($defaultField)->isEmpty()->castToString($customField)->isEmpty()->if($defaultField->handleEvent(atoum\runner::runStop, $runner))->and($customField->handleEvent(atoum\runner::runStop, $runner))->then->castToString($defaultField)->isEqualTo($defaultField->getTitlePrompt() . sprintf($defaultField->getLocale()->_('Code coverage value: %3.2f%%'), $scoreCoverage->getValue() * 100) . PHP_EOL . $defaultField->getClassPrompt() . sprintf($defaultField->getLocale()->_('Class %s: %3.2f%%'), $className, $scoreCoverage->getValueForClass($className) * 100.0) . PHP_EOL . $defaultField->getMethodPrompt() . sprintf($defaultField->getLocale()->_('%s::%s(): %3.2f%%'), $className, $methodName, $scoreCoverage->getValueForMethod($className, $methodName) * 100.0) . PHP_EOL)->castToString($customField)->isEqualTo($titlePrompt . sprintf($locale->_('%s: %s'), $titleColorizer->colorize($locale->_('Code coverage value')), $coverageColorizer->colorize(sprintf('%3.2f%%', $scoreCoverage->getValue() * 100.0))) . PHP_EOL . $classPrompt . sprintf($locale->_('%s: %s'), $titleColorizer->colorize(sprintf($locale->_('Class %s'), $className)), $coverageColorizer->colorize(sprintf('%3.2f%%', $scoreCoverage->getValueForClass($className) * 100.0))) . PHP_EOL . $methodPrompt . sprintf($locale->_('%s: %s'), $titleColorizer->colorize(sprintf($locale->_('%s::%s()'), $className, $methodName)), $coverageColorizer->colorize(sprintf('%3.2f%%', $scoreCoverage->getValueForClass($className, $methodName) * 100.0))) . PHP_EOL)->if($defaultField->hideMethodsCoverageDetails())->and($defaultField->handleEvent(atoum\runner::runStop, $runner))->then->castToString($defaultField)->isEqualTo($defaultField->getTitlePrompt() . sprintf($defaultField->getLocale()->_('Code coverage value: %3.2f%%'), $scoreCoverage->getValue() * 100) . PHP_EOL . $defaultField->getClassPrompt() . sprintf($defaultField->getLocale()->_('Class %s: %3.2f%%'), $className, $scoreCoverage->getValueForClass($className) * 100.0) . PHP_EOL)->if($defaultField->hideClassesCoverageDetails())->and($defaultField->handleEvent(atoum\runner::runStop, $runner))->then->castToString($defaultField)->isEqualTo($defaultField->getTitlePrompt() . sprintf($defaultField->getLocale()->_('Code coverage value: %3.2f%%'), $scoreCoverage->getValue() * 100) . PHP_EOL)->if($customField->hideClassesCoverageDetails())->and($customField->handleEvent(atoum\runner::runStop, $runner))->then->castToString($customField)->isEqualTo($customField->getTitlePrompt() . sprintf($customField->getLocale()->_('Code coverage value: %3.2f%%'), $scoreCoverage->getValue() * 100) . PHP_EOL); }
public function testGetCoverageForMethod() { $this->if($coverage = new testedClass())->then->array($coverage->getCoverageForClass(uniqid()))->isEmpty()->if($classController = new mock\controller())->and($classController->disableMethodChecking())->and($classController->__construct = function () { })->and($classController->getName = function () use(&$className) { return $className; })->and($classController->getFileName = function () use(&$classFile) { return $classFile; })->and($classController->getTraits = array())->and($classController->getStartLine = 1)->and($classController->getEndLine = 12)->and($class = new \mock\reflectionClass(uniqid(), $classController))->and($methodController = new mock\controller())->and($methodController->__construct = function () { })->and($methodController->getName = function () use(&$methodName) { return $methodName; })->and($methodController->isAbstract = false)->and($methodController->getFileName = function () use(&$classFile) { return $classFile; })->and($methodController->getDeclaringClass = function () use($class) { return $class; })->and($methodController->getStartLine = 4)->and($methodController->getEndLine = 8)->and($classController->getMethods = array(new \mock\reflectionMethod(uniqid(), uniqid(), $methodController)))->and($classFile = uniqid())->and($className = uniqid())->and($methodName = uniqid())->and($xdebugData = array($classFile => array(3 => -2, 4 => 1, 5 => -1, 6 => -1, 7 => -1, 8 => -2, 9 => -1), uniqid() => array(5 => 2, 6 => 3, 7 => 4, 8 => 3, 9 => 2)))->and($expected = array(4 => 1, 5 => -1, 6 => -1, 7 => -1, 8 => -2))->and($coverage = new testedClass())->and($coverage->setReflectionClassFactory(function () use($class) { return $class; }))->and($coverage->addXdebugDataForTest($this, $xdebugData))->then->array($coverage->getCoverageForMethod($className, $methodName))->isEqualTo($expected); }
public function testControl() { $mockAggregatorController = new testedClass(); $mockAggregatorController->__construct = function () { }; $mockAggregatorController->getName = function () { return 'mageekguy\\atoum\\mock\\aggregator'; }; $mockAggregator = new \mock\reflectionClass(uniqid(), $mockAggregatorController); $methods = array(\reflectionMethod::IS_PUBLIC => array(), \reflectionMethod::IS_PROTECTED => array(), \reflectionMethod::IS_PRIVATE => array()); $setMockController = new testedClass(); $setMockController->__construct = function () { }; $setMockController->getName = function () { return 'setMockController'; }; $setMockController->getPrototype = function () use($mockAggregator) { return $mockAggregator; }; $methods[\reflectionMethod::IS_PUBLIC][] = new \mock\reflectionMethod('setMockController'); $getMockController = new testedClass(); $getMockController->__construct = function () { }; $getMockController->getName = function () { return 'getMockController'; }; $getMockController->getPrototype = function () use($mockAggregator) { return $mockAggregator; }; $methods[\reflectionMethod::IS_PUBLIC][] = new \mock\reflectionMethod('getMockController'); $resetMockController = new testedClass(); $resetMockController->__construct = function () { }; $resetMockController->getName = function () { return 'resetMockController'; }; $resetMockController->getPrototype = function () use($mockAggregator) { return $mockAggregator; }; $methods[\reflectionMethod::IS_PUBLIC][] = new \mock\reflectionMethod('resetMockController'); $protectedMethodController = new testedClass(); $protectedMethodController->__construct = function () { }; $protectedMethodController->getName = function () { return 'protected'; }; $protectedMethodController->getPrototype = function () { throw new \exception(); }; $methods[\reflectionMethod::IS_PROTECTED][] = new \mock\reflectionMethod('protectedMethod'); $privateMethodController = new testedClass(); $privateMethodController->__construct = function () { }; $privateMethodController->getName = function () { return 'private'; }; $privateMethodController->getPrototype = function () { throw new \exception(); }; $methods[\reflectionMethod::IS_PRIVATE][] = new \mock\reflectionMethod('privateMethod'); $aMethodController = new testedClass(); $aMethodController->__construct = function () { }; $aMethodController->getName = function () { return 'a'; }; $aMethodController->getPrototype = function () { throw new \exception(); }; $methods[\reflectionMethod::IS_PUBLIC][] = new \mock\reflectionMethod('a'); $bMethodController = new testedClass(); $bMethodController->__construct = function () { }; $bMethodController->getName = function () { return 'b'; }; $bMethodController->getPrototype = function () { throw new \exception(); }; $methods[\reflectionMethod::IS_PUBLIC][] = new \mock\reflectionMethod('b'); $reflectionClassController = new testedClass(); $reflectionClassController->__construct = function () { }; $reflectionClassController->getMethods = function ($modifier) use($methods) { return $methods[$modifier]; }; $reflectionClass = new \mock\reflectionClass(uniqid(), $reflectionClassController); $aMockController = new testedClass(); $aMockController->__construct = function () { }; $aMock = new \mock\reflectionClass(uniqid(), $aMockController); $this->if($mockController = new testedClass(function () use($reflectionClass) { return $reflectionClass; }))->then->variable($mockController->getMockClass())->isNull()->array($mockController->getInvokers())->isEmpty()->array($mockController->getCalls())->isEmpty()->object($mockController->control($aMock))->isIdenticalTo($mockController)->string($mockController->getMockClass())->isEqualTo(get_class($aMock))->array($mockController->getInvokers())->isEqualTo(array('a' => null, 'b' => null))->array($mockController->getCalls())->isEmpty()->if($mock = new \mock\foo())->and($mockController = new testedClass())->and($mockController->controlNextNewMock())->and($mockController->control($mock))->then->variable(testedClass::get())->isNull()->if($mockController = new testedClass())->and($mockController->{$method = uniqid()} = uniqid())->then->exception(function () use($mockController, $aMock) { $mockController->control($aMock); })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Method \'' . get_class($aMock) . '::' . $method . '()\' does not exist')->if($mockController->disableMethodChecking())->and($mockController->{uniqid()} = uniqid())->then->object($mockController->control($aMock))->isIdenticalTo($mockController); }
public function testControl() { $this->if->mockGenerator->shunt('__construct')->and($aMock = new \mock\reflectionClass(uniqid()))->and($mockController = new testedClass())->then->variable($mockController->getMockClass())->isNull()->array($mockController->getInvokers())->isEmpty()->sizeOf($mockController->getCalls())->isZero()->object($mockController->control($aMock))->isIdenticalTo($mockController)->string($mockController->getMockClass())->isEqualTo(get_class($aMock))->array($mockController->getInvokers())->hasSize(sizeof(\mock\reflectionClass::getMockedMethods()))->array($mockController->getMethods())->isEqualTo(\mock\reflectionClass::getMockedMethods())->sizeOf($mockController->getCalls())->isZero()->if($mock = new \mock\foo())->and($mockController = new testedClass())->and($mockController->controlNextNewMock())->and($mockController->control($mock))->then->variable(testedClass::get())->isNull()->if($mockController = new testedClass())->and($mockController->{$method = uniqid()} = uniqid())->then->exception(function () use($mockController, $aMock) { $mockController->control($aMock); })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Method \'' . get_class($aMock) . '::' . $method . '()\' does not exist')->if($mockController->disableMethodChecking())->and($mockController->{uniqid()} = uniqid())->then->object($mockController->control($aMock))->isIdenticalTo($mockController); }