微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Codecept没有显示任何php单元测试结果

如何解决Codecept没有显示任何php单元测试结果

我是 PHP 和 codecept 的新手,一直在学习教程,但是当我尝试运行一个简单的单元测试时,我没有得到任何测试结果。

我的项目结构如下:

enter image description here

类的代码是:

Config.PHP

<?PHP
//Have we already been here?
if (!defined('DB_HOST')) {
 
    // Define DB Params
    define("DB_HOST","localhost");
    define("DB_USER","root");
    define("DB_PASS","");
    define("DB_NAME","philter");
    
    // Define URL
    define("ROOT_URL","http://bit703.module2/");
 
    // Add some helpful filepath constants
    define('APP_ROOT',dirname(realpath(__FILE__)) . '/');
    define('VIEW_ROOT',APP_ROOT . 'Views/');
 
    // Tell this sytem we are in a development environment
    define('DEV_ENV',true);
}

Utils.PHP

<?PHP
 
/* 
 * spl_autoload_register() allows you to register multiple functions 
 * (or static methods from your own Autoload class) 
 * that PHP will put into a stack/queue and call sequentially 
 * when a "new Class" is declared. 
 */
spl_autoload_register(function ($class) {
 
    /*
     *  Project-specific namespace prefix
     */
    $prefix = 'BIT703\\';
  
    /*
     *  Does the class use the namespace prefix?
     */
    $len = strlen($prefix);
    if (strncmp($prefix,$class,$len) !== 0) {
        // no,move to the next registered autoloader
        return;
    }
  
    /*
     *  Get the relative class name
     */
    $relative_class = substr($class,$len);
    print("<pre>".print_r($relative_class,1)."</pre>");
  
    /*
     *  Replace the namespace prefix with the base directory,replace namespace
     *  separators with directory separators in the relative class name,append
     *  with .PHP
     */
    $file = APP_ROOT . str_replace('\\','/',$relative_class) . '.PHP';
    print("<pre>".print_r($file,1)."</pre>");
  
    die();
    
    /*
     *  if the file exists,require it
     */
    if (file_exists($file)) {
        require $file;
    }
  });
  $router = new \BIT703\Classes\Router();

Bootstrap.PHP

<?PHP

require  'config.PHP';
require 'utils.PHP';

RouterTest.PHP

<?PHP
require(dirname(__FILE__).'/../../src/App/bootstrap.PHP');

use \BIT703\Classes\Router as Router;

class RouterTest extends \Codeception\Test\Unit
{
    /**
     * @var \UnitTester
     */
    protected $tester;
    
    protected function _before()
    {
    }

    protected function _after()
    {
    }

    // tests
    public function testSomeFeature()
    {
        $this->assertInstanceOf('\BIT703\Classes\Router',$this->router);
    }

}

这是我运行测试时得到的输出

$ PHP vendor/bin/codecept run unit RouterTest
Codeception PHP Testing Framework v4.1.18
Powered by PHPUnit 9.5.4 by Sebastian Bergmann and contributors.
<pre>Classes\Router</pre>. 
<pre>/Applications/MAMP/htdocs/bit703/module2/src/App/Classes/Router.PHP</pre>

如果我注释掉“require 'utils.PHP';”从 bootstrap.utils,然后我收到一条正确的测试失败消息,但是一旦包含它,它就会停止工作。

谁能看出我错在哪里?

解决方法

我看到您创建了默认的 Codeception 目录结构,其中包含单元、功能和验收目录。

测试文件必须放在这些目录之一,所以将 RouterTest.php 文件移动到单元目录。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?