[英]Symfony & Panther : Panther does'nt load - can't createPantherClient()
我在Symfony 4.4項目中遇到 Panther 問題。 該項目有LiipFunctionnalTestBundle
,但為了測試 JS,我想要 Panther。 我已經安裝了 Panther,在我的作曲家中我有"symfony/panther": "^0.8.0"
並且我可以使用 PantherTestCase 擴展我的PantherTestCase
或使用PantherTestCaseTrait
來擁有 Panther 和Liip
(根據文檔symfony/panther )。 但是我不確定我的項目是否初始化了 Panther...如果我做一個簡單的測試,比如:
<?php
namespace App\Tests\Controller\Social;
use Symfony\Component\Panther\PantherTestCase;
class PantherControllerTest extends PantherTestCase
{
public function test1(): void
{
$client = static::createPantherClient(); // create your panther client
$client->request('GET', '/login');
}
}
我在測試的時候會報錯:
App\Tests\Controller\Social\PantherControllerTest::test1
Symfony\Component\Process\Exception\LogicException: Output has been disabled.
and it target the line with "createPantherClient".
如果我嘗試在 Trait Liip
與WebTestCase
和 Panther 一起使用:它一直有效,直到我想使用來自 Panther 的特定斷言。 然后我的 IDE 說'assertSelectorIsEnabled'
not found in NewsControllerPantherTest'
。 方法createPantherClient
無法識別,所以即使我嘗試將本地主機和端口放入其中,它也不起作用......
所以,我認為 Panther 在我的項目中但沒有加載? 我在一台裝有 Mamp 的 Windows PC、PHP 7.4.1 和 Apache。
如文檔中所述,我已將標簽放在 phpunit.xml.dist 中。
<?xml version="1.0" encoding="UTF-8"?>
<!-- https://phpunit.readthedocs.io/en/latest/configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="tests/bootstrap.php"
>
<extensions>
<extension class="Symfony\Component\Panther\ServerExtension" />
</extensions>
<php>
<ini name="error_reporting" value="-1" />
<server name="APP_ENV" value="test" force="true" />
<server name="SHELL_VERBOSITY" value="-1" />
<env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled" />
</php>
<testsuites>
<testsuite name="Project Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
非常感謝您的幫助 =)
我得到這個錯誤是因為我們的 web 目錄是非標准的。 (通過堆棧跟蹤發現)。
嘗試將其放入.env
(將web
替換為您使用的目錄):
PANTHER_WEB_SERVER_DIR='./web/'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.