Skip to content

Commit

Permalink
Merge pull request #20 from Bee-Lab/upgrade-phpunit
Browse files Browse the repository at this point in the history
⬆️  allow phpunit 10/11
  • Loading branch information
garak authored Aug 18, 2024
2 parents 175d01e + b596502 commit 3763f5c
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 89 deletions.
3 changes: 2 additions & 1 deletion .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHP80Migration:risky' => true,
'@PHPUnit84Migration:risky' => true,
'@PHP81Migration' => true,
'@PHPUnit100Migration:risky' => true,
'declare_strict_types' => false,
'native_function_invocation' => ['include' => ['@all']],
'php_unit_mock_short_will_return' => true,
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"doctrine/lexer": "^2.1",
"doctrine/orm": "^2.16",
"mikey179/vfsstream": "^1.6.7",
"phpunit/phpunit": "^9.6",
"phpunit/phpunit": "^10.5 || ^11.3",
"symfony/doctrine-bridge": "^6.4 || ^7.0",
"symfony/framework-bundle": "^6.4 || ^7.0",
"symfony/mime": "^6.4 || ^7.0",
Expand Down
6 changes: 0 additions & 6 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,3 @@ parameters:
message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeDefinition\\:\\:children\\(\\)\\.$#"
count: 1
path: src/DependencyInjection/Configuration.php

-
message: "#^PHPDoc tag @throws with type Doctrine\\\\DBAL\\\\DBALException\\|InvalidArgumentException is not subtype of Throwable$#"
count: 1
path: src/Test/WebTestCase.php

16 changes: 5 additions & 11 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- https://phpunit.readthedocs.io/en/9.5/configuration.html -->
<!-- https://docs.phpunit.de/en/10.5/configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
backupGlobals="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite name="Project Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<source>
<include>
<directory>src</directory>
</include>
</coverage>
</source>
</phpunit>
3 changes: 0 additions & 3 deletions src/DependencyInjection/BeelabTestExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@

final class BeelabTestExtension extends Extension
{
/**
* @param array<int, mixed> $configs
*/
public function load(array $configs, ContainerBuilder $container): void
{
$configuration = new Configuration();
Expand Down
26 changes: 9 additions & 17 deletions src/Test/WebTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,11 @@
abstract class WebTestCase extends SymfonyWebTestCase
{
protected static ?EntityManagerInterface $em = null;

protected static KernelBrowser $client;

private ?AbstractFixture $fixture = null;

protected static ?string $authUser = null;

protected static ?string $authPw = null;

/** @var ContainerInterface */
protected static $container;
protected static ?ContainerInterface $container = null;

protected function setUp(): void
{
Expand Down Expand Up @@ -64,15 +58,13 @@ protected function setUp(): void

protected function tearDown(): void
{
if (null !== self::$em) {
self::$em->getConnection()->close();
}
self::$em?->getConnection()->close();
parent::tearDown();
}

/**
* Save request output and show it in the browser
* See http://giorgiocefaro.com/blog/test-symfony-and-automatically-open-the-browser-with-the-response-content
* See https://web.archive.org/web/20190205012632/https://giorgiocefaro.com/blog/test-symfony-and-automatically-open-the-browser-with-the-response-content
* You can define a "domain" parameter with the current domain of your app.
*/
protected static function saveOutput(bool $delete = true): void
Expand Down Expand Up @@ -104,7 +96,7 @@ protected static function saveOutput(bool $delete = true): void
*
* @throws \InvalidArgumentException
*/
protected static function login(string $username = '[email protected]', string $firewall = null, string $service = null): void
protected static function login(string $username = '[email protected]', ?string $firewall = null, ?string $service = null): void
{
$service ??= static::$container->getParameter('beelab_test.user_service');
$object = static::$container->get($service);
Expand Down Expand Up @@ -180,13 +172,13 @@ protected static function getTxtFile(string $file = '0'): UploadedFile
*
* @param array<int, string> $fixtures e.g. ['UserData', 'OrderData']
*
* @throws \Doctrine\DBAL\DBALException
* @throws \Doctrine\DBAL\Exception
* @throws \InvalidArgumentException
*/
protected function loadFixtures(
array $fixtures,
string $namespace = 'App\\DataFixtures\\ORM\\',
string $managerService = null,
?string $managerService = null,
bool $append = false,
): void {
if (null !== $managerService) {
Expand Down Expand Up @@ -238,7 +230,7 @@ protected static function commandTest(
Command $command,
array $arguments = [],
array $otherCommands = [],
array $inputs = null,
?array $inputs = null,
): string {
$application = new Application(self::$client->getKernel());
$application->add($command);
Expand Down Expand Up @@ -307,15 +299,15 @@ protected static function setSessionException(string $msg = 'error...'): void
self::$client->getCookieJar()->set($cookie);
}

protected static function clickLinkByData(string $dataName, string $parent = null): Crawler
protected static function clickLinkByData(string $dataName, ?string $parent = null): Crawler
{
$selector = (null === $parent ? '' : $parent.' ').'a[data-'.$dataName.']';
$linkNode = self::$client->getCrawler()->filter($selector);

return self::$client->click($linkNode->link());
}

protected static function clickLinkBySelectorText(string $linkText, string $parent = null): Crawler
protected static function clickLinkBySelectorText(string $linkText, ?string $parent = null): Crawler
{
$selector = (null === $parent ? '' : $parent.' ').'a:contains("'.$linkText.'")';
$linkNode = self::$client->getCrawler()->filter($selector);
Expand Down
Loading

0 comments on commit 3763f5c

Please sign in to comment.