PHPUnit 在 IDE 中工作,但服务器说找不到类 [英] PHPUnit working in IDE, but server says class not found

查看:13
本文介绍了PHPUnit 在 IDE 中工作,但服务器说找不到类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using the Symfony3 plugin in PhpStorm. My PHP Interpreter is 7.0.18. I have PHPUnit 6.3.0 configured in PhpStorm by having the .phar file in the root directory of my project.

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

Unit test work like a charm inside the IDE however performing any operation on the server (like bin/console server:start) triggers the following messages:

PHP 致命错误:在中找不到类 'PHPUnitFrameworkTestCase'/1tb/programming/PhpstormProjects/binary_search/src/AppBundle/Search/BinarySearchTest.php 第 13 行
PHP 致命错误:在中找不到类 'PHPUnitFrameworkTestCase'/1tb/programming/PhpstormProjects/binary_search/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Tests/TestCase.php第 17 行

PHP Fatal error: Class 'PHPUnitFrameworkTestCase' not found in /1tb/programming/PhpstormProjects/binary_search/src/AppBundle/Search/BinarySearchTest.php on line 13
PHP Fatal error: Class 'PHPUnitFrameworkTestCase' not found in /1tb/programming/PhpstormProjects/binary_search/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Tests/TestCase.php on line 17

BinarySearchTest.php:

 <?php

namespace AppBundleSearch;

use PHPUnitFrameworkTestCase;

class BinarySearchTest extends TestCase
{

}

TestCase.php:

<?php

namespace SymfonyBundleFrameworkBundleTests;

use PHPUnitFrameworkTestCase as PHPUnitTestCase;

class TestCase extends PHPUnitTestCase
{

}

我已经阅读了许多类似问题的帖子,但没有一篇文章以我的方式描述问题.然后我尝试在文件夹的根目录中使用 phpunit . 运行 PHPUnit,但出现此错误:

I have read many posts with problems similar but none of them describe the problem the way I do. Then I tried running PHPUnit with phpunit . in the root directory of the folder with this error:

PHP 致命错误:类 'DoctrineTestsCommonCacheCacheTest' 不是在发现/1tb/programming/PhpstormProjects/binary_search/vendor/doctrine/cache/tests/Doctrine/Tests/Common/Cache/ApcCacheTest.php在第 10 行

PHP Fatal error: Class 'DoctrineTestsCommonCacheCacheTest' not found in /1tb/programming/PhpstormProjects/binary_search/vendor/doctrine/cache/tests/Doctrine/Tests/Common/Cache/ApcCacheTest.php on line 10

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

It seems whatever I do I just run into more errors. I only just got started with Symfony and read a bit of the documentation but I can't get a grip on this thing, I have been at it for two days. Any suggestions for me?

推荐答案

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

Installation of PHPUnit via composer worked. It turns out my composer installation went wrong in some way. After composer was successfully installed, I let it handle installing PHPUnit. After that it just worked. Tests work fine in the IDE and the server is responsive again. Thanks LazyOne.

这篇关于PHPUnit 在 IDE 中工作,但服务器说找不到类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆