Skip to content

Commit

Permalink
update pipelines
Browse files Browse the repository at this point in the history
  • Loading branch information
LauLaman committed Dec 9, 2022
1 parent 4608a8e commit 1ab46ef
Show file tree
Hide file tree
Showing 19 changed files with 97,944 additions and 58,492 deletions.
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
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": "^8.0",
"php": "^8.1",
"laulamanapps/apple-passbook": "^1.1",
"ext-openssl": "*"
},
"require-dev": {
"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",
"symfony/http-foundation": "^5.4 || ^6.0",
"symfony/routing": "^5.4 || ^6.0",
"symfony/event-dispatcher": "^5.4 || ^6.0",
"symfony/framework-bundle": "^5.4 || ^6.0",
"symfony/yaml": "^5.4 || ^6.0",
"symfony/browser-kit": "^5.4 || ^6.0",
"matthiasnoback/symfony-config-test": "^4.1",
"ext-zip": "*"
},
"suggest": {
"symfony/http-foundation": "^6.0",
"symfony/routing": "^6.0",
"symfony/event-dispatcher": "^6.0",
"symfony/framework-bundle": "^6.0"
"symfony/http-foundation": "^5.4 || ^6.0",
"symfony/routing": "^5.4 || ^6.0",
"symfony/event-dispatcher": "^5.4 || ^6.0",
"symfony/framework-bundle": "^5.4 || ^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
4 changes: 2 additions & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<php>
<ini name="error_reporting" value="-1" />
<env name="KERNEL_CLASS" value="LauLamanApps\ApplePassbookBundle\Tests\Functional\TestKernel" />
<env name="APP_ENV" value="test" />
<env name="APP_DEBUG" value="1" />
<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>
Expand Down
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

0 comments on commit 1ab46ef

Please sign in to comment.