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
I am trying to enable my custom module only for a single store view but the functionality is still working for all store views.
I have the following configuration:
Main Website > (Default store view, B2B Store view)
I want to enable my module only for the B2B Store view.
I tried to did this using system.xml: Code is:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<tab id="customrfq" translate="label" sortOrder="1000">
<label>Request For Quote</label>
</tab>
<section id="customrfq" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>RFQ</label>
<tab>customrfq</tab>
<resource>CustomB2BRFQ_Module::rfq</resource>
<group id="department" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>RFQ configuration</label>
<field id="view_list" translate="label comment" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Show Quotes</label>
<comment>Show request for quotes</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
</group>
</section>
</system>
</config>
Config.xml:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
<customrfq>
<department>
<view_list>1</view_list>
</department>
</customrfq>
</default>
</config>
Layout file:
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block class="CustomB2BRFQ\Module\Block\RequestForQuoteForm" name="custom_module_form"
template="CustomB2BRFQ_Module::rfq.phtml" ifconifg="customrfq/department/view_list" cacheable="false"/>
<arguments>
<argument name="path" xsi:type="helper" helper="CustomB2BRFQ\Module\Helper\Data::getPath" translate="true" />
</arguments>
</referenceContainer>
</body>
</page>
Helper File:
<?php
/**
* Created By : Rashi Goyal
*/
namespace CustomB2BRFQ\Module\Helper;
class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
const PATH_FIELD = 'customrfq/department/view_list';
/**
* #var \Magento\Framework\App\Config\ScopeConfigInterface
*/
protected $scopeConfig;
/**
* #param \Magento\Framework\App\Helper\Context $context
* #param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
*/
public function __construct(
\Magento\Framework\App\Helper\Context $context,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
){
$this->scopeConfig = $scopeConfig;
parent::__construct($context);
}
public function getPath()
{
return $this->scopeConfig->getValue(self::PATH_FIELD,\Magento\Store\Model\ScopeInterface::SCOPE_STORE);
}
}
Please specify what's wrong with the code?
I think you have set wrong values for following properties (system.xml):
showInDefault
showInWebsite
showInStore
According to your requirement, you want functionality by store. So you have to set these properties like this:
showInDefault="0"
showInWebsite="0"
showInStore="1"
Using this, your configuration setting display only on store view.
Also You have assigned default value = 1 (config.xml)
You should use by default this:
<view_list>0</view_list>
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.
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.
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>