Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Symfony 6.2, PHP 8.2, PHPUnit 10 #42

Merged
merged 9 commits into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ jobs:
- name: 'Checkout Code'
uses: actions/checkout@v2

- name: 'Setup PHP'
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
ini-values: memory_limit=-1
coverage: none
tools: composer:v2

- name: 'Install Dependencies'
run: composer install --prefer-dist --no-progress --no-interaction

Expand All @@ -41,7 +49,7 @@ jobs:
- name: 'Setup PHP'
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
php-version: 8.2
ini-values: memory_limit=-1
coverage: none
tools: composer:v2
Expand All @@ -66,7 +74,7 @@ jobs:
- name: 'Setup PHP'
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
php-version: 8.2
ini-values: memory_limit=-1
coverage: none
tools: composer:v2
Expand All @@ -86,10 +94,8 @@ jobs:
fail-fast: false
matrix:
php-version:
- '8.1'
- '8.2'
symfony-version:
- '6.1'
- '6.2'
steps:
- name: 'Checkout Code'
Expand All @@ -102,8 +108,6 @@ jobs:
ini-values: memory_limit=-1
coverage: none
tools: composer:v2
env:
SYMFONY_VERSION: ${{ matrix.symfony-version }}

- name: 'Install PHP dependencies with Composer'
run: composer install --prefer-dist --no-progress --optimize-autoloader
Expand All @@ -125,7 +129,7 @@ jobs:
- name: 'Setup PHP'
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
php-version: 8.2
ini-values: memory_limit=-1
coverage: pcov
tools: composer:v2
Expand Down
2 changes: 1 addition & 1 deletion .styleci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ risky: true
preset: symfony
tab-width: 4
use-tabs: false
version: 8.1
version: 8.2
enabled:
- combine_consecutive_unsets
- ordered_class_elements
Expand Down
2 changes: 0 additions & 2 deletions Tests/Asset/DatetimeVersionStrategyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@

final class DatetimeVersionStrategyTest extends TestCase
{
/** @var DateTimeHelper|MockObject */
private DateTimeHelper|MockObject $dateTimeHelper;

private DatetimeVersionStrategy $datetimeVersionStrategy;

protected function setUp(): void
Expand Down
13 changes: 2 additions & 11 deletions Tests/Command/AbstractBaseCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace StfalconStudio\ApiBundle\Tests\Command;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use StfalconStudio\ApiBundle\Exception\Console\InvalidParameterException;
Expand All @@ -21,15 +22,9 @@

final class AbstractBaseCommandTest extends TestCase
{
/** @var OutputFormatterInterface|MockObject */
private OutputFormatterInterface|MockObject $formatter;

/** @var InputInterface|MockObject */
private InputInterface|MockObject $input;

/** @var OutputInterface|MockObject */
private OutputInterface|MockObject $output;

private DummyCommand $command;

protected function setUp(): void
Expand Down Expand Up @@ -76,11 +71,7 @@ public function testInitializeWrongTypeOfDate(): void
$this->command->runInitialize($this->input, $this->output);
}

/**
* @dataProvider dataProviderForInitializeInvalidDateFormat
*
* @param string $optionValue
*/
#[DataProvider('dataProviderForInitializeInvalidDateFormat')]
public function testInitializeInvalidDateFormat(string $optionValue): void
{
$this->input
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,15 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;

abstract class AbstractDtoBasedActionTest extends TestCase
abstract class AbstractDtoBasedActionTestCase extends TestCase
{
/** @var AuthorizationCheckerInterface|MockObject */
protected AuthorizationCheckerInterface|MockObject $authorizationChecker;

/** @var EntityValidator|MockObject */
protected EntityValidator|MockObject $entityValidator;

/** @var JsonSchemaValidator|MockObject */
protected JsonSchemaValidator|MockObject $jsonSchemaValidator;

/** @var Serializer|MockObject */
protected Serializer|MockObject $serializer;

/** @var DtoExtractor|MockObject */
protected DtoExtractor|MockObject $dtoExtractor;

/** @var EventDispatcherInterface|MockObject */
protected EventDispatcherInterface|MockObject $eventDispatcher;

/** @var Request|MockObject */
protected Request|MockObject $request;

/** @var AbstractDtoBasedAction */
protected $action;

protected function setUp(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
use StfalconStudio\ApiBundle\DTO\DtoInterface;
use Symfony\Component\HttpFoundation\Request;

final class DtoBasedActionTest extends AbstractDtoBasedActionTest
final class DtoBasedActionTestCase extends AbstractDtoBasedActionTestCase
{
/** @var DummyAction */
protected $action;

protected function setUp(): void
Expand Down
19 changes: 0 additions & 19 deletions Tests/Controller/DummyAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,21 @@ class DummyAction extends AbstractDtoBasedAction
{
use EntityManagerTrait;

/**
* @param Request $request
*/
public function doValidateJsonSchema(Request $request): void
{
$this->validateJsonSchema($request);
}

/**
* @param DtoInterface $dto
* @param Constraint|Constraint[]|null $constraints
* @param array|null $groups
*/
public function doValidateDto(DtoInterface $dto, Constraint|array|null $constraints = null, array $groups = null): void
{
$this->validateDto($dto, $constraints, $groups);
}

/**
* @param mixed $entity
* @param Constraint|Constraint[]|null $constraints
* @param array|null $groups
*/
public function doValidateEntity(mixed $entity, Constraint|array|null $constraints = null, array $groups = null): void
{
$this->validateEntity($entity, $constraints, $groups);
}

/**
* @param Request $request
* @param object|null $objectToPopulate
*
* @return DtoInterface
*/
public function doGetDtoFromRequest(Request $request, object $objectToPopulate = null): DtoInterface
{
return $this->getDtoFromRequest($request, $objectToPopulate);
Expand Down
4 changes: 0 additions & 4 deletions Tests/EventListener/Console/ConsoleErrorListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,8 @@

final class ConsoleErrorListenerTest extends TestCase
{
/** @var InputInterface|MockObject */
private InputInterface|MockObject $input;

/** @var OutputInterface|MockObject */
private OutputInterface|MockObject $output;

private ConsoleErrorListener $subscriber;

protected function setUp(): void
Expand Down
8 changes: 0 additions & 8 deletions Tests/EventListener/JWT/JwtRefreshSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,10 @@

final class JwtRefreshSubscriberTest extends TestCase
{
/** @var RefreshEvent|MockObject */
private RefreshEvent|MockObject $refreshEvent;

/** @var TokenInterface|MockObject */
private TokenInterface|MockObject $token;

/** @var RefreshToken|MockObject */
private RefreshToken|MockObject $refreshToken;

/** @var CredentialsInterface|MockObject */
private CredentialsInterface|MockObject $user;

private JwtRefreshSubscriber $subscriber;

protected function setUp(): void
Expand Down
85 changes: 70 additions & 15 deletions Tests/EventListener/JWT/JwtSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@

final class JwtSubscriberTest extends TestCase
{
/** @var TranslatorInterface|MockObject */
private TranslatorInterface|MockObject $translator;

private JwtSubscriber $subscriber;

protected function setUp(): void
Expand Down Expand Up @@ -64,21 +62,17 @@ public function testGetSubscribedEvents(): void
self::assertSame($expected, $actual);
}

/**
* @param MockObject|AuthenticationFailureEvent|string $event
* @param string $message
*
* @dataProvider dataProviderForTestOnAuthenticationFailureResponse
*/
public function testOnAuthenticationFailureResponse(MockObject|AuthenticationFailureEvent|string $event, string $message): void
public function testOnAuthenticationFailureResponse(): void
{
$this->translator
->expects(self::once())
->method('trans')
->with($message)
->with('unauthorised_user_message')
->willReturn('translated message')
;

$event = $this->createMock(AuthenticationFailureEvent::class);

$event
->expects(self::once())
->method('setResponse')
Expand All @@ -91,11 +85,72 @@ public function testOnAuthenticationFailureResponse(MockObject|AuthenticationFai
$this->subscriber->onAuthenticationFailureResponse($event);
}

public function dataProviderForTestOnAuthenticationFailureResponse(): iterable
public function testOnJWTInvalidEvent(): void
{
$this->translator
->expects(self::once())
->method('trans')
->with('invalid_jwt_token_message')
->willReturn('translated message')
;

$event = $this->createMock(JWTInvalidEvent::class);

$event
->expects(self::once())
->method('setResponse')
->with($this->callback(static function (JsonResponse $response) {
return '{"error":"unauthorised_user","errorDescription":"translated message"}' === $response->getContent()
&& JsonResponse::HTTP_UNAUTHORIZED === $response->getStatusCode();
}))
;

$this->subscriber->onAuthenticationFailureResponse($event);
}

public function testOnJWTNotFoundEvent(): void
{
$this->translator
->expects(self::once())
->method('trans')
->with('not_found_jwt_token_message')
->willReturn('translated message')
;

$event = $this->createMock(JWTNotFoundEvent::class);

$event
->expects(self::once())
->method('setResponse')
->with($this->callback(static function (JsonResponse $response) {
return '{"error":"unauthorised_user","errorDescription":"translated message"}' === $response->getContent()
&& JsonResponse::HTTP_UNAUTHORIZED === $response->getStatusCode();
}))
;

$this->subscriber->onAuthenticationFailureResponse($event);
}

public function testOnJWTExpiredEvent(): void
{
yield [$this->createMock(AuthenticationFailureEvent::class), 'unauthorised_user_message'];
yield [$this->createMock(JWTInvalidEvent::class), 'invalid_jwt_token_message'];
yield [$this->createMock(JWTNotFoundEvent::class), 'not_found_jwt_token_message'];
yield [$this->createMock(JWTExpiredEvent::class), 'expired_jwt_token_message'];
$this->translator
->expects(self::once())
->method('trans')
->with('expired_jwt_token_message')
->willReturn('translated message')
;

$event = $this->createMock(JWTExpiredEvent::class);

$event
->expects(self::once())
->method('setResponse')
->with($this->callback(static function (JsonResponse $response) {
return '{"error":"unauthorised_user","errorDescription":"translated message"}' === $response->getContent()
&& JsonResponse::HTTP_UNAUTHORIZED === $response->getStatusCode();
}))
;

$this->subscriber->onAuthenticationFailureResponse($event);
}
}
2 changes: 0 additions & 2 deletions Tests/EventListener/JWT/TokenBlackListSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@

final class TokenBlackListSubscriberTest extends TestCase
{
/** @var JwtBlackListService|MockObject */
private JwtBlackListService|MockObject $tokenBlackListService;

private TokenBlackListSubscriber $subscriber;

protected function setUp(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,14 @@ final class ApiExceptionFormatterListenerTest extends TestCase
{
private const API_HOST = 'https://test.com';

/** @var SerializerInterface|MockObject */
private SerializerInterface|MockObject $serializer;

/** @var ClientInterface|MockObject */
private ClientInterface|MockObject $sentryClient;

/** @var TranslatorInterface|MockObject */
private TranslatorInterface|MockObject $translator;

/** @var Request|MockObject */
private Request|MockObject $request;

/** @var JsonResponse|MockObject */
private JsonResponse|MockObject $response;

/** @var HttpKernelInterface|MockObject */
private HttpKernelInterface|MockObject $kernel;

/** @var ExceptionResponseProcessorInterface|MockObject */
private ExceptionResponseProcessorInterface|MockObject $exceptionResponseProcessor;

/** @var ExceptionResponseFactory|MockObject */
private ExceptionResponseFactory|MockObject $exceptionResponseFactory;

private ApiExceptionFormatterListener $exceptionFormatterListener;

protected function setUp(): void
Expand Down
Loading