Skip to content

Commit

Permalink
Fixed UDP server creation during PHPUnit tests in a non-CI context
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianLeChat committed Oct 27, 2023
1 parent 0829f00 commit 32a5a5f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/Command/UdpServerCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ function (Socket $server) use ($io): void
// Si le serveur a bien été créé, on affiche ensuite un message de succès.
$io->success("UDP server successfully created.");

if ($this->kernel->getEnvironment() === "test")
{
// En plein environnement de test, on ferme le serveur immédiatement
// pour éviter de bloquer les tests.
$server->close();
}

$server->on("message", function ($message, $address) use ($io): void
{
// Lorsque le serveur reçoit un message, on vérifie s'il est enregistré
Expand Down
3 changes: 1 addition & 2 deletions tests/Command/UdpServerCreatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ public function testExecute(): void
$tester->assertCommandIsSuccessful();

// Vérification de la sortie de la commande.
// Note : sur GitHub Actions, la création sera refusée.
$output = $tester->getDisplay();

$this->assertStringContainsString("Permission denied", $output);
$this->assertMatchesRegularExpression("/(successfully created)|(Permission denied)/", $output);
}
}

0 comments on commit 32a5a5f

Please sign in to comment.