Skip to content

Commit

Permalink
Merge pull request #242 from l0gicgate/add-github-actions
Browse files Browse the repository at this point in the history
Add GitHub Actions
  • Loading branch information
l0gicgate authored Oct 2, 2021
2 parents 7a2d344 + 0cde64b commit 23888ed
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 37 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Tests

on: [push, pull_request]

jobs:
tests:
name: Tests PHP ${{ matrix.php }}
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.experimental }}
strategy:
fail-fast: false
matrix:
php: [7.3, 7.4, 8.0]
experimental: [false]
include:
- php: 8.0
analysis: true
- php: 8.1
experimental: true

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: xdebug

- name: Install dependencies with Composer
uses: ramsey/composer-install@v1

- name: Coding standards
if: matrix.analysis
run: vendor/bin/phpcs

- name: Static analysis
if: matrix.analysis
run: vendor/bin/phpstan

- name: Tests
run: vendor/bin/phpunit --coverage-clover clover.xml

- name: Upload coverage results to Coveralls
if: matrix.analysis
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
composer require php-coveralls/php-coveralls -n -W
vendor/bin/php-coveralls --coverage_clover=clover.xml -v
25 changes: 0 additions & 25 deletions .travis.yml

This file was deleted.

6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
}
],
"require": {
"php": "^7.2 || ^8.0",
"php": "^7.3 || ^8.0",
"ext-json": "*",
"monolog/monolog": "^2.3",
"php-di/php-di": "^6.3",
Expand All @@ -31,9 +31,11 @@
},
"require-dev": {
"jangregor/phpstan-prophecy": "^0.8.1",
"phpspec/prophecy-phpunit": "^2.0",
"phpstan/extension-installer": "^1.1.0",
"phpstan/phpstan": "^0.12.99",
"phpunit/phpunit": "^8.0 || ^9.0"
"phpunit/phpunit": "^9.5.10",
"squizlabs/php_codesniffer": "^3.6"
},
"config": {
"process-timeout": 0,
Expand Down
17 changes: 17 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<ruleset name="Slim coding standard">
<description>Slim coding standard</description>

<!-- display progress -->
<arg value="p"/>
<!-- use colors in output -->
<arg name="colors"/>

<!-- inherit rules from: -->
<rule ref="PSR2"/>
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>

<!-- Paths to check -->
<file>src</file>
<file>tests</file>
</ruleset>
2 changes: 2 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
parameters:
level: 4
paths:
- src
5 changes: 3 additions & 2 deletions src/Application/Actions/User/UserAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ abstract class UserAction extends Action
* @param LoggerInterface $logger
* @param UserRepository $userRepository
*/
public function __construct(LoggerInterface $logger,
UserRepository $userRepository
public function __construct(
LoggerInterface $logger,
UserRepository $userRepository
) {
parent::__construct($logger);
$this->userRepository = $userRepository;
Expand Down
3 changes: 1 addition & 2 deletions src/Application/Handlers/HttpErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ protected function respond(): Response
}
}

if (
!($exception instanceof HttpException)
if (!($exception instanceof HttpException)
&& $exception instanceof Throwable
&& $this->displayErrorDetails
) {
Expand Down
8 changes: 7 additions & 1 deletion src/Application/Handlers/ShutdownHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@ public function __invoke()
}

$exception = new HttpInternalServerErrorException($this->request, $message);
$response = $this->errorHandler->__invoke($this->request, $exception, $this->displayErrorDetails, false, false);
$response = $this->errorHandler->__invoke(
$this->request,
$exception,
$this->displayErrorDetails,
false,
false,
);

$responseEmitter = new ResponseEmitter();
$responseEmitter->emit($response);
Expand Down
5 changes: 4 additions & 1 deletion src/Application/ResponseEmitter/ResponseEmitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ public function emit(ResponseInterface $response): void
$response = $response
->withHeader('Access-Control-Allow-Credentials', 'true')
->withHeader('Access-Control-Allow-Origin', $origin)
->withHeader('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type, Accept, Origin, Authorization')
->withHeader(
'Access-Control-Allow-Headers',
'X-Requested-With, Content-Type, Accept, Origin, Authorization',
)
->withHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, PATCH, DELETE, OPTIONS')
->withHeader('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0')
->withAddedHeader('Cache-Control', 'post-check=0, pre-check=0')
Expand Down
2 changes: 1 addition & 1 deletion src/Application/Settings/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ public function get(string $key = '')
{
return (empty($key)) ? $this->settings : $this->settings[$key];
}
}
}
2 changes: 1 addition & 1 deletion src/Application/Settings/SettingsInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ interface SettingsInterface
* @return mixed
*/
public function get(string $key = '');
}
}
2 changes: 1 addition & 1 deletion tests/Application/Actions/User/ViewUserActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function testActionThrowsUserNotFoundException()
$responseFactory = $app->getResponseFactory();

$errorHandler = new HttpErrorHandler($callableResolver, $responseFactory);
$errorMiddleware = new ErrorMiddleware($callableResolver, $responseFactory, true, false ,false);
$errorMiddleware = new ErrorMiddleware($callableResolver, $responseFactory, true, false, false);
$errorMiddleware->setDefaultErrorHandler($errorHandler);

$app->add($errorMiddleware);
Expand Down
3 changes: 3 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use DI\ContainerBuilder;
use Exception;
use PHPUnit\Framework\TestCase as PHPUnit_TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\App;
use Slim\Factory\AppFactory;
Expand All @@ -16,6 +17,8 @@

class TestCase extends PHPUnit_TestCase
{
use ProphecyTrait;

/**
* @return App
* @throws Exception
Expand Down
1 change: 0 additions & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
<?php
require __DIR__ . '/../vendor/autoload.php';

0 comments on commit 23888ed

Please sign in to comment.