Symfony 4.4 PHPUnit Panther : Facebook\WebDriver\Exception\SessionNotCreatedException: session not created - php
Here is my test file:
<?php
// src/tests/UserActionsTest.php
namespace App\Tests;
use Symfony\Component\Panther\PantherTestCase;
class UserActionsTest extends PantherTestCase {
/**
* An user can subscribe on the Blog
*/
public function testRegistration(): void {
$client = static::createPantherClient();
$crawler = $client->request('GET', '/subscribe');
// This form is generated in JavaScript
$client->waitFor('#subscribe-form');
// Form submission
$client->submitForm('Create the account', [
'username' => 'zozor',
'password' => 'ZoZ0rIsHome',
]);
// User rediction newly subscribed to the homepage
$this->assertSame(self::$baseUrl . '/', $client->getCurrentURL());
// Success notification in JavaScript
$client->waitFor('#success-message');
$this->assertSame('Welcome on the Zozor blog', $crawler->filter('#success-message ol li:first-child')->text());
// The user is well authenticatd
$this->assertSame('Zozor', $crawler->filter('#user-profile span:first-child')->text());
}
}
When I run the command:
PANTHER_NO_HEADLESS=1 ./vendor/bin/simple-phpunit --filter="UserActionsTest"
This gives me an error:
1) App\Tests\UserActionsTest::testRegistration
Facebook\WebDriver\Exception\SessionNotCreatedException: session not created: This version of ChromeDriver only supports Chrome version 85
./vendor/php-webdriver/webdriver/lib/Exception/WebDriverException.php:125
./vendor/php-webdriver/webdriver/lib/Remote/HttpCommandExecutor.php:371
./vendor/php-webdriver/webdriver/lib/Remote/RemoteWebDriver.php:136
./vendor/symfony/panther/src/ProcessManager/ChromeManager.php:67
./vendor/symfony/panther/src/Client.php:98
./vendor/symfony/panther/src/Client.php:365
./vendor/symfony/panther/src/Client.php:254
./tests/UserActionsTest.php:13
I searched on DuckDuckGo but nothing is related to Symfony, PHPUnit, or even PHP language.
I am leaning for a version problem, here is my composer.json:
{
// ...
"require": {
"php": ">=7.1.3",
"ext-ctype": "*",
"ext-iconv": "*",
"composer/package-versions-deprecated": "1.11.99.1",
"doctrine/annotations": "^1.11",
"doctrine/doctrine-bundle": "^2.2",
"doctrine/doctrine-migrations-bundle": "^3.0",
"doctrine/orm": "^2.7",
"sensio/framework-extra-bundle": "^5.6",
"symfony/apache-pack": "^1.0",
"symfony/asset": "4.4.*",
"symfony/console": "4.4.*",
"symfony/dotenv": "4.4.*",
"symfony/flex": "^1.3.1",
"symfony/form": "4.4.*",
"symfony/framework-bundle": "4.4.*",
"symfony/panther": "^0.8.0",
"symfony/security-bundle": "4.4.*",
"symfony/validator": "4.4.*",
"symfony/yaml": "4.4.*"
},
"require-dev": {
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^0.12.58",
"phpstan/phpstan-beberlei-assert": "^0.12.3",
"symfony/browser-kit": "4.4.*",
"symfony/css-selector": "4.4.*",
"symfony/maker-bundle": "^1.24",
"symfony/phpunit-bridge": "^5.2",
"symfony/stopwatch": "^4.4",
"symfony/twig-bundle": "^4.4",
"symfony/web-profiler-bundle": "^4.4"
},
// ...
}
And here is my 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="bin/.phpunit/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
>
<php>
<ini name="error_reporting" value="-1" />
<env name="KERNEL_CLASS" value="App\Kernel" />
<server name="APP_ENV" value="test" force="true" />
<server name="SHELL_VERBOSITY" value="-1" />
<server name="SYMFONY_PHPUNIT_REMOVE" value="" />
<server name="SYMFONY_PHPUNIT_VERSION" value="7.5" />
<env name="SYMFONY_DEPRECATIONS_HELPER" value="" />
<!-- ###+ doctrine/doctrine-bundle ### -->
<env name="DATABASE_URL" value="mysql://:#localhost:33060/" />
<!-- ###- doctrine/doctrine-bundle ### -->
<!-- ###+ symfony/swiftmailer-bundle ### -->
<env name="MAILER_URL" value="null://localhost" />
<!-- ###- symfony/swiftmailer-bundle ### -->
<!-- ###+ symfony/framework-bundle ### -->
<env name="APP_DEBUG" value="1" />
<env name="APP_SECRET" value="" />
<!-- ###- symfony/framework-bundle ### -->
</php>
<testsuites>
<testsuite name="Project Test Suite">
<directory>tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
</listeners>
<extensions>
<!-- It begins a database transaction before every testcase and rolls it back after
the test finished, so tests can manipulate the database without affecting other tests
<extension class="\DAMA\DoctrineTestBundle\PHPUnit\PHPUnitExtension" /> -->
<extension class="Symfony\Component\Panther\ServerExtension" />
</extensions>
</phpunit>
If I add the line as recommended by symfony/panther:
<listener class="Symfony\Component\Panther\ServerListener" />
This gives me the error:
1x: The "Symfony\Component\Panther\ServerListener" class is deprecated since Panther 0.6, use "Symfony\Component\Panther\ServerExtension" instead.
But using Symfony\Component\Panther\ServerExtension it gives me the error:
Class "Symfony\Component\Panther\ServerExtension" does not implement the PHPUnit\Framework\TestListener interface
Thank you in advance for your help.
Modification: the problem was fixed by uninstalling Chromium and installing it from the Snap Store (Linux Mint 20 / Ubuntu LTS 20.04.1):
sudo rm /etc/apt/preferences.d/nosnap.pref
sudo apt update
sudo apt full-upgrade
sudo apt install snapd
sudo snap install chromium
Related
Why PHPUnit into Laravel return "No tests executed!" at execution feature tests
I have file tests/Feature/InvoicePaymentTest.php, he contains are three tests. First and second are tests is executed correctly. Third test has return "No tests executed!", and not return error. My code scheme <?php namespace Tests\Feature; // use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; use Tests\TestCase; class SubscriptionInvoicePaymentTest extends TestCase { public function testFirst() { // this test correctly exeqted } public function testSecond() { // this test correctly exeqted } public function nextPaymentTest() { // this test return "No tests executed!" as seen in the screenshot } } My phpunit.xml <?xml version="1.0" encoding="UTF-8"?> <phpunit backupGlobals="false" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false"> <testsuites> <testsuite name="Unit"> <directory suffix="Test.php">./tests/Unit</directory> </testsuite> <testsuite name="Feature"> <directory suffix="Test.php">./tests/Feature</directory> </testsuite> </testsuites> <filter> <whitelist processUncoveredFilesFromWhitelist="true"> <directory suffix=".php">./app</directory> </whitelist> </filter> <php> <env name="APP_ENV" value="testing"/> <env name="BCRYPT_ROUNDS" value="4"/> <env name="BROADCAST_DRIVER" value="fake"/> <env name="CACHE_DRIVER" value="array"/> <env name="SESSION_DRIVER" value="array"/> <env name="QUEUE_DRIVER" value="sync"/> <env name="MAIL_DRIVER" value="array"/> <env name="DB_CONNECTION" value="mysql"/> <env name="DB_DATABASE" value="dbName"/> <env name="TELESCOPE_ENABLED" value="false"/> </php> </phpunit> What could be the problem? Thank you in advance
In phpunit a method should be either prefixed with test or have the #test annotation in order to be run.
When I set Config database, it is reseting my db connection
I wanna use php unit tests to test an endpoint. I'm calling an endpoint from my unit test. Within my endpoint when I say public function __construct() { \Config::set('database.default', 'pgsql-master'); print_r(\Config::get('database.connections.pgsql-master.username')); // toters_testing_usr } I believe it's resetting my db connection and my db testing is empty. because when I say $env = config('app.env'); if ($env == 'production') { \Config::set('database.default', 'pgsql-master'); } it worrks. Why is this happening? this is my phpunit.xml <?xml version="1.0" encoding="UTF-8"?> <phpunit backupGlobals="false" backupStaticAttributes="false" bootstrap="bootstrap/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" syntaxCheck="false"> <filter> <whitelist> <directory suffix=".php">app/</directory> </whitelist> </filter> <listeners> <listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener"></listener> </listeners> <php> <env name="APP_ENV" value="testing"/> <env name="API_STRICT" value="false"/> <env name="CACHE_DRIVER" value="array"/> <env name="SESSION_DRIVER" value="array"/> <env name="QUEUE_DRIVER" value="sync"/> <env name="RAVEN_LEVEL" value="none"/> <env name="MAIL_DRIVER" value="log"/> <ini name="display_errors" value="On" /> <ini name="display_startup_errors" value="On" /> <ini name="memory_limit" value="2048M" /> </php> </phpunit>
RuntimeException : Unable to guess the Kernel directory
I am using Symfony 3.4. Suddenly, whenever I try to run my tests (phpunit) in /tests, I get the following error: RuntimeException : Unable to guess the Kernel directory. My test class looks something like: class PaymentCreditTest extends KernelTestCase { /** #var PaymentRepository */ public $paymentRepository; /** * {#inheritDoc} */ protected function setUp() { $this->paymentRepository = self::bootKernel()->getContainer()->get('chaku.repository.payment'); } public function test_canRetrieveDeadFreightNetAmount() { /** #var Payment $payment */ $payment = $this->paymentRepository->findOneBy(['id' => 1000002]); // just to see payment object dump($payment); } } This is what my phpunit.xml.dist looks like: <?xml version="1.0" encoding="UTF-8"?> <!-- https://phpunit.de/manual/current/en/appendixes.configuration.html --> <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.8/phpunit.xsd" backupGlobals="false" colors="true" bootstrap="app/autoload.php"> <php> <ini name="error_reporting" value="-1" /> <server name="KERNEL_CLASS" value="AppKernel" /> <env name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/> </php> <testsuites> <testsuite name="Project Test Suite"> <directory>tests</directory> </testsuite> </testsuites> <filter> <whitelist> <directory>src</directory> <exclude> <directory>src/*Bundle/Resources</directory> <directory>src/*/*Bundle/Resources</directory> <directory>src/*/Bundle/*Bundle/Resources</directory> </exclude> </whitelist> </filter> </phpunit> Any help with this will be well appreciated.
I think I had the exact same issue few weeks ago, can you try adding KERNEL_DIR: <php> <ini name="error_reporting" value="-1" /> <server name="KERNEL_CLASS" value="AppKernel" /> <server name="KERNEL_DIR" value="app/" /> <env name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/> </php>
./vendor/bin/simple-phpunit -c app/ add the Appkernel directory which is app while executing the command for testing.
Where do I need to register my new Symfony controller test?
Symfony 3.3 automatically generated an empty test for my new controller. It lives at src/AppBundle/Tests/Controller/PairGalleryControllerTest.php Now I want to actually run the contents. They look like this: public function testIndex() { $client = static::createClient(); $crawler = $client->request('GET', '/pair-gallery/1'); $content = $client->getResponse()->getContent(); $this->assertContains('NeedleShouldFail', $content); } ... but when I run my test suite with bin/phpunit I find that all tests pass. This new test is clearly not being run. Where do I need to register my new test in order for it to run? ==== Edit: Here is the content of my phpunit.xml.dist file: <?xml version="1.0" encoding="UTF-8"?> <!-- http://phpunit.de/manual/4.1/en/appendixes.configuration.html --> <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd" backupGlobals="false" colors="true" bootstrap="autoload.php" > <php> <ini name="error_reporting" value="-1" /> <!-- <server name="KERNEL_DIR" value="/path/to/your/app/" /> --> </php> <testsuites> <testsuite name="Project Test Suite"> <directory>../src/*/*Bundle/Tests</directory> <directory>../src/*/Bundle/*Bundle/Tests</directory> <directory>../src/*Bundle/Tests</directory> </testsuite> </testsuites> <filter> <whitelist> <directory>../src</directory> <exclude> <directory>../src/*Bundle/Resources</directory> <directory>../src/*Bundle/Tests</directory> <directory>../src/*/*Bundle/Resources</directory> <directory>../src/*/*Bundle/Tests</directory> <directory>../src/*/Bundle/*Bundle/Resources</directory> <directory>../src/*/Bundle/*Bundle/Tests</directory> </exclude> </whitelist> </filter> </phpunit>
Delete action is not working in laravel?
I have a form which has the delete button in it. <form method="post" id="delform" action="{{ url('/templates/delete',[$template->template_id]) }}"> {{ method_field('DELETE') }} {{ csrf_field() }} <input type="submit" class="btn btn-danger" id="del" value="delete> </form> then in my routes web.php: Route::delete('/templates/delete/{id}','TemplateController#delete'); when i click on delete i get this error: what am i doing wong please help? thanks in advance I have added my composer.json here: { "name": "laravel/laravel", "description": "The Laravel Framework.", "keywords": ["framework", "laravel"], "license": "MIT", "type": "project", "require": { "php": ">=5.6.4", "laravel/framework": "5.4.*", "laravel/tinker": "~1.0", "maatwebsite/excel": "~2.1.0" "rmccue/requests": ">=1.0" }, "require-dev": { "fzaninotto/faker": "~1.4", "mockery/mockery": "0.9.*", "phpunit/phpunit": "~5.7" }, "autoload": { "classmap": [ "database" ], "psr-4": { "App\\": "app/" } }, "autoload-dev": { "psr-4": { "Tests\\": "tests/" } }, "scripts": { "post-root-package-install": [ "php -r \"file_exists('.env') || copy('.env.example', '.env');\"" ], "post-create-project-cmd": [ "php artisan key:generate" ], "post-install-cmd": [ "Illuminate\\Foundation\\ComposerScripts::postInstall", "php artisan optimize" ], "post-update-cmd": [ "Illuminate\\Foundation\\ComposerScripts::postUpdate", "php artisan optimize" ] }, "config": { "preferred-install": "dist", "sort-packages": true } } here is the console logs:
You forgot double-quotes to close value from input submit <input type="submit" ... value="delete"> and a comma in composer json after package: "maatwebsite/excel": "~2.1.0", Finally HTML forms do not support PUT, PATCH or DELETE actions. So, when defining PUT, PATCH or DELETE routes that are called from an HTML form, you will need to add a hidden _method field to the form. The value sent with the _method field will be used as the HTTP request method. <input type="hidden" name="_method" value="DELETE"> You may use the method_field helper to generate the _method input: {{ method_field('DELETE') }} Laravel routes documentation Look at rest conventions