ランニング
phpunit --bootstrap tests/bootstrap.php tests/ExampleTest.php
動作するが実行中
phpunit --bootstrap tests/bootstrap.php --coverage-html /tmp/report tests/ExampleTest.php
ではない
何か案は?
失敗メッセージ
phpunit --bootstrap tests/bootstrap.php --coverage-html /tmp/report tests/ExampleTest.php
PHPUnit 3.7.10 by Sebastian Bergmann.
PHP Fatal error: examplePhpRepositoryAutoLoader(): Failed opening required 'Example.php' (include_path='.:/usr/share/php:/usr/share/pear') in /home/dmakin/workspace/example-php-repository/classes/__autoloader__.php on line 15
PHP Stack trace:
PHP 1. {main}() /usr/bin/phpunit:0
PHP 2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:46
PHP 3. PHPUnit_TextUI_Command->run() /usr/share/php/PHPUnit/TextUI/Command.php:129
PHP 4. PHPUnit_TextUI_TestRunner->doRun() /usr/share/php/PHPUnit/TextUI/Command.php:176
PHP 5. PHPUnit_Framework_TestSuite->run() /usr/share/php/PHPUnit/TextUI/TestRunner.php:346
PHP 6. PHPUnit_Framework_TestSuite->runTest() /usr/share/php/PHPUnit/Framework/TestSuite.php:745
PHP 7. PHPUnit_Framework_TestCase->run() /usr/share/php/PHPUnit/Framework/TestSuite.php:775
PHP 8. PHPUnit_Framework_TestResult->run() /usr/share/php/PHPUnit/Framework/TestCase.php:769
PHP 9. PHP_CodeCoverage->stop() /usr/share/php/PHPUnit/Framework/TestResult.php:677
PHP 10. PHP_CodeCoverage->append() /usr/share/php/PHP/CodeCoverage.php:253
PHP 11. PHP_CodeCoverage->applyCoversAnnotationFilter() /usr/share/php/PHP/CodeCoverage.php:285
PHP 12. PHP_CodeCoverage->getLinesToBeCovered() /usr/share/php/PHP/CodeCoverage.php:447
PHP 13. PHP_CodeCoverage->resolveCoversToReflectionObjects() /usr/share/php/PHP/CodeCoverage.php:655
PHP 14. class_exists() /usr/share/php/PHP/CodeCoverage.php:742
PHP 15. examplePhpRepositoryAutoLoader() /usr/share/php/PHP/CodeCoverage.php:0
tests //bootstrap.php
require_once __DIR__.'/../classes/__autoloader__.php';
spl_autoload_register('examplePhpRepositoryAutoLoader');
classes/__autoloader__.php
https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.mdのサンプル PSR0 から取得したオートローダー
function examplePhpRepositoryAutoLoader($className)
{
$className = ltrim($className, '\\');
$fileName = '';
$namespace = '';
if ($lastNsPos = strrpos($className, '\\')) {
$namespace = substr($className, 0, $lastNsPos);
$className = substr($className, $lastNsPos + 1);
$fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
}
$fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
require_once $fileName;
}
spl_autoload_register('examplePhpRepositoryAutoLoader');
tests\ExampleTest.php
/**
* Generated by PHPUnit_SkeletonGenerator on 2012-12-13 at 15:40:40.
*/
class ExampleTest extends PHPUnit_Framework_TestCase
{
/**
* @var example
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$this->object = new examplePhpRepository\Example();
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
/**
* @test
* @covers Example::setIntNumberOne
*/
public function testSetIntNumberOne()
{
$this->assertNull($this->object->intNumberOne);
$this->object->setIntNumberOne(1);
$this->assertEquals(1, $this->object->intNumberOne);
}
}
examplePhpRepository\Example.php
<?php
/**
* Example class
*/
namespace examplePhpRepository;
class Example
{
public $intNumberOne;
/**
* Class constructor
*/
public function __construct()
{
}
public function setIntNumberOne($newValue)
{
$this->intNumberOne = $newValue;
}
}
修理済み
問題は、tests/ExampleTest.php のコメントにありました。名前空間を追加する必要がありました。
動作していません
/**
* @test
* @covers Example::setIntNumberOne
*/
働く
/**
* @test
* @covers examplePhpRepository\Example::setIntNumberOne
*/