Reputation: 1105
I want to write some browser tests using phpunit-selenium, Now this is my test class
<?php
namespace Tests\System;
use Tests\TestCase;
class LoginTest extends TestCase
{
/**
* @test
*/
public function showLoginPage()
{
$this->url('/');
$this->assertTrue(true);
}
}
And this is the testCase class that i have made to add extra methods and properties to it
<?php
namespace Tests;
require_once dirname(__DIR__) . '/vendor/autoload.php';
use PHPUnit\Extensions\Selenium2TestCase;
class TestCase extends Selenium2TestCase {
public function setUp(): void
{
$config = new \Config('test');
$this->setDesiredCapabilities([
'chromeOptions'=>['w3c' => false, "args" => [
'--no-sandbox',
'--disable-gpu',
'--headless',
'--verbose',
'--whitelisted-ips='
]]]);
$this->setHost('localhost');
$this->setPort(4444);
$this->setBrowserUrl('http://localhost/');
$this->setBrowser('chrome');
$this->shareSession(true);
}
}
Now when i run vendor/bin/phpunit it runs around 366 tests. But they are not tests, They are methods in the assert class. For example it runs this methods
Tests\System\LoginTest::objectHasAttribute
Tests\System\LoginTest::classHasStaticAttribute
Tests\System\LoginTest::classHasAttribute
What did i understand from that response is that, Somehow it not understand to run only those methods which has @test annotation or has prefix test. And the final file is phpunit.xml file
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="tests/bootstrap.php"
backupGlobals="false"
>
<testsuites>
<testsuite name="PHPUnit">
<directory suffix="Test.php">Tests</directory>
</testsuite>
</testsuites>
</phpunit>
I appreciate any help, Thanks.
Upvotes: 2
Views: 243
Reputation: 199
In my case, I was using phpunit 9.5.4 and phpunit-selenium 9.0.0.
Apparently phpunit-selenium is not compatible with phpunit >= 9.4.0. There is an open issue for this: https://github.com/giorgiosironi/phpunit-selenium/issues/453
So the solution (for me) was to downgrade phpunit to 9.3.x:
composer require --dev phpunit/phpunit:9.3.*
Apparently the same problem also occurs for phpunit 8.5.9: https://github.com/sebastianbergmann/phpunit/issues/4516
Upvotes: 2