【问题标题】:I keep getting this error when I try input phpunit当我尝试输入 phpunit 时,我不断收到此错误
【发布时间】:2016-05-05 21:57:48
【问题描述】:

当我尝试使用 phpunit 时,我在 phpStorm 的命令行中不断收到此错误。谁可以给我解释一下这个?我是phpunit的新手。

C:\xampp\php\phpunit.bat

警告:PHPUnit_TextUI_TestRunner::doRun() 缺少参数 3, 在第 176 行调用 C:\xampp\php\pear\PHPUnit\TextUI\Command.php 和 定义在 C:\xampp\htdocs\tutorials\php_unit_testing\vendor\phpunit\phpunit\src\TextUI\TestRunner.php 在第 148 行

Sebastian Bergmann 和贡献者的 PHPUnit 5.3-dev。

致命错误:在 'controllers\core\web\Pages' 中找不到类 C:\xampp\htdocs\tutorials\php_unit_testing\tests\app\controllers\core\web\PagesTest.php 在第 6 行

进程在 22:23:20 以退出代码 255 结束。执行时间:186 女士。

这是我的 xml 文件中的代码:

<?xml version='1.0' encoding='UTF-8' ?>

<phpunit bootstrap="./vendor/autoload.php"
     color="true"
     convertErrorsToExceptions="true"
     convertNoticesToExceptions="true"
     convertWarningsToExceptions="true"
     stopOnFailures="false"
     syntaxCheck="false"
    >
<testsuites>
        <testsuite name="Tutorial Unit Tests">
            <directory>./tests/</directory>
        </testsuite>
</testsuites>
</phpunit>

这是 pages.php 中的代码:

<?php


 namespace controllers\core\web;

 class Pages{
 public function rendor(){
    return 'Hello World';
 }

 public function return_true(){
    return true;
 }
 public function return_array(){
    return array('Hello', 'world', 'This', 'is', 'an', 'array');
 }
 }
 ?>

这是来自 PagesTest.php 的代码:

<?php
class PagesTest extends PHPUnit_Framework_TestCase
{ 
public function testRenderReturnsHelloWorld(){ 

    $pages = new \controllers\core\web\Pages();

    $expected = 'Hello Word'; 

    $this->assertEquals($expected, $pages->rendor());

}
}
?>

【问题讨论】:

    标签: php phpunit phpstorm


    【解决方案1】:

    经过大量研究,我找到了丢失课程的解决方案。我添加require_once 'app/controllers/core/web/pages.php'; 以要求我将类与命名空间一起存储的页面。这对我有用,我希望它适用于遇到此问题的其他任何人。在我制作的自动加载器文件中,我现在有了这段代码

    <?php
    require_once 'app/controllers/core/web/pages.php';
    $loader = require_once __DIR__ . '/vendor/autoload.php';
    

    我一直没弄明白有关的部分

    警告:PHPUnit_TextUI_TestRunner::doRun() 缺少参数 3,在第 176 行的 C:\xampp\php\pear\PHPUnit\TextUI\Command.php 中调用并在 C:\xampp\htdocs\tutorials\php_unit_testing 中定义\vendor\phpunit\phpunit\src\TextUI\TestRunner.php 在第 148 行

    如果有人知道这一点,请告诉我。

    【讨论】:

      【解决方案2】:

      您似乎没有在库中加载。通常,您必须创建一个备用 autoload.php 文件并将其包含在 phpunit bootsrap 值中。所以它会是这样的:

      &lt;phpunit bootstrap="./autoload.php" ...

        #./auotload.php
        $loader = require_once __DIR__ . '/vendor/autoload.php';
        $loader.add('directory_of_code', 'path/to/that/directory');
      
        return $loader;
      

      【讨论】:

      • 你能举个例子吗?你会在 $loader->add() 中写什么。代码目录是什么意思?
      • 从你上面的命名空间我认为它可能类似于$loader.add('controller', 'src/');
      • 作曲家文档有点垃圾,但它们使您尝试使用 autoload 的加载器;
      猜你喜欢
      • 1970-01-01
      • 2014-05-03
      • 1970-01-01
      • 1970-01-01
      • 2019-07-01
      • 1970-01-01
      • 2020-05-15
      • 1970-01-01
      • 2020-11-12
      相关资源
      最近更新 更多