Skip to content

Commit

Permalink
chore: modernize tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alanpoulain committed Jan 22, 2024
1 parent 8b652e8 commit 952e74e
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 39 deletions.
10 changes: 7 additions & 3 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@
'@PhpCsFixer:risky' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHPUnit75Migration:risky' => true,
'method_chaining_indentation' => false,
'no_superfluous_phpdoc_tags' => ['allow_mixed' => true],
'@PHPUnit100Migration:risky' => true,
'declare_strict_types' => true,
'final_class' => true,
'header_comment' => [
'header' => $header,
'location' => 'after_open',
],
'method_chaining_indentation' => false,
'no_superfluous_phpdoc_tags' => ['allow_mixed' => true],
'php_unit_internal_class' => false,
'php_unit_test_class_requires_covers' => false,
])
->setRiskyAllowed(true)
->setFinder(
Expand Down
2 changes: 2 additions & 0 deletions features/app/config/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@
* file that was distributed with this source code.
*/

declare(strict_types=1);

$_ENV['SIGNATURE_KEY'] = 'les-tilleuls.coop';
2 changes: 2 additions & 0 deletions features/app/config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* file that was distributed with this source code.
*/

declare(strict_types=1);

return [
CoopTilleuls\UrlSignerBundle\CoopTilleulsUrlSignerBundle::class => ['all' => true],
FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle::class => ['test' => true],
Expand Down
4 changes: 3 additions & 1 deletion features/app/src/Controller/DocumentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace CoopTilleuls\UrlSignerBundle\Tests\Controller;

use Symfony\Component\HttpFoundation\Response;

class DocumentController
final class DocumentController
{
public function __invoke(): Response
{
Expand Down
4 changes: 3 additions & 1 deletion features/app/src/Controller/SignController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace CoopTilleuls\UrlSignerBundle\Tests\Controller;

use CoopTilleuls\UrlSignerBundle\UrlSigner\UrlSignerInterface;
Expand All @@ -17,7 +19,7 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

class SignController extends AbstractController
final class SignController extends AbstractController
{
private UrlSignerInterface $urlSigner;

Expand Down
4 changes: 3 additions & 1 deletion features/app/src/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace CoopTilleuls\UrlSignerBundle\Tests;

use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;

class Kernel extends BaseKernel
final class Kernel extends BaseKernel
{
use MicroKernelTrait;

Expand Down
4 changes: 2 additions & 2 deletions tests/Behat/UrlSignerContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function iCreateAnAbsoluteSignedUrl(): void
public function iRequestTheSignedUrl(): void
{
$signedUrl = $this->client->getResponse()->getContent();
if (!$signedUrl) {
if (false === $signedUrl || '' === $signedUrl) {
throw new \RuntimeException('No signed URL received.');
}
$this->client->request('GET', $signedUrl);
Expand All @@ -75,7 +75,7 @@ public function iRequestASignedRouteWithoutAValidSignature(): void
public function iShouldGetAValidSignedUrl(): void
{
$signedUrl = $this->client->getResponse()->getContent();
if (!$signedUrl) {
if (false === $signedUrl || '' === $signedUrl) {
throw new \RuntimeException('No signed URL received.');
}
if (!$this->urlSigner->validate($signedUrl)) {
Expand Down
7 changes: 2 additions & 5 deletions tests/DependencyInjection/Compiler/SignerPassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use CoopTilleuls\UrlSignerBundle\UrlSigner\Md5UrlSigner;
use CoopTilleuls\UrlSignerBundle\UrlSigner\Sha256UrlSigner;
use CoopTilleuls\UrlSignerBundle\UrlSigner\UrlSignerInterface;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
Expand All @@ -26,11 +27,7 @@
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;

/**
* @internal
*
* @covers \CoopTilleuls\UrlSignerBundle\DependencyInjection\Compiler\SignerPass
*/
#[CoversClass(SignerPass::class)]
final class SignerPassTest extends TestCase
{
use ProphecyTrait;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use CoopTilleuls\UrlSignerBundle\UrlSigner\Md5UrlSigner;
use CoopTilleuls\UrlSignerBundle\UrlSigner\Sha256UrlSigner;
use CoopTilleuls\UrlSignerBundle\UrlSigner\UrlSignerInterface;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
Expand All @@ -26,11 +27,7 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;

/**
* @internal
*
* @covers \CoopTilleuls\UrlSignerBundle\DependencyInjection\CoopTilleulsUrlSignerExtension
*/
#[CoversClass(CoopTilleulsUrlSignerExtension::class)]
final class CoopTilleulsUrlSignerExtensionTest extends TestCase
{
use ProphecyTrait;
Expand Down
10 changes: 4 additions & 6 deletions tests/EventListener/ValidateSignedRouteListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

use CoopTilleuls\UrlSignerBundle\EventListener\ValidateSignedRouteListener;
use CoopTilleuls\UrlSignerBundle\UrlSigner\UrlSignerInterface;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
Expand All @@ -25,11 +27,7 @@
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\HttpKernelInterface;

/**
* @internal
*
* @covers \CoopTilleuls\UrlSignerBundle\EventListener\ValidateSignedRouteListener
*/
#[CoversClass(ValidateSignedRouteListener::class)]
final class ValidateSignedRouteListenerTest extends TestCase
{
use ProphecyTrait;
Expand All @@ -51,7 +49,7 @@ public function testSubscribedEvents(): void
self::assertArrayHasKey(RequestEvent::class, ValidateSignedRouteListener::getSubscribedEvents());
}

/** @dataProvider provideValidateSignedRouteCases */
#[DataProvider('provideValidateSignedRouteCases')]
public function testValidateSignedRoute(string $validUrl): void
{
$request = Request::create('http://test.org/valid-signature');
Expand Down
7 changes: 2 additions & 5 deletions tests/UrlSigner/AbstractUrlSignerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@
namespace Tests\UrlSigner;

use CoopTilleuls\UrlSignerBundle\UrlSigner\AbstractUrlSigner;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

/**
* @internal
*
* @covers \CoopTilleuls\UrlSignerBundle\UrlSigner\AbstractUrlSigner
*/
#[CoversClass(AbstractUrlSigner::class)]
final class AbstractUrlSignerTest extends TestCase
{
private AbstractUrlSigner $signer;
Expand Down
7 changes: 2 additions & 5 deletions tests/UrlSigner/Md5UrlSignerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@
namespace Tests\UrlSigner;

use CoopTilleuls\UrlSignerBundle\UrlSigner\Md5UrlSigner;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

/**
* @internal
*
* @covers \CoopTilleuls\UrlSignerBundle\UrlSigner\Md5UrlSigner
*/
#[CoversClass(Md5UrlSigner::class)]
final class Md5UrlSignerTest extends TestCase
{
private Md5UrlSigner $signer;
Expand Down
7 changes: 2 additions & 5 deletions tests/UrlSigner/Sha256UrlSignerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@
namespace Tests\UrlSigner;

use CoopTilleuls\UrlSignerBundle\UrlSigner\Sha256UrlSigner;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

/**
* @internal
*
* @covers \CoopTilleuls\UrlSignerBundle\UrlSigner\Sha256UrlSigner
*/
#[CoversClass(Sha256UrlSigner::class)]
final class Sha256UrlSignerTest extends TestCase
{
private Sha256UrlSigner $signer;
Expand Down

0 comments on commit 952e74e

Please sign in to comment.