Skip to content

Commit

Permalink
Merge branch 'test-refactoring'
Browse files Browse the repository at this point in the history
  • Loading branch information
floriankraemer committed Mar 16, 2024
2 parents d3a630c + 33fa98b commit a4f29de
Show file tree
Hide file tree
Showing 79 changed files with 806 additions and 484 deletions.
19 changes: 11 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: ['7.4', '8.0']
php-version: ['8.0', '8.1', '8.2', '8.3']

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
with:
fetch-depth: 1

Expand All @@ -26,35 +26,38 @@ jobs:

- name: Composer install
run: |
if [[ ${{ matrix.prefer-lowest == '7.4' }} ]]; then
if [[ ${{ matrix.prefer-lowest == '8.3' }} ]]; then
composer update --prefer-lowest --prefer-stable
else
composer install
fi
- name: Run PHPUnit
run: |
if [[ ${{ matrix.php-version }} == '7.4' ]]; then
if [[ ${{ matrix.php-version }} == '8.3' ]]; then
bin/phpunit --coverage-clover=coverage.xml
else
bin/phpunit
fi
- name: Code Coverage Report
if: success() && matrix.php-version == '7.4'
uses: codecov/codecov-action@v1
if: success() && matrix.php-version == '8.3'
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: phauthentic/authentication

validation:
name: Coding Standard & Static Analysis
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.3'
extensions: json, pdo, ldap
coverage: none
tools: pecl
Expand Down
4 changes: 2 additions & 2 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ build:
tests-php74:
environment:
php:
version: '7.4'
version: '8.0'
ini:
phar.readonly: 'Off'
pecl_extensions:
Expand All @@ -18,7 +18,7 @@ build:
tests-php80:
environment:
php:
version: '8.0'
version: '8.3'
ini:
phar.readonly: 'Off'
pecl_extensions:
Expand Down
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ language: php
php:
- 7.4
- 8.0
- 8.1
- 8.2
- 8.3

sudo: false

Expand Down
23 changes: 8 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,23 @@
"library"
],
"require": {
"php": "^7.4|^8.0",
"php": "^8.0",
"ext-json": "*",
"phauthentic/password-hashers": "^2.0",
"psr/http-factory": "^1.0",
"psr/http-message": "~1.0",
"psr/http-server-handler": "~1.0",
"psr/http-server-middleware": "^1.0",
"ext-json": "*"
"psr/http-server-middleware": "^1.0"
},
"require-dev": {
"ext-pdo": "*",
"dms/phpunit-arraysubset-asserts": "^0.3.0",
"firebase/php-jwt": "~4.0",
"firebase/php-jwt": "6.*",
"misantron/dbunit": "dev-master",
"roave/security-advisories": "dev-master",
"laminas/laminas-diactoros": "^2.5.0"
"nyholm/psr7": "^1.8",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3.9"
},
"suggest": {
"firebase/php-jwt": "If you want to use the JWT adapter add this dependency",
Expand All @@ -47,15 +49,6 @@
}
],
"scripts": {
"post-install-cmd": [
"php config/composer_post_install.php"
],
"post-update-cmd": [
"php config/composer_post_install.php"
],
"phive": [
"php ./config/composer_phive.php"
],
"check": [
"@cs-check",
"@test"
Expand Down
33 changes: 33 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: '3.8'

services:
php:
build: ./docker/php
container_name: phpunit-container
volumes:
- .:/app
working_dir: /app
command: "tail -f /dev/null"
depends_on:
- mysql
networks:
- phpnet
environment:
PDO_DB_DSN: "mysql:host=mysql;dbname=test"

mysql:
image: mysql:latest
container_name: mysql-container
environment:
MYSQL_ROOT_PASSWORD: changeme
MYSQL_DATABASE: test
MYSQL_USER: test
MYSQL_PASSWORD: changeme
ports:
- "3306:3306"
networks:
- phpnet

networks:
phpnet:
driver: bridge
14 changes: 14 additions & 0 deletions docker/php/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM php:8.3-cli

RUN apt-get update
RUN apt-get install -y libzip-dev zip git

RUN pear update-channels \
&& pecl update-channels \
&& pecl install xdebug redis

RUN docker-php-ext-install pdo_mysql zip
RUN docker-php-ext-enable pdo_mysql zip redis xdebug

# Install Composer globally
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
73 changes: 33 additions & 40 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,42 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
colors="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="./tests/bootstrap.php"
>
<php>
<ini name="memory_limit" value="-1"/>
<ini name="apc.enable_cli" value="1"/>
</php>

<!-- Add any additional test suites you want to run here -->
<testsuites>
<testsuite name="authentication">
<directory>tests/TestCase/</directory>
</testsuite>
<!-- Add plugin test suites here. -->
</testsuites>

<logging>
<log type="coverage-html" target="./tmp/tests/report" lowUpperBound="35" highLowerBound="70"/>
<!--<log type="coverage-clover" target="./tmp/tests/coverage.xml"/>-->
<!--<log type="coverage-php" target="/tmp/coverage.serialized"/>-->
<!--<log type="coverage-text" target="php://stdout" showUncoveredFiles="false"/>-->
<!--<log type="json" target="/tmp/logfile.json"/>-->
<!--<log type="tap" target="/tmp/logfile.tap"/>-->
<!--<log type="junit" target="/tmp/logfile.xml" logIncompleteSkipped="false"/>-->
<!--<log type="testdox-html" target=".//tmp/tests/testdox.html"/>-->
<!--<log type="testdox-text" target=".//tmp/tests/testdox.txt"/>-->
</logging>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src/</directory>
<exclude>
<file>src/Identifier/Ldap/ExtensionAdapter.php</file>
</exclude>
</whitelist>
</filter>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" processIsolation="false" stopOnFailure="false" bootstrap="./tests/bootstrap.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src/</directory>
</include>
<exclude>
<file>src/Identifier/Ldap/ExtensionAdapter.php</file>
</exclude>
<report>
<html outputDirectory="./tmp/tests/report" lowUpperBound="35" highLowerBound="70"/>
</report>
</coverage>
<php>
<ini name="memory_limit" value="-1"/>
<ini name="apc.enable_cli" value="1"/>
</php>
<!-- Add any additional test suites you want to run here -->
<testsuites>
<testsuite name="authentication">
<directory>tests/TestCase/</directory>
</testsuite>
<!-- Add plugin test suites here. -->
</testsuites>
<logging>
<!--<log type="coverage-clover" target="./tmp/tests/coverage.xml"/>-->
<!--<log type="coverage-php" target="/tmp/coverage.serialized"/>-->
<!--<log type="coverage-text" target="php://stdout" showUncoveredFiles="false"/>-->
<!--<log type="json" target="/tmp/logfile.json"/>-->
<!--<log type="tap" target="/tmp/logfile.tap"/>-->
<!--<log type="junit" target="/tmp/logfile.xml" logIncompleteSkipped="false"/>-->
<!--<log type="testdox-html" target=".//tmp/tests/testdox.html"/>-->
<!--<log type="testdox-text" target=".//tmp/tests/testdox.txt"/>-->
</logging>
</phpunit>
1 change: 0 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
[![Scrutinizer Coverage](https://img.shields.io/scrutinizer/coverage/g/Phauthentic/authentication/2.0.svg?style=flat-square)](https://scrutinizer-ci.com/g/Phauthentic/authentication/?branch=2.0)
[![Code Quality](https://img.shields.io/scrutinizer/g/Phauthentic/authentication/2.0.svg?style=flat-square)](https://scrutinizer-ci.com/g/Phauthentic/authentication/?branch=2.0)
![phpstan Level 8](https://img.shields.io/badge/phpstan-Level%208-brightgreen?style=flat-square)
![php 7.4](https://img.shields.io/badge/php-7.4-blue?style=flat-square)
![php 8.0](https://img.shields.io/badge/php-8.0-blue?style=flat-square)


Expand Down
14 changes: 14 additions & 0 deletions src/AuthenticationException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace Phauthentic\Authentication;

use Exception;

/**
* Authentication Exception
*/
class AuthenticationException extends Exception
{
}
4 changes: 3 additions & 1 deletion src/AuthenticationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* @license https://opensource.org/licenses/mit-license.php MIT License
*/

declare(strict_types=1);

namespace Phauthentic\Authentication;

use ArrayAccess;
Expand Down Expand Up @@ -138,7 +140,7 @@ public function authenticate(ServerRequestInterface $request): bool
return true;
}

if (!$result->isValid()) {
if ($result->isValid() === false) {
if ($authenticator instanceof StatelessInterface) {
$authenticator->unauthorizedChallenge($request);
}
Expand Down
2 changes: 2 additions & 0 deletions src/AuthenticationServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* @license https://opensource.org/licenses/mit-license.php MIT License
*/

declare(strict_types=1);

namespace Phauthentic\Authentication;

use Phauthentic\Authentication\Authenticator\AuthenticatorInterface;
Expand Down
2 changes: 2 additions & 0 deletions src/AuthenticationServiceProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* @license https://opensource.org/licenses/mit-license.php MIT License
*/

declare(strict_types=1);

namespace Phauthentic\Authentication;

use Psr\Http\Message\ServerRequestInterface;
Expand Down
2 changes: 2 additions & 0 deletions src/Authenticator/AbstractAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* @license https://opensource.org/licenses/mit-license.php MIT License
*/

declare(strict_types=1);

namespace Phauthentic\Authentication\Authenticator;

use Phauthentic\Authentication\Identifier\IdentifierInterface;
Expand Down
2 changes: 2 additions & 0 deletions src/Authenticator/AuthenticatorCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* @license https://opensource.org/licenses/mit-license.php MIT License
*/

declare(strict_types=1);

namespace Phauthentic\Authentication\Authenticator;

use ArrayIterator;
Expand Down
2 changes: 2 additions & 0 deletions src/Authenticator/AuthenticatorCollectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* @license https://opensource.org/licenses/mit-license.php MIT License
*/

declare(strict_types=1);

namespace Phauthentic\Authentication\Authenticator;

use IteratorAggregate;
Expand Down
2 changes: 2 additions & 0 deletions src/Authenticator/AuthenticatorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* @license https://opensource.org/licenses/mit-license.php MIT License
*/

declare(strict_types=1);

namespace Phauthentic\Authentication\Authenticator;

use Psr\Http\Message\ServerRequestInterface;
Expand Down
9 changes: 7 additions & 2 deletions src/Authenticator/CookieAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* @license https://opensource.org/licenses/mit-license.php MIT License
*/

declare(strict_types=1);

namespace Phauthentic\Authentication\Authenticator;

use ArrayAccess;
Expand Down Expand Up @@ -126,8 +128,11 @@ public function authenticate(ServerRequestInterface $request): ResultInterface
* {@inheritDoc}
* @throws \JsonException
*/
public function persistIdentity(ServerRequestInterface $request, ResponseInterface $response, ArrayAccess $data): ResponseInterface
{
public function persistIdentity(
ServerRequestInterface $request,
ResponseInterface $response,
ArrayAccess $data
): ResponseInterface {
$field = $this->rememberMeField;
$bodyData = $request->getParsedBody();

Expand Down
2 changes: 2 additions & 0 deletions src/Authenticator/CredentialFieldsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* @license https://opensource.org/licenses/mit-license.php MIT License
*/

declare(strict_types=1);

namespace Phauthentic\Authentication\Authenticator;

use Phauthentic\Authentication\Identifier\IdentifierInterface;
Expand Down
Loading

0 comments on commit a4f29de

Please sign in to comment.