Skip to content

Commit

Permalink
Upgrade psalm and phpunit
Browse files Browse the repository at this point in the history
  • Loading branch information
hlecorche committed Oct 25, 2023
1 parent 4c1edc9 commit 483df0f
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- php-version: '8.2'

#CS
- php-version: '8.1'
- php-version: '8.2'
description: 'with Coding Standards'
coding-standards: true

Expand Down
2 changes: 1 addition & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
'@DoctrineAnnotation' => true,
'@PHP81Migration' => true,
'@PHP80Migration:risky' => true,
'@PHPUnit84Migration:risky' => true,
'@PHPUnit100Migration:risky' => true,
'array_syntax' => ['syntax' => 'short'],
'fopen_flags' => true,
'header_comment' => ['header' => $fileHeaderComment, 'separate' => 'both'],
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@
"doctrine/dbal": "^2.11.0|^3.0",
"doctrine/doctrine-bundle": "^2.4.5",
"friendsofphp/php-cs-fixer": "^3.0",
"phpunit/phpunit": "^9.3",
"phpunit/phpunit": "^10",
"symfony/doctrine-messenger": "^5.4|^6.3",
"symfony/yaml": "^5.4|^6.3",
"vimeo/psalm": "^4.22"
"vimeo/psalm": "^5"
},
"conflict": {
"symfony/messenger": "6.3.5",
Expand Down
37 changes: 14 additions & 23 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
<?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/8.0/phpunit.xsd"
backupGlobals="false"
colors="true"
beStrictAboutTestsThatDoNotTestAnything="false"
bootstrap="vendor/autoload.php"
>
<php>
<env name="KERNEL_CLASS" value="Ecommit\MessengerSupervisorBundle\Tests\Functional\App\Kernel" />
<env name="APP_ENV" value="test" />
<env name="SHELL_VERBOSITY" value="-1" />
</php>

<extensions>
<extension class="Ecommit\MessengerSupervisorBundle\Tests\BypassFinalHook"/>
</extensions>

<testsuites>
<testsuite name="Project Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd" backupGlobals="false" colors="true" beStrictAboutTestsThatDoNotTestAnything="false" bootstrap="vendor/autoload.php" cacheDirectory=".phpunit.cache">
<php>
<env name="KERNEL_CLASS" value="Ecommit\MessengerSupervisorBundle\Tests\Functional\App\Kernel"/>
<env name="APP_ENV" value="test"/>
<env name="SHELL_VERBOSITY" value="-1"/>
</php>
<extensions>
<bootstrap class="Ecommit\MessengerSupervisorBundle\Tests\BypassFinalHook"/>
</extensions>
<testsuites>
<testsuite name="Project Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
2 changes: 1 addition & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
* @psalm-suppress PossiblyUndefinedMethod
* @psalm-suppress UndefinedMethod
*/
class Configuration implements ConfigurationInterface
{
Expand Down
1 change: 1 addition & 0 deletions src/Mailer/ErrorEmailBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ protected function getThrowableMessage(\Throwable $throwable): string

public function getSubject(WorkerMessageFailedEvent $event, array $transportInfos, array $mailerParameters, bool $stop): string
{
/** @var string $subject */
$subject = $mailerParameters['subject'];
$subject = str_replace('<program>', $transportInfos['program'], $subject);
$subject = str_replace('<server>', php_uname('n'), $subject);
Expand Down
24 changes: 17 additions & 7 deletions tests/AbstractTest.php → tests/AbstractTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Supervisor\Supervisor as SupervisorApi;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

abstract class AbstractTest extends KernelTestCase
abstract class AbstractTestCase extends KernelTestCase
{
protected function getTransports(): array
{
Expand Down Expand Up @@ -98,10 +98,15 @@ protected function createSupervisorApiMockerStart(array $programs, bool $wait):
foreach ($programs as $program) {
$consecutives[] = [$program, $wait];
}
$supervisorApi->expects($this->exactly(\count($programs)))
$matcher = $this->exactly(\count($consecutives));
$supervisorApi->expects($matcher)
->method('startProcessGroup')
->withConsecutive(...$consecutives)
->willReturn([]);
->willReturnCallback(function (string $program, bool $wait) use ($matcher, $consecutives) {
$this->assertEquals($consecutives[$matcher->numberOfInvocations() - 1][0], $program);
$this->assertEquals($consecutives[$matcher->numberOfInvocations() - 1][1], $wait);

return [];
});

return $supervisorApi;
}
Expand All @@ -116,10 +121,15 @@ protected function createSupervisorApiMockerStop(array $programs, bool $wait): S
foreach ($programs as $program) {
$consecutives[] = [$program, $wait];
}
$supervisorApi->expects($this->exactly(\count($programs)))
$matcher = $this->exactly(\count($consecutives));
$supervisorApi->expects($matcher)
->method('stopProcessGroup')
->withConsecutive(...$consecutives)
->willReturn([]);
->willReturnCallback(function (string $program, bool $wait) use ($matcher, $consecutives) {
$this->assertEquals($consecutives[$matcher->numberOfInvocations() - 1][0], $program);
$this->assertEquals($consecutives[$matcher->numberOfInvocations() - 1][1], $wait);

return [];
});

return $supervisorApi;
}
Expand Down
9 changes: 6 additions & 3 deletions tests/BypassFinalHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@
namespace Ecommit\MessengerSupervisorBundle\Tests;

use DG\BypassFinals;
use PHPUnit\Runner\BeforeTestHook;
use PHPUnit\Runner\Extension\Extension;
use PHPUnit\Runner\Extension\Facade;
use PHPUnit\Runner\Extension\ParameterCollection;
use PHPUnit\TextUI\Configuration\Configuration;

class BypassFinalHook implements BeforeTestHook
class BypassFinalHook implements Extension
{
public function executeBeforeTest(string $test): void
public function bootstrap(Configuration $configuration, Facade $facade, ParameterCollection $parameters): void
{
BypassFinals::enable();
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Command/ManageCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@

use Ecommit\MessengerSupervisorBundle\Command\ManageCommand;
use Ecommit\MessengerSupervisorBundle\Supervisor\Supervisor;
use Ecommit\MessengerSupervisorBundle\Tests\AbstractTest;
use Ecommit\MessengerSupervisorBundle\Tests\AbstractTestCase;
use Supervisor\Supervisor as SupervisorApi;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;

class ManageCommandTest extends AbstractTest
class ManageCommandTest extends AbstractTestCase
{
public function testStatusAll(): void
{
Expand Down
18 changes: 10 additions & 8 deletions tests/EventListener/WorkerMessageFailedEventListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,19 @@

use Ecommit\MessengerSupervisorBundle\EventListener\WorkerMessageFailedEventListener;
use Ecommit\MessengerSupervisorBundle\Supervisor\Supervisor;
use Ecommit\MessengerSupervisorBundle\Tests\AbstractTest;
use Ecommit\MessengerSupervisorBundle\Tests\AbstractTestCase;
use Ecommit\MessengerSupervisorBundle\Tests\Functional\App\Messenger\Message\MessageSuccess;
use PHPUnit\Framework\Attributes\DataProvider;
use Psr\Log\LoggerInterface;
use Supervisor\Supervisor as SupervisorApi;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Event\WorkerMessageFailedEvent;

class WorkerMessageFailedEventListenerTest extends AbstractTest
class WorkerMessageFailedEventListenerTest extends AbstractTestCase
{
/**
* @dataProvider getTestOnFailureProvider
*/
#[DataProvider('getTestOnFailureProvider')]
public function testOnFailure(array $failure, bool $willRetry, bool $expectedStopProgram, bool $expectedMail): void
{
self::bootKernel();
Expand Down Expand Up @@ -74,9 +73,12 @@ public function testOnFailure(array $failure, bool $willRetry, bool $expectedSto
if ($expectedMail) {
$consecutives[] = ['Sending email'];
}
$logger->expects($this->exactly(\count($consecutives)))
$matcher = $this->exactly(\count($consecutives));
$logger->expects($matcher)
->method('info')
->withConsecutive(...$consecutives);
->willReturnCallback(function (mixed $value) use ($matcher, $consecutives): void {
$this->assertEquals($consecutives[$matcher->numberOfInvocations() - 1][0], $value);
});

$mailer = $this->getMockBuilder(MailerInterface::class)->getMock();
if ($expectedMail) {
Expand Down Expand Up @@ -119,7 +121,7 @@ public function testOnFailure(array $failure, bool $willRetry, bool $expectedSto
$listener->onFailure($event);
}

public function getTestOnFailureProvider(): array
public static function getTestOnFailureProvider(): array
{
return [
[['stop_program' => 'always', 'send_mail' => 'always'], true, true, true],
Expand Down
4 changes: 2 additions & 2 deletions tests/Supervisor/SupervisorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@

use Ecommit\MessengerSupervisorBundle\Exception\TransportNotFoundException;
use Ecommit\MessengerSupervisorBundle\Supervisor\Supervisor;
use Ecommit\MessengerSupervisorBundle\Tests\AbstractTest;
use Ecommit\MessengerSupervisorBundle\Tests\AbstractTestCase;
use Supervisor\Process;
use Supervisor\Supervisor as SupervisorApi;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;

class SupervisorTest extends AbstractTest
class SupervisorTest extends AbstractTestCase
{
public function testServiceClass(): void
{
Expand Down

0 comments on commit 483df0f

Please sign in to comment.