Netbeans 8.2中的PHPUnit插件给出致命错误:尝试运行测试用例时找不到类'PHPUnit_Framework_TestSuite'

问题描述 投票:0回答:1

当我尝试在Netbeans中运行PHPUnit时,我遇到了这个错误:

Fatal error: Class 'PHPUnit_Framework_TestSuite' not found in C:\Users\julian\AppData\Roaming\NetBeans\8.2\phpunit\NetBeansSuite.php on line 63
Done.

这在Netbeans和CLI中都会发生。


我开始通过导航到这个目录来调试这个问题:C:\Users\julian\AppData\Roaming\NetBeans\8.2\phpunit\

该目录包含一个文件:NetBeansSuite.php。我打开它寻找线索,并看到这一行:

class NetBeansSuite extends PHPUnit_Framework_TestSuite {

我没看到的是任何具体的PHPUnit_Framework_TestSuite课程。

接下来是NetBeansSuite.php文件没有任何includerequire语言结构,可能包括PHPUnit_Framework_TestSuite类。

因此,为了解决致命错误问题,我应该在PHPUnit_Framework_TestSuite中包含NetbeansSuite.php

这是一个问题,因为我不是NetbeansSuite.php的作者。最重要的是,NetbeansSuite.php的作者在评论部分写了这篇文章:

 <b>WARNING: User changes to this file should be avoided.</b>

我在评论中进一步阅读:

 * Copyright 2010 Oracle and/or its affiliates. All rights reserved.

我想NetbeansSuite.php文件已经过时了。


在网上搜索带我到这个stackoverflow问题:

Why, Fatal error: Class 'PHPUnit_Framework_TestCase' not found in ...?

他们声称使用命名空间版本的PHPUnit_Framework_TestCase可以解决问题。所以我做了他们写的。

我固执地改变了NetBeansSuite.php。旧代码:

class NetBeansSuite extends PHPUnit_Framework_TestSuite {

新代码:

require_once 'PHPUnit/Autoload.php';

use PHPUnit\Framework\TestCase;

class NetBeansSuite extends TestCase {

我试图再次运行测试用例,这是不幸的结果:

Fatal error: Declaration of CalculatorTest::setUp() must be compatible with PHPUnit\Framework\TestCase::setUp(): void in C:\wamp64\www\test\CalculatorTest.php on line 97

换句话说,它给了我一个新问题。

我的系统:

Windows 10
WAMP
php 7.2.14
PHPUnit 8.0.6
Netbeans version 8.2 (Netbeans PHPUnit plugin installed through Tools > Plugins. Version: 0.26.2)

我的问题是:有没有人知道NetBeansSuite.php文件应该如何与上述系统一样?


The setUp method in my test case:
protected function setUp()
{
    $this->object = new Calculator;
}


Update: The Skeleton Generator project is abandoned. See link: https://github.com/sebastianbergmann/phpunit-skeleton-generator So in order to fix the Declaration of CalculatorTest::setUp() must be compatible with PHPUnit\Framework\TestCase::setUp() error the corresponding return type declaration should be used in the test case.
// I added : void
protected function setUp(): void
{
    $this->object = new Calculator;
}

// : void needs to be added in the tearDown method as well
protected function tearDown(): void

不幸的是,这给了我新的问题:

Warning: require_once(PHPUnit/Autoload.php): failed to open stream: No such file or directory in C:\wamp64\www\test\CalculatorTest.php on line 4

Fatal error: require_once(): Failed opening required 'PHPUnit/Autoload.php' (include_path='.;C:\php\pear') in C:\wamp64\www\test\CalculatorTest.php on line 4

我通过手动安装PEAR并在C:\php\PEAR中创建一个新的“PHPUnit”目录来解决这个问题。然后我创建了一个新的Autoload.php文件。我用Autoload.phpPSR-4示例文件填充了https://www.php-fig.org/psr/psr-4/的内容。

这解决了Autoload问题,但是在执行测试用例期间我遇到了一个新问题。

C:\wamp64\www\test>phpunit CalculatorTest.php
PHPUnit 8.0.6 by Sebastian Bergmann and contributors.



Time: 170 ms, Memory: 10.00 MB

No tests executed!

它显示No tests executed!但我有5个测试。我会为此提出一个新问题。这是:PHPUnit 8 installed on Windows through PHAR shows No tests are executed

php phpunit netbeans-8 netbeans-plugins phpunit-testing
1个回答
1
投票

最初确实应该更新您的命名空间,因为它已在更新版本的PHPUnit中更改。

但是,该错误表明您的CalculatorTest::setUp()方法与PHPUnit版本不兼容。你可以在这里发布这种方法吗?

© www.soinside.com 2019 - 2024. All rights reserved.