简体   繁体   English

更新了composer.json,现在PHP自动加载不起作用。 PHPUnit找不到我的班级

[英]Updated composer.json, now PHP autoload does not work. PHPUnit cannot find my classes

I am a user of the EWZSearchBundle and want to update it to work with Symfony 3.x 我是EWZSearchBundle的用户,想更新它以与Symfony 3.x一起使用

Updating the composer.json file should be easy, but I don't manage to get the unit tests running. 更新composer.json文件应该很容易,但是我无法使单元测试运行。

Here is the link to my fork of the bundle with some "improvements": link to commit 这是带有一些“改进”的捆绑包的链接提交的链接

When I run the phpunit tests, I get the following error: 当我运行phpunit测试时,出现以下错误:

$ vendor/bin/phpunit Tests/Lucene/FieldTest.php
PHPUnit 5.7.26 by Sebastian Bergmann and contributors.

PHP Fatal error:  Call to undefined method Zend\Search\Lucene\Document\Field::getType() in /tmp/azine/EWZSearchBundle/Tests/Lucene/FieldTest.php on line 18
PHP Stack trace:
PHP   1. {main}() /tmp/azine/EWZSearchBundle/vendor/phpunit/phpunit/phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() /tmp/azine/EWZSearchBundle/vendor/phpunit/phpunit/phpunit:52
PHP   3. PHPUnit_TextUI_Command->run() /tmp/azine/EWZSearchBundle/vendor/phpunit/phpunit/src/TextUI/Command.php:116
PHP   4. PHPUnit_TextUI_TestRunner->doRun() /tmp/azine/EWZSearchBundle/vendor/phpunit/phpunit/src/TextUI/Command.php:186
PHP   5. PHPUnit_Framework_TestSuite->run() /tmp/azine/EWZSearchBundle/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:517
PHP   6. PHPUnit_Framework_TestCase->run() /tmp/azine/EWZSearchBundle/vendor/phpunit/phpunit/src/Framework/TestSuite.php:733
PHP   7. PHPUnit_Framework_TestResult->run() /tmp/azine/EWZSearchBundle/vendor/phpunit/phpunit/src/Framework/TestCase.php:868
PHP   8. PHPUnit_Framework_TestCase->runBare() /tmp/azine/EWZSearchBundle/vendor/phpunit/phpunit/src/Framework/TestResult.php:686
PHP   9. PHPUnit_Framework_TestCase->runTest() /tmp/azine/EWZSearchBundle/vendor/phpunit/phpunit/src/Framework/TestCase.php:913
PHP  10. ReflectionMethod->invokeArgs() /tmp/azine/EWZSearchBundle/vendor/phpunit/phpunit/src/Framework/TestCase.php:1062
PHP  11. EWZ\Bundle\SearchBundle\Tests\Lucene\FieldTest->testGetType() /tmp/azine/EWZSearchBundle/vendor/phpunit/phpunit/src/Framework/TestCase.php:1062

Steps to reproduce: 重现步骤:

$ git clone  git@github.com:azine/EWZSearchBundle.git
$ cd EWZSearchBundle
$ composer install
$ vendor/bin/phpunit Tests/Lucene/FieldTest.php

The cause of this error is, that the EWZ\\Bundle\\SearchBundle\\Lucene\\Field class is not (properly) autoloaded, but the Zend\\Search\\Lucene\\Document\\Field from the vendor directory is autoloaded but doesn't have that method. 导致此错误的原因是, EWZ\\Bundle\\SearchBundle\\Lucene\\Field类没有(正确)自动加载,但是vendor目录中的Zend\\Search\\Lucene\\Document\\Field是自动加载的,但没有该方法。

Can anyone tell me why the autoloading of the classes in the namespace EWZ\\Bundle\\SearchBundle from the root directory does not work? 谁能告诉我为什么无法从根目录自动加载名称空间EWZ\\Bundle\\SearchBundle中的类吗?

All help is highly appreciated. 非常感谢所有帮助。

The class is properly autoloaded. 该类已正确自动加载。 The problem is with the code itself. 问题出在代码本身。

When you're initiating a $binaryField by code 通过代码初始化$binaryField

$binaryField = Field::Binary('Binary', 'value');

the result is of class \\Zend\\Search\\Lucene\\Document\\Field , not of \\EWZ\\Bundle\\SearchBundle\\Lucene\\Field . 结果是\\Zend\\Search\\Lucene\\Document\\Field ,而不是\\EWZ\\Bundle\\SearchBundle\\Lucene\\Field

Because it executes return new self($name, $value, '', true, false, false, true); 因为执行return new self($name, $value, '', true, false, false, true); inside of \\Zend\\Search\\Lucene\\Document\\Field , and this runs a constructor of \\Zend\\Search\\Lucene\\Document\\Field , not your extended class. \\Zend\\Search\\Lucene\\Document\\Field ,这将运行\\Zend\\Search\\Lucene\\Document\\Field的构造函数,而不是扩展类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM