Symfony和黑豹:Panther无法加载-无法创建PantherClient()

at0kjp5o  于 2022-12-13  发布在  其他
关注(0)|答案(1)|浏览(144)

我在一个 Symfony 4.4 项目中遇到了一个Panther问题。这个项目有LiipFunctionnalTestBundle,但是为了测试JS,我也想使用Panther。我已经安装了Panther,在我的composer中,我有"symfony/panther": "^0.8.0",我可以用PantherTestCase扩展我的类,或者用PantherTestCaseTrait得到Panther和Liip(根据文档symfony/panther).但是我不确定我的项目初始化了Panther...如果我做一个简单的测试,比如:

  1. <?php
  2. namespace App\Tests\Controller\Social;
  3. use Symfony\Component\Panther\PantherTestCase;
  4. class PantherControllerTest extends PantherTestCase
  5. {
  6. public function test1(): void
  7. {
  8. $client = static::createPantherClient(); // create your panther client
  9. $client->request('GET', '/login');
  10. }
  11. }

我在测试时会收到一条错误消息:

  1. App\Tests\Controller\Social\PantherControllerTest::test1
  2. Symfony\Component\Process\Exception\LogicException: Output has been disabled.
  3. and it target the line with "createPantherClient".

如果我尝试将LiipWebTestCase和Panther组合使用:它一直在工作,直到我想使用Panther中的特定Assert。然后我的IDE显示'assertSelectorIsEnabled' not found in NewsControllerPantherTest'。方法createPantherClient无法识别,因此即使我尝试将localhost和端口放入其中,它也无法工作...
所以,我认为黑豹是在我的项目,但不加载?我在一个Windows PC与Mamp,PHP 7.4.1和Apache。
我已经把标记放在了phpunit.xml.dist中,就像文档中所说的那样。

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- https://phpunit.readthedocs.io/en/latest/configuration.html -->
  3. <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
  5. backupGlobals="false"
  6. colors="true"
  7. bootstrap="tests/bootstrap.php"
  8. >
  9. <extensions>
  10. <extension class="Symfony\Component\Panther\ServerExtension" />
  11. </extensions>
  12. <php>
  13. <ini name="error_reporting" value="-1" />
  14. <server name="APP_ENV" value="test" force="true" />
  15. <server name="SHELL_VERBOSITY" value="-1" />
  16. <env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled" />
  17. </php>
  18. <testsuites>
  19. <testsuite name="Project Test Suite">
  20. <directory>tests</directory>
  21. </testsuite>
  22. </testsuites>
  23. <filter>
  24. <whitelist processUncoveredFilesFromWhitelist="true">
  25. <directory suffix=".php">src</directory>
  26. </whitelist>
  27. </filter>
  28. </phpunit>

非常感谢你的帮助=)

k3fezbri

k3fezbri1#

我得到这个错误,因为我们的网站目录是非标准的。(发现通过堆栈跟踪)。
尝试将其放入.env(用您使用的dir替换web):

  1. PANTHER_WEB_SERVER_DIR='./web/'

相关问题