PHPUnit在IDE中工作,但是服务器说找不到类

时间:2017-08-09 08:10:00

标签: phpunit phpstorm

我在PhpStorm中使用Symfony3插件。我的PHP解释器是7.0.18。我在PhpStorm中通过在项目的根目录中包含.phar文件来配置PHPUnit 6.3.0。

单元测试工作就像IDE中的一个魅力,但是在服务器上执行任何操作(如bin/console server:start)会触发以下消息:

  

PHP致命错误:类' PHPUnit \ Framework \ TestCase'找不到   第13行上的/1tb/programming/PhpstormProjects/binary_search/src/AppBundle/Search/BinarySearchTest.php
  PHP致命错误:Class' PHPUnit \ Framework \ TestCase'找不到   /1tb/programming/PhpstormProjects/binary_search/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Tests/TestCase.php   第17行

BinarySearchTest.php:

 <?php

namespace AppBundle\Search;

use PHPUnit\Framework\TestCase;

class BinarySearchTest extends TestCase
{

}

TestCase.php:

<?php

namespace Symfony\Bundle\FrameworkBundle\Tests;

use PHPUnit\Framework\TestCase as PHPUnitTestCase;

class TestCase extends PHPUnitTestCase
{

}

我读过很多类似问题的帖子,但没有一个像我一样描述问题。然后我尝试在文件夹的根目录中运行带有phpunit .的PHPUnit,并显示以下错误:

  

PHP致命错误:Class&#39; Doctrine \ Tests \ Common \ Cache \ CacheTest&#39;不   在发现   /1tb/programming/PhpstormProjects/binary_search/vendor/doctrine/cache/tests/Doctrine/Tests/Common/Cache/ApcCacheTest.php   在第10行

无论我做什么,我都会遇到更多错误。我刚刚开始使用Symfony并阅读了一些文档,但是我无法控制这个东西,我已经有两天了。对我有什么建议吗?

2 个答案:

答案 0 :(得分:0)

  

我的PHPUnit 6.3.0已配置... 将.phar文件放在项目的根目录中

这么糟糕的主意。 PHPUnit should not be installed on your (production?) server

如果这是您尝试测试的本地登台服务器,then you need to install the phar in the path

全局安装PHAR:

$ wget https://phar.phpunit.de/phpunit-6.2.phar
$ chmod +x phpunit-6.2.phar
$ sudo mv phpunit-6.2.phar /usr/local/bin/phpunit
$ phpunit --version

另外,请考虑将PHP升级到最新版本。您正在使用的漏洞存在多个漏洞。 (见:change log for versions between yours and current)。

编辑:

为什么在服务器上运行bin/console server:startAlso not meant to be on a production server

我的猜测是,它正在查看文档根目录中的phar并尝试执行它,这就是造成所有错误的原因。

答案 1 :(得分:0)

通过composer安装PHPUnit工作。事实证明我的作曲家安装在某种程度上出错了。在成功安装composer之后,我让它处理安装PHPUnit。之后它才起作用。测试在IDE中运行良好,服务器再次响应。谢谢LazyOne。

相关问题