【发布时间】:2016-11-30 16:47:42
【问题描述】:
我开始设置 PHPUnit (v4.8) 以在我的“遗留”代码中使用(它不是那么遗留,但它有不良的编程习惯)。
我的文件夹结构如下
/home
-phpunit.xml
/folder1
/folder2
/folder3
/vendor
/tests
-Test1.php
/includes
-functions.php
/libs
-User.php
-TableClass.php
....
functions.php
<?php
//require_once $_SERVER['DOCUMENT_ROOT'] . "/home/vendor/autoload.php" ;
require_once $_SERVER['DOCUMENT_ROOT'] . "/home/includes/libs/table_classes/User.php" ;
?>
我已经评论了那行,因为我认为作曲家会自动加载它。 问题 1,我是正确的吗? (因为 phpunit 在我的 Test 类中被自动识别...)
Test1.php
<?php
class Test1 extends PHPUnit_Framework_TestCase
{
public function testSomething()
{
// $something = getColNameByStatusId(1);
$this->assertEquals(1,2);
}
}
?>
phpunit.xml
<phpunit bootstrap="includes/functions.php" colors="true">
<testsuite name="Test1" >
<directory>./tests</directory>
</testsuite>
</phpunit>
然后我在命令行中执行phpunit
我的 functions.php 在我的代码中运行良好,当然没有 composer 集成,但是当它加载 phpunit 时它“中断”,我收到以下错误:
Warning: require_once(/home/includes/libs/table_classes/User.php): failed to open stream: No such file or directory in C:\wamp\www\home\includes\functions.php on line 18
我想我缺少 phpunit 的“加载”内容。我的代码既不使用命名空间,也不使用 PSR-0,也不使用 PSR-4。
问题2-在这种情况下如何正确加载文件?
我的目标是加载functions.php,然后它将加载所有其他“表”类来进行我的测试
【问题讨论】:
标签: php unit-testing testing phpunit