Symfony & Panther : Panther does'nt load - can't createPantherClient()

1.1k views Asked by At

I have an issue with Panther in a Symfony 4.4 project. The project has LiipFunctionnalTestBundle on it, but for testing JS as well, I wanted to have Panther. I've installed Panther, in my composer I've "symfony/panther": "^0.8.0" and I can extend my class with PantherTestCase or use PantherTestCaseTrait to have Panther and Liip (according to the documentation symfony/panther). But I'm not sure my project initialized Panther... If I do a simple test like:

<?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');
    }
}

I will have an error message when testing it:

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

If I tried to use Liip with WebTestCase and Panther in a Trait : it's working until I want to use specific assert from Panther. And then my IDE say 'assertSelectorIsEnabled' not found in NewsControllerPantherTest'. The method createPantherClient is not recognized, so even if I tried to put a localhost and a port to it, it doesn't work...

So, I think Panther is in my project but doesn't load? I'm in a Windows PC with Mamp, PHP 7.4.1 and Apache.

I've put the tag in phpunit.xml.dist as say in the doc.

<?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>

Thanks a lot for your help =)

1

There are 1 answers

0
Simon Epskamp On

I got this error because our web dir is non-standard. (Found out via stacktrace).

Try putting this in .env (replace web with dir you use):

PANTHER_WEB_SERVER_DIR='./web/'