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

Bump to Symfony 6 and PHP 8 #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
39 changes: 33 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,66 @@ on:
jobs:
build-unit:
name: Unit tests
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
strategy:
matrix:
php-versions: [ '8.1', '8.2' ]
steps:
- name: Checkout code
uses: actions/checkout@v1

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: openssl

- name: Install composer dependencies
run: composer install --prefer-dist --ignore-platform-reqs

- name: Run PHPUnit tests
run: php7.3 bin/phpunit-8.4.3.phar --testsuite=unit
run: php bin/phpunit-9.5.20.phar --testsuite=unit

build-functional:
name: Functional tests
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
strategy:
matrix:
php-versions: [ '8.1', '8.2' ]
steps:
- name: Checkout code
uses: actions/checkout@v1

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: openssl

- name: Install composer dependencies
run: composer install --prefer-dist --ignore-platform-reqs

- name: Run PHPUnit tests
run: php7.3 bin/phpunit-8.4.3.phar --testsuite=functional
run: php bin/phpunit-9.5.20.phar --testsuite=functional

build-infection:
name: Infection tests
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
strategy:
matrix:
php-versions: [ '8.1', '8.2' ]
steps:
- name: Checkout code
uses: actions/checkout@v1

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: openssl

- name: Install composer dependencies
run: composer install --prefer-dist --ignore-platform-reqs

- name: Run Infection
run: php7.3 bin/infection.phar --min-msi=70 --show-mutations
run: php bin/infection.phar --min-msi=50 --show-mutations
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ checks:
build:
environment:
php:
version: 7.3
version: 8.1
tests:
override:
-
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ coverage:
rm -rf coverage; bin/phpunit-8.4.3.phar --coverage-html=coverage/ --coverage-clover=coverage/clover.xml

tests:
bin/phpunit-8.4.3.phar
bin/phpunit-9.5.20.phar

tests-unit:
bin/phpunit-8.4.3.phar --testsuite unit
bin/phpunit-9.5.20.phar --testsuite unit

tests-integration:
bin/phpunit-8.4.3.phar --testsuite integration
bin/phpunit-9.5.20.phar --testsuite integration

tests-functional:
bin/phpunit-8.4.3.phar --testsuite functional
bin/phpunit-9.5.20.phar --testsuite functional

tests-infection:
./bin/infection.phar
Expand Down
Binary file modified bin/infection.phar
Binary file not shown.
58,255 changes: 0 additions & 58,255 deletions bin/phpunit-8.4.3.phar

This file was deleted.

97,632 changes: 97,632 additions & 0 deletions bin/phpunit-9.5.20.phar

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,25 @@
}
},
"require": {
"php": ">=7.3",
"php": "^8.1",
"laulamanapps/apple-passbook": "^1.1",
"ext-openssl": "*"
},
"require-dev": {
"symfony/http-foundation": "^5.1",
"symfony/routing": "^5.1",
"symfony/event-dispatcher": "^5.1",
"symfony/framework-bundle": "^5.1",
"symfony/yaml": "^5.1",
"symfony/browser-kit": "^5.1",
"symfony/http-foundation": "^6.0",
"symfony/routing": "^6.0",
"symfony/event-dispatcher": "^6.0",
"symfony/framework-bundle": "^6.0",
"symfony/yaml": "^6.0",
"symfony/browser-kit": "^6.0",
"matthiasnoback/symfony-config-test": "^4.1",
"ext-zip": "*"
},
"suggest": {
"symfony/http-foundation": "^5.1",
"symfony/routing": "^5.1",
"symfony/event-dispatcher": "^5.1",
"symfony/framework-bundle": "^5.1"
"symfony/http-foundation": "^6.0",
"symfony/routing": "^6.0",
"symfony/event-dispatcher": "^6.0",
"symfony/framework-bundle": "^6.0"
},
"config": {
"bin-dir": "bin"
Expand Down
2 changes: 1 addition & 1 deletion infection.json.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
]
},
"phpUnit": {
"customPath": "bin\/phpunit-8.4.3.phar"
"customPath": "bin\/phpunit-9.5.20.phar"
},
"logs": {
"text": "infection.log"
Expand Down
8 changes: 8 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
processIsolation = "false"
stopOnFailure = "false"
bootstrap = "phpunit.bootstrap.php" >
<php>
<ini name="error_reporting" value="-1" />
<env name="KERNEL_CLASS" value="LauLamanApps\ApplePassbookBundle\Tests\Functional\TestKernel" />
<env name="APP_ENV" value="test" force="true"/>
<env name="APP_DEBUG" value="0" />
<env name="SHELL_VERBOSITY" value="-1" />
<!-- define your env variables for the test env here -->
</php>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
Expand Down
3 changes: 2 additions & 1 deletion src/ApplePassbookBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
namespace LauLamanApps\ApplePassbookBundle;

use LauLamanApps\ApplePassbookBundle\DependencyInjection\ApplePassbookExtension;
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
use Symfony\Component\HttpKernel\Bundle\Bundle;

final class ApplePassbookBundle extends Bundle
{
public function getContainerExtension()
public function getContainerExtension(): ?ExtensionInterface
{
if (null === $this->extension) {
$this->extension = new ApplePassbookExtension();
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/V1/PassKit/AuthenticationToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ trait AuthenticationToken
{
protected function getAuthenticationToken(Request $request): string
{
return str_replace('ApplePass ', '', $request->headers->get('Authorization'));
return str_replace('ApplePass ', '', $request->headers->get('Authorization', ''));
}
}
69 changes: 69 additions & 0 deletions src/Controller/V1/PassKit/Device/RegisterController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

declare(strict_types=1);

namespace LauLamanApps\ApplePassbookBundle\Controller\V1\PassKit\Device;

use LauLamanApps\ApplePassbookBundle\Controller\V1\PassKit\AuthenticationToken;
use LauLamanApps\ApplePassbookBundle\Event\DeviceRegisteredEvent;
use LauLamanApps\ApplePassbookBundle\Event\Status;
use LogicException;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

/**
* @Route("/v1/devices/{deviceLibraryIdentifier}/registrations/{passTypeIdentifier}/{serialNumber}/", methods={"POST"})
*/
class RegisterController
{
use AuthenticationToken;

/**
* @var EventDispatcherInterface
*/
private $eventDispatcher;

public function __construct(EventDispatcherInterface $eventDispatcher)
{
$this->eventDispatcher = $eventDispatcher;
}

public function __invoke(
Request $request,
string $deviceLibraryIdentifier,
string $passTypeIdentifier,
string $serialNumber
): JsonResponse {
$event = new DeviceRegisteredEvent(
$deviceLibraryIdentifier,
$passTypeIdentifier,
$serialNumber,
$this->getAuthenticationToken($request),
json_decode($request->getContent())->pushToken
);

/** @var Status $status */
$status = $this->eventDispatcher->dispatch($event)->getStatus();

if ($status->isUnhandled()) {
throw new LogicException('DeviceRegisteredEvent was not handled. Please implement a listener for this event.');
}

if ($status->isNotAuthorized()) {
return new JsonResponse([], Response::HTTP_UNAUTHORIZED);
}

if ($status->isAlreadyRegistered()) {
return new JsonResponse([], Response::HTTP_OK);
}

if ($status->isSuccessful()) {
return new JsonResponse([], Response::HTTP_CREATED);
}

throw new LogicException('DeviceRegisteredEvent was not handled correctly. Unexpected status was set.');
}
}
61 changes: 61 additions & 0 deletions src/Controller/V1/PassKit/Device/SerialNumbersController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

declare(strict_types=1);

namespace LauLamanApps\ApplePassbookBundle\Controller\V1\PassKit\Device;

use DateTimeImmutable;
use LauLamanApps\ApplePassbookBundle\Controller\V1\PassKit\AuthenticationToken;
use LauLamanApps\ApplePassbookBundle\Event\DeviceRequestUpdatedPassesEvent;
use LogicException;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

/**
* @Route("/v1/devices/{deviceLibraryIdentifier}/registrations/{passTypeIdentifier}", methods={"GET"})
*/
class SerialNumbersController
{
use AuthenticationToken;

/**
* @var EventDispatcherInterface
*/
private $eventDispatcher;

public function __construct(EventDispatcherInterface $eventDispatcher)
{
$this->eventDispatcher = $eventDispatcher;
}

public function __invoke(
string $deviceLibraryIdentifier,
string $passTypeIdentifier
): JsonResponse {
$event = new DeviceRequestUpdatedPassesEvent($deviceLibraryIdentifier, $passTypeIdentifier);
$this->eventDispatcher->dispatch($event);

if ($event->getStatus()->isUnhandled()) {
throw new LogicException('DeviceRequestUpdatedPassesEvent was not handled. Please implement a listener for this event.');
}

if ($event->getStatus()->isNotFound()) {
return new JsonResponse([], Response::HTTP_NO_CONTENT);
}

if ($event->getStatus()->isNotModified()) {
return new JsonResponse([], Response::HTTP_NOT_MODIFIED);
}

if ($event->getStatus()->isSuccessful()) {
return new JsonResponse([
'lastUpdated' => $event->getLastUpdated()->format(DateTimeImmutable::ATOM),
'serialNumbers' => $event->getSerialNumbers()
]);
}

throw new LogicException('DeviceRequestUpdatedPassesEvent was not handled correctly. Unexpected status was set.');
}
}
64 changes: 64 additions & 0 deletions src/Controller/V1/PassKit/Device/UnregisterController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

declare(strict_types=1);

namespace LauLamanApps\ApplePassbookBundle\Controller\V1\PassKit\Device;

use LauLamanApps\ApplePassbookBundle\Controller\V1\PassKit\AuthenticationToken;
use LauLamanApps\ApplePassbookBundle\Event\DeviceUnregisteredEvent;
use LauLamanApps\ApplePassbookBundle\Event\Status;
use LogicException;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

/**
* @Route("/v1/devices/{deviceLibraryIdentifier}/registrations/{passTypeIdentifier}/{serialNumber}", methods={"DELETE"})
*/
class UnregisterController
{
use AuthenticationToken;

/**
* @var EventDispatcherInterface
*/
private $eventDispatcher;

public function __construct(EventDispatcherInterface $eventDispatcher)
{
$this->eventDispatcher = $eventDispatcher;
}

public function __invoke(
Request $request,
string $deviceLibraryIdentifier,
string $passTypeIdentifier,
string $serialNumber
): JsonResponse {
$event = new DeviceUnregisteredEvent(
$deviceLibraryIdentifier,
$passTypeIdentifier,
$serialNumber,
$this->getAuthenticationToken($request)
);

/** @var Status $status */
$status = $this->eventDispatcher->dispatch($event)->getStatus();

if ($status->isUnhandled()) {
throw new LogicException('DeviceUnregisteredEvent was not handled. Please implement a listener for this event.');
}

if ($status->isNotAuthorized()) {
return new JsonResponse([], Response::HTTP_UNAUTHORIZED);
}

if ($status->isSuccessful()) {
return new JsonResponse([], Response::HTTP_OK);
}

throw new LogicException('DeviceUnregisteredEvent was not handled correctly. Unexpected status was set.');
}
}
Loading