我使用以下代码关注Getting Started with PHPUnit:
测试\ MoneyTest.php
<?php
class MoneyTest extends PHPUnit_Framework_TestCase
{
// ...
public function testCanBeNegated()
{
// Arrange
$a = new Money(1);
// Act
$b = $a->negate();
// Assert
$this->assertEquals(-1, $b->getAmount());
}
// ...
}
SRC \ Money.php
{{{
<?php
class Money
{
private $amount;
public function __construct($amount)
{
$this->amount = $amount;
}
public function getAmount()
{
return $this->amount;
}
public function negate()
{
return new Money(-1 * $this->amount);
}
// ...
}
}}}
当我运行phpunit tests/MoneyTest
时,我收到以下消息:
PHPUnit 4.8.26 by Sebastian Bergmann and contributors.
E
Time: 56 ms, Memory: 4.00MB
There was 1 error:
1) MoneyTest::testCanBeNegated
Error: Class 'Money' not found
/srv/www/wordpress-default/wp-content/plugins/x-helloworld/tests/MoneyTest.php:10
FAILURES!
Tests: 1, Assertions: 0, Errors: 1.
vagrant@vvv:/srv/www/wordpress-default/wp-content/plugins/x-helloworld$
如何将.. \ src中的类文件识别为测试test \ MoneyTest.php中的引用?
更新
列出版本和操作系统:
php --version
PHP 7.0.8-3+deb.sury.org~trusty+1 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.8-3+deb.sury.org~trusty+1, Copyright (c) 1999-2016, by Zend Technologies
phpunit --version
PHPUnit 4.8.26 by Sebastian Bergmann and contributors.