From 23f22ba6281047fbf3e9f612d2d9c0806cdf6f53 Mon Sep 17 00:00:00 2001 From: poprazvan17 Date: Mon, 10 Jul 2023 12:44:09 +0300 Subject: [PATCH 1/6] implemented unit tests, added phpcs, static-analysis and run unit test github actions --- .github/workflows/cs-tests.yml | 46 ++++++++++ .github/workflows/static-analysis.yml | 46 ++++++++++ .github/workflows/unit-tests.yaml | 47 ++++++++++ .gitignore | 2 + composer.json | 24 ++++-- phpcs.xml | 20 +++++ phpunit.xml | 10 +++ psalm.xml | 15 ++++ src/AuthenticationInterface.php | 19 +---- src/AuthenticationResult.php | 99 ++++++---------------- src/Exception/ExceptionInterface.php | 7 +- src/Exception/InvalidArgumentException.php | 10 +-- src/Exception/RuntimeException.php | 10 +-- src/Exception/UnauthorizedException.php | 13 +-- src/Identity/IdentityInterface.php | 9 +- test/AuthenticationResultTest.php | 20 ----- tests/AuthenticationResultTest.php | 43 ++++++++++ 17 files changed, 287 insertions(+), 153 deletions(-) create mode 100644 .github/workflows/cs-tests.yml create mode 100644 .github/workflows/static-analysis.yml create mode 100644 .github/workflows/unit-tests.yaml create mode 100644 phpcs.xml create mode 100644 phpunit.xml create mode 100644 psalm.xml delete mode 100644 test/AuthenticationResultTest.php create mode 100644 tests/AuthenticationResultTest.php diff --git a/.github/workflows/cs-tests.yml b/.github/workflows/cs-tests.yml new file mode 100644 index 0000000..a04c904 --- /dev/null +++ b/.github/workflows/cs-tests.yml @@ -0,0 +1,46 @@ +on: + - push + +name: Run phpcs checks + +jobs: + mutation: + name: PHP ${{ matrix.php }}-${{ matrix.os }} + + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: + - ubuntu-latest + + php: + - "8.1" + - "8.2" + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: "${{ matrix.php }}" + tools: composer:v2, cs2pr + coverage: none + + - name: Determine composer cache directory + run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV + + - name: Cache dependencies installed with composer + uses: actions/cache@v3 + with: + path: ${{ env.COMPOSER_CACHE_DIR }} + key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: | + php${{ matrix.php }}-composer- + - name: Install dependencies with composer + run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi + + - name: Run phpcs checks + run: vendor/bin/phpcs \ No newline at end of file diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml new file mode 100644 index 0000000..e5dfb02 --- /dev/null +++ b/.github/workflows/static-analysis.yml @@ -0,0 +1,46 @@ +on: + - push + +name: Run static analysis + +jobs: + mutation: + name: PHP ${{ matrix.php }}-${{ matrix.os }} + + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: + - ubuntu-latest + + php: + - "8.1" + - "8.2" + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: "${{ matrix.php }}" + tools: composer:v2, cs2pr + coverage: none + + - name: Determine composer cache directory + run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV + + - name: Cache dependencies installed with composer + uses: actions/cache@v3 + with: + path: ${{ env.COMPOSER_CACHE_DIR }} + key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: | + php${{ matrix.php }}-composer- + - name: Install dependencies with composer + run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi + + - name: Run static analysis + run: vendor/bin/psalm --no-cache --output-format=github --show-info=false --threads=4 \ No newline at end of file diff --git a/.github/workflows/unit-tests.yaml b/.github/workflows/unit-tests.yaml new file mode 100644 index 0000000..e0b3199 --- /dev/null +++ b/.github/workflows/unit-tests.yaml @@ -0,0 +1,47 @@ +on: + - push + +name: Run PHPUnit tests + +jobs: + mutation: + name: PHP ${{ matrix.php }}-${{ matrix.os }} + + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: + - ubuntu-latest + + php: + - "8.1" + - "8.2" + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: "${{ matrix.php }}" + tools: composer:v2, cs2pr + coverage: none + + - name: Determine composer cache directory + run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV + + - name: Cache dependencies installed with composer + uses: actions/cache@v3 + with: + path: ${{ env.COMPOSER_CACHE_DIR }} + key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: | + php${{ matrix.php }}-composer- + + - name: Install dependencies with composer + run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi + + - name: Run PHPUnit tests + run: vendor/bin/phpunit --colors=always \ No newline at end of file diff --git a/.gitignore b/.gitignore index ca12fe7..6a96a2d 100644 --- a/.gitignore +++ b/.gitignore @@ -33,4 +33,6 @@ com_crashlytics_export_strings.xml crashlytics.properties crashlytics-build.properties fabric.properties +.phpunit.result.cache +.phpcs-cache diff --git a/composer.json b/composer.json index 8bca6f1..bad9724 100644 --- a/composer.json +++ b/composer.json @@ -10,12 +10,14 @@ } ], "require": { - "php": "^7.4 || ~8.0.0 || ~8.1.0", + "php": "~8.1.0 || ~8.2.0", "psr/http-message": "^1.0" }, "require-dev": { - "phpunit/phpunit": "^4.8", - "squizlabs/php_codesniffer": "^2.3" + "phpunit/phpunit": "^10.2", + "laminas/laminas-coding-standard": "^2.5", + "squizlabs/php_codesniffer": "3.7.*", + "vimeo/psalm": "^5.13" }, "autoload": { "psr-4": { @@ -24,7 +26,7 @@ }, "autoload-dev": { "psr-4": { - "DotTest\\Authentication\\": "test/" + "DotTest\\Authentication\\": "tests/" } }, "extra": { @@ -35,7 +37,19 @@ }, "config": { "allow-plugins": { - "laminas/laminas-dependency-plugin": true + "laminas/laminas-dependency-plugin": true, + "dealerdirect/phpcodesniffer-composer-installer": true } + }, + "scripts": { + "check": [ + "@cs-check", + "@test" + ], + "cs-check": "phpcs", + "cs-fix": "phpcbf", + "test": "phpunit --colors=always", + "test-coverage": "phpunit --colors=always --coverage-clover clover.xml", + "static-analysis": "psalm --shepherd --stats" } } diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..f28322c --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + src + tests + + + + \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..24843ef --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,10 @@ + + + + + ./tests + + + \ No newline at end of file diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 0000000..6dee3f1 --- /dev/null +++ b/psalm.xml @@ -0,0 +1,15 @@ + + + + + + + + + \ No newline at end of file diff --git a/src/AuthenticationInterface.php b/src/AuthenticationInterface.php index 5620c9a..8be1328 100644 --- a/src/AuthenticationInterface.php +++ b/src/AuthenticationInterface.php @@ -1,11 +1,10 @@ code = (int)$code; + public function __construct(int $code, string $message = '', ?IdentityInterface $identity = null) + { + $this->code = (int) $code; $this->identity = $identity; - $this->message = $message; + $this->message = $message; } - /** - * @return bool - */ public function isValid(): bool { - return ($this->code > 0); + return $this->code > 0; } - /** - * @return bool - */ public function hasIdentity(): bool { return $this->identity instanceof IdentityInterface; } - /** - * @return int - */ public function getCode(): int { return $this->code; } - /** - * @param int $code - */ public function setCode(int $code) { $this->code = $code; } - /** - * @return IdentityInterface - */ public function getIdentity(): ?IdentityInterface { return $this->identity; } - /** - * @param IdentityInterface $identity - */ public function setIdentity(IdentityInterface $identity) { $this->identity = $identity; } - /** - * @return string - */ public function getMessage(): string { return $this->message ?? ''; } - /** - * @param string $message - */ public function setMessage(string $message) { $this->message = $message; diff --git a/src/Exception/ExceptionInterface.php b/src/Exception/ExceptionInterface.php index 9de5798..2da4b86 100644 --- a/src/Exception/ExceptionInterface.php +++ b/src/Exception/ExceptionInterface.php @@ -1,19 +1,16 @@ indentyInterfaceMock = $this->createMock(IdentityInterface::class); + $this->indentyInterfaceMock->method('getId')->will($this->returnValue(10)); + $this->indentyInterfaceMock->method('getName')->willReturn('username'); + $this->subject = new AuthenticationResult(2, 'valid', $this->indentyInterfaceMock); + + parent::setUp(); + } + + public function testAuth() + { + $code = $this->subject->getCode(); + $message = $this->subject->getMessage(); + $name = $this->subject->getIdentity(); + $interface = $this->subject->hasIdentity(); + $isValid = $this->subject->isValid(); + + $this->assertSame(2, $code); + $this->assertSame('valid', $message); + $this->assertSame('username', $name->getName()); + $this->assertSame(10, $name->getId()); + $this->assertTrue($interface); + $this->assertEquals('valid', $message); + $this->assertTrue($isValid); + } +} From 869e5af8289054096f9a0256f4c7de39718d5663 Mon Sep 17 00:00:00 2001 From: poprazvan17 Date: Wed, 12 Jul 2023 11:51:50 +0300 Subject: [PATCH 2/6] implemented unit tests, added phpcs, static-analysis and run unit test github actions --- .github/workflows/cs-tests.yml | 92 +++++++++--------- .github/workflows/static-analysis.yml | 92 +++++++++--------- .github/workflows/unit-tests.yaml | 94 +++++++++---------- composer.json | 104 ++++++++++----------- phpcs.xml | 40 ++++---- phpunit.xml | 20 ++-- psalm.xml | 30 +++--- src/AuthenticationInterface.php | 4 - src/AuthenticationResult.php | 42 +++------ src/Exception/ExceptionInterface.php | 4 - src/Exception/InvalidArgumentException.php | 4 - src/Exception/RuntimeException.php | 4 - src/Exception/UnauthorizedException.php | 4 - tests/AuthenticationResultTest.php | 8 +- 14 files changed, 253 insertions(+), 289 deletions(-) diff --git a/.github/workflows/cs-tests.yml b/.github/workflows/cs-tests.yml index a04c904..dfb8435 100644 --- a/.github/workflows/cs-tests.yml +++ b/.github/workflows/cs-tests.yml @@ -1,46 +1,46 @@ -on: - - push - -name: Run phpcs checks - -jobs: - mutation: - name: PHP ${{ matrix.php }}-${{ matrix.os }} - - runs-on: ${{ matrix.os }} - - strategy: - matrix: - os: - - ubuntu-latest - - php: - - "8.1" - - "8.2" - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Install PHP - uses: shivammathur/setup-php@v2 - with: - php-version: "${{ matrix.php }}" - tools: composer:v2, cs2pr - coverage: none - - - name: Determine composer cache directory - run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV - - - name: Cache dependencies installed with composer - uses: actions/cache@v3 - with: - path: ${{ env.COMPOSER_CACHE_DIR }} - key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: | - php${{ matrix.php }}-composer- - - name: Install dependencies with composer - run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi - - - name: Run phpcs checks - run: vendor/bin/phpcs \ No newline at end of file +on: + - push + +name: Run phpcs checks + +jobs: + mutation: + name: PHP ${{ matrix.php }}-${{ matrix.os }} + + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: + - ubuntu-latest + + php: + - "8.1" + - "8.2" + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: "${{ matrix.php }}" + tools: composer:v2, cs2pr + coverage: none + + - name: Determine composer cache directory + run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV + + - name: Cache dependencies installed with composer + uses: actions/cache@v3 + with: + path: ${{ env.COMPOSER_CACHE_DIR }} + key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: | + php${{ matrix.php }}-composer- + - name: Install dependencies with composer + run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi + + - name: Run phpcs checks + run: vendor/bin/phpcs diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index e5dfb02..525c9c2 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -1,46 +1,46 @@ -on: - - push - -name: Run static analysis - -jobs: - mutation: - name: PHP ${{ matrix.php }}-${{ matrix.os }} - - runs-on: ${{ matrix.os }} - - strategy: - matrix: - os: - - ubuntu-latest - - php: - - "8.1" - - "8.2" - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Install PHP - uses: shivammathur/setup-php@v2 - with: - php-version: "${{ matrix.php }}" - tools: composer:v2, cs2pr - coverage: none - - - name: Determine composer cache directory - run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV - - - name: Cache dependencies installed with composer - uses: actions/cache@v3 - with: - path: ${{ env.COMPOSER_CACHE_DIR }} - key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: | - php${{ matrix.php }}-composer- - - name: Install dependencies with composer - run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi - - - name: Run static analysis - run: vendor/bin/psalm --no-cache --output-format=github --show-info=false --threads=4 \ No newline at end of file +on: + - push + +name: Run static analysis + +jobs: + mutation: + name: PHP ${{ matrix.php }}-${{ matrix.os }} + + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: + - ubuntu-latest + + php: + - "8.1" + - "8.2" + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: "${{ matrix.php }}" + tools: composer:v2, cs2pr + coverage: none + + - name: Determine composer cache directory + run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV + + - name: Cache dependencies installed with composer + uses: actions/cache@v3 + with: + path: ${{ env.COMPOSER_CACHE_DIR }} + key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: | + php${{ matrix.php }}-composer- + - name: Install dependencies with composer + run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi + + - name: Run static analysis + run: vendor/bin/psalm --no-cache --output-format=github --show-info=false --threads=4 diff --git a/.github/workflows/unit-tests.yaml b/.github/workflows/unit-tests.yaml index e0b3199..9f0c3e2 100644 --- a/.github/workflows/unit-tests.yaml +++ b/.github/workflows/unit-tests.yaml @@ -1,47 +1,47 @@ -on: - - push - -name: Run PHPUnit tests - -jobs: - mutation: - name: PHP ${{ matrix.php }}-${{ matrix.os }} - - runs-on: ${{ matrix.os }} - - strategy: - matrix: - os: - - ubuntu-latest - - php: - - "8.1" - - "8.2" - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Install PHP - uses: shivammathur/setup-php@v2 - with: - php-version: "${{ matrix.php }}" - tools: composer:v2, cs2pr - coverage: none - - - name: Determine composer cache directory - run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV - - - name: Cache dependencies installed with composer - uses: actions/cache@v3 - with: - path: ${{ env.COMPOSER_CACHE_DIR }} - key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: | - php${{ matrix.php }}-composer- - - - name: Install dependencies with composer - run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi - - - name: Run PHPUnit tests - run: vendor/bin/phpunit --colors=always \ No newline at end of file +on: + - push + +name: Run PHPUnit tests + +jobs: + mutation: + name: PHP ${{ matrix.php }}-${{ matrix.os }} + + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: + - ubuntu-latest + + php: + - "8.1" + - "8.2" + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: "${{ matrix.php }}" + tools: composer:v2, cs2pr + coverage: none + + - name: Determine composer cache directory + run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV + + - name: Cache dependencies installed with composer + uses: actions/cache@v3 + with: + path: ${{ env.COMPOSER_CACHE_DIR }} + key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: | + php${{ matrix.php }}-composer- + + - name: Install dependencies with composer + run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi + + - name: Run PHPUnit tests + run: vendor/bin/phpunit --colors=always diff --git a/composer.json b/composer.json index bad9724..6e0bb2c 100644 --- a/composer.json +++ b/composer.json @@ -1,55 +1,49 @@ -{ - "name": "dotkernel/dot-authentication", - "type": "library", - "description": "Core interfaces for authentication implementations", - "license": "MIT", - "authors": [ - { - "name": "DotKernel Team", - "email": "team@dotkernel.com" - } - ], - "require": { - "php": "~8.1.0 || ~8.2.0", - "psr/http-message": "^1.0" - }, - "require-dev": { - "phpunit/phpunit": "^10.2", - "laminas/laminas-coding-standard": "^2.5", - "squizlabs/php_codesniffer": "3.7.*", - "vimeo/psalm": "^5.13" - }, - "autoload": { - "psr-4": { - "Dot\\Authentication\\": "src/" - } - }, - "autoload-dev": { - "psr-4": { - "DotTest\\Authentication\\": "tests/" - } - }, - "extra": { - "branch-alias": { - "dev-master": "2.0-dev", - "dev-develop": "2.1-dev" - } - }, - "config": { - "allow-plugins": { - "laminas/laminas-dependency-plugin": true, - "dealerdirect/phpcodesniffer-composer-installer": true - } - }, - "scripts": { - "check": [ - "@cs-check", - "@test" - ], - "cs-check": "phpcs", - "cs-fix": "phpcbf", - "test": "phpunit --colors=always", - "test-coverage": "phpunit --colors=always --coverage-clover clover.xml", - "static-analysis": "psalm --shepherd --stats" - } -} +{ + "name": "dotkernel/dot-authentication", + "type": "library", + "description": "Core interfaces for authentication implementations", + "license": "MIT", + "authors": [ + { + "name": "DotKernel Team", + "email": "team@dotkernel.com" + } + ], + "require": { + "php": "~8.1.0 || ~8.2.0", + "psr/http-message": "^1.0" + }, + "require-dev": { + "phpunit/phpunit": "^10.2", + "laminas/laminas-coding-standard": "^2.5", + "vimeo/psalm": "^5.13" + }, + "autoload": { + "psr-4": { + "Dot\\Authentication\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "DotTest\\Authentication\\": "tests/" + } + }, + "config": { + "allow-plugins": { + "laminas/laminas-dependency-plugin": true, + "dealerdirect/phpcodesniffer-composer-installer": true + } + }, + "sort-packages": true, + "scripts": { + "check": [ + "@cs-check", + "@test" + ], + "cs-check": "phpcs", + "cs-fix": "phpcbf", + "test": "phpunit --colors=always", + "test-coverage": "phpunit --colors=always --coverage-clover clover.xml", + "static-analysis": "psalm --shepherd --stats" + } +} diff --git a/phpcs.xml b/phpcs.xml index f28322c..ae43e47 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -1,20 +1,20 @@ - - - - - - - - - - - - - - src - tests - - - - \ No newline at end of file + + + + + + + + + + + + + + src + tests + + + + diff --git a/phpunit.xml b/phpunit.xml index 24843ef..0da17d6 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,10 +1,10 @@ - - - - - ./tests - - - \ No newline at end of file + + + + + ./tests + + + diff --git a/psalm.xml b/psalm.xml index 6dee3f1..641f3ba 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,15 +1,15 @@ - - - - - - - - - \ No newline at end of file + + + + + + + + + diff --git a/src/AuthenticationInterface.php b/src/AuthenticationInterface.php index 8be1328..5fe68b9 100644 --- a/src/AuthenticationInterface.php +++ b/src/AuthenticationInterface.php @@ -1,9 +1,5 @@ code = (int) $code; + $this->code = $code; $this->identity = $identity; $this->message = $message; } @@ -73,7 +61,7 @@ public function setIdentity(IdentityInterface $identity) public function getMessage(): string { - return $this->message ?? ''; + return $this->message; } public function setMessage(string $message) diff --git a/src/Exception/ExceptionInterface.php b/src/Exception/ExceptionInterface.php index 2da4b86..76add1f 100644 --- a/src/Exception/ExceptionInterface.php +++ b/src/Exception/ExceptionInterface.php @@ -1,9 +1,5 @@ indentyInterfaceMock = $this->createMock(IdentityInterface::class); $this->indentyInterfaceMock->method('getId')->will($this->returnValue(10)); $this->indentyInterfaceMock->method('getName')->willReturn('username'); $this->subject = new AuthenticationResult(2, 'valid', $this->indentyInterfaceMock); - - parent::setUp(); } public function testAuth() From 5c75e97174a319025962bc8b40dee61434ea707f Mon Sep 17 00:00:00 2001 From: poprazvan17 Date: Wed, 12 Jul 2023 19:35:26 +0300 Subject: [PATCH 3/6] implemented unit tests, added phpcs, static-analysis and run unit test github actions --- composer.json | 6 +++--- phpcs.xml | 2 +- phpunit.xml | 2 +- src/Identity/IdentityInterface.php | 4 ---- {tests => test}/AuthenticationResultTest.php | 0 5 files changed, 5 insertions(+), 9 deletions(-) rename {tests => test}/AuthenticationResultTest.php (100%) diff --git a/composer.json b/composer.json index 6e0bb2c..23ff2e4 100644 --- a/composer.json +++ b/composer.json @@ -25,16 +25,16 @@ }, "autoload-dev": { "psr-4": { - "DotTest\\Authentication\\": "tests/" + "DotTest\\Authentication\\": "test/" } }, "config": { + "sort-packages": true, "allow-plugins": { - "laminas/laminas-dependency-plugin": true, "dealerdirect/phpcodesniffer-composer-installer": true } }, - "sort-packages": true, + "scripts": { "check": [ "@cs-check", diff --git a/phpcs.xml b/phpcs.xml index ae43e47..408bab1 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -13,7 +13,7 @@ src - tests + test diff --git a/phpunit.xml b/phpunit.xml index 0da17d6..b069646 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -4,7 +4,7 @@ bootstrap="vendor/autoload.php"> - ./tests + ./test diff --git a/src/Identity/IdentityInterface.php b/src/Identity/IdentityInterface.php index aa0825e..80ddb8e 100644 --- a/src/Identity/IdentityInterface.php +++ b/src/Identity/IdentityInterface.php @@ -1,9 +1,5 @@ Date: Thu, 13 Jul 2023 11:46:44 +0300 Subject: [PATCH 4/6] added symfony Insight badge --- README.md | 122 +++++++++++++++++++++++++++--------------------------- 1 file changed, 61 insertions(+), 61 deletions(-) diff --git a/README.md b/README.md index 9d50394..1fe4e30 100644 --- a/README.md +++ b/README.md @@ -1,61 +1,61 @@ -# dot-authentication - -Authentication base package defining interfaces for authentication services to be used with DotKernel applications. - -![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/dot-authentication) -![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-authentication) - -[![GitHub issues](https://img.shields.io/github/issues/dotkernel/dot-authentication)](https://github.com/dotkernel/dot-authentication/issues) -[![GitHub forks](https://img.shields.io/github/forks/dotkernel/dot-authentication)](https://github.com/dotkernel/dot-authentication/network) -[![GitHub stars](https://img.shields.io/github/stars/dotkernel/dot-authentication)](https://github.com/dotkernel/dot-authentication/stargazers) -[![GitHub license](https://img.shields.io/github/license/dotkernel/dot-authentication)](https://github.com/dotkernel/dot-authentication/blob/2.1/LICENSE.md) - - -## Installation - -Run the following command in you project directory -```bash -$ composer require dotkernel/dot-authentication -``` - -Please note that usually this package will be installed as a dependency to a concrete implementation, so usually you won't need to add this to you project manually. - -## AuthenticationInterface - -Defines the interface that should be implemented by any authentication service, in order to work with DotKernel applications. This is a result of the fact that the default packages used by DotKernel applications, that need access to the authentication service are type-hinted against this interface. - -Also, concrete implementations should be registered in the service manager using this interface's FQN. - -### Methods - -```php -public function authenticate(ServerRequestInterface $request): AuthenticationResult; -``` -* method to implement the actual authentication process. It should extract credentials from the `$request` object(Authorization header, custom request attributes etc.). It should return an `AuthenticationResult` object, defined in this package, which carry the authentication status and identity on success. - -```php -public function challenge(ServerRequestInterface $request): ResponseInterface; -``` -* this method should return a valid PSR-7 `ResponseInterface` used to notify the client or browser that it needs to authenticate first(usually using the `WWW-Authenticate` header - usefull for HTTP basic and digest authentication) - -```php -public function hasIdentity(): bool; -public function getIdentity(): ?IdentityInterface; -public function setIdentity(IdentityInterface $identity); -public function clearIdentity(); -``` - -* these methods are used to check if authenticated, get the authenticated identity object, force set an identity(maybe useful for auto-login) or clear an identity(logout) - - -## IdentityInterface - -You can use any object to represent an authenticated identity(user) as long as it implements this interface. It requires 2 methods, `getId()` which should return the unique identifier of the identity, and `getName(): string` which should return a string representation of the identity(for display purposes, usually the email or username) - -## AuthenticationResult - -Returned by the authentication service, on authentication success or failure. It composes one of the predefined authentication codes, which describes the authentication status, an error message in case the authentication has failed, and the identity object on success. - -## UnauthorizedException - -Exception to be thrown when accessing content that need authentication first. This can be used within an application to trigger an error and do a custom action(like redirecting to a login page). There is not a predefined way to handle this, DotKernel packages use this exception paired with a custom error handler to handle unauthorized errors. When using the frontend or admin applications, this is already setup among the authentication/authorization packages, and throwing an UnauthorizedException from anywhere your application, it will redirect to the login page by default. +# dot-authentication + +Authentication base package defining interfaces for authentication services to be used with DotKernel applications. + +![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/dot-authentication) +![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-authentication) + +[![GitHub issues](https://img.shields.io/github/issues/dotkernel/dot-authentication)](https://github.com/dotkernel/dot-authentication/issues) +[![GitHub forks](https://img.shields.io/github/forks/dotkernel/dot-authentication)](https://github.com/dotkernel/dot-authentication/network) +[![GitHub stars](https://img.shields.io/github/stars/dotkernel/dot-authentication)](https://github.com/dotkernel/dot-authentication/stargazers) +[![GitHub license](https://img.shields.io/github/license/dotkernel/dot-authentication)](https://github.com/dotkernel/dot-authentication/blob/2.1/LICENSE.md) +[![SymfonyInsight](https://insight.symfony.com/projects/8a0dfa12-fdda-43d7-bdbe-1c6996b30c12/big.svg)](https://insight.symfony.com/projects/8a0dfa12-fdda-43d7-bdbe-1c6996b30c12) + +## Installation + +Run the following command in you project directory +```bash +$ composer require dotkernel/dot-authentication +``` + +Please note that usually this package will be installed as a dependency to a concrete implementation, so usually you won't need to add this to you project manually. + +## AuthenticationInterface + +Defines the interface that should be implemented by any authentication service, in order to work with DotKernel applications. This is a result of the fact that the default packages used by DotKernel applications, that need access to the authentication service are type-hinted against this interface. + +Also, concrete implementations should be registered in the service manager using this interface's FQN. + +### Methods + +```php +public function authenticate(ServerRequestInterface $request): AuthenticationResult; +``` +* method to implement the actual authentication process. It should extract credentials from the `$request` object(Authorization header, custom request attributes etc.). It should return an `AuthenticationResult` object, defined in this package, which carry the authentication status and identity on success. + +```php +public function challenge(ServerRequestInterface $request): ResponseInterface; +``` +* this method should return a valid PSR-7 `ResponseInterface` used to notify the client or browser that it needs to authenticate first(usually using the `WWW-Authenticate` header - usefull for HTTP basic and digest authentication) + +```php +public function hasIdentity(): bool; +public function getIdentity(): ?IdentityInterface; +public function setIdentity(IdentityInterface $identity); +public function clearIdentity(); +``` + +* these methods are used to check if authenticated, get the authenticated identity object, force set an identity(maybe useful for auto-login) or clear an identity(logout) + + +## IdentityInterface + +You can use any object to represent an authenticated identity(user) as long as it implements this interface. It requires 2 methods, `getId()` which should return the unique identifier of the identity, and `getName(): string` which should return a string representation of the identity(for display purposes, usually the email or username) + +## AuthenticationResult + +Returned by the authentication service, on authentication success or failure. It composes one of the predefined authentication codes, which describes the authentication status, an error message in case the authentication has failed, and the identity object on success. + +## UnauthorizedException + +Exception to be thrown when accessing content that need authentication first. This can be used within an application to trigger an error and do a custom action(like redirecting to a login page). There is not a predefined way to handle this, DotKernel packages use this exception paired with a custom error handler to handle unauthorized errors. When using the frontend or admin applications, this is already setup among the authentication/authorization packages, and throwing an UnauthorizedException from anywhere your application, it will redirect to the login page by default. From 0da3614072ca20f5c2bc094a1a296c2d47dc779f Mon Sep 17 00:00:00 2001 From: poprazvan17 Date: Thu, 13 Jul 2023 13:02:19 +0300 Subject: [PATCH 5/6] modified from crlf to lf --- .github/workflows/cs-tests.yml | 92 +++++++++---------- .github/workflows/static-analysis.yml | 92 +++++++++---------- .github/workflows/unit-tests.yaml | 94 ++++++++++---------- .gitignore | 1 - README.md | 122 +++++++++++++------------- phpcs.xml | 40 ++++----- phpunit.xml | 20 ++--- psalm.xml | 30 +++---- src/AuthenticationInterface.php | 4 +- src/AuthenticationResult.php | 6 +- src/Identity/IdentityInterface.php | 2 +- test/AuthenticationResultTest.php | 1 + 12 files changed, 252 insertions(+), 252 deletions(-) diff --git a/.github/workflows/cs-tests.yml b/.github/workflows/cs-tests.yml index dfb8435..3da9965 100644 --- a/.github/workflows/cs-tests.yml +++ b/.github/workflows/cs-tests.yml @@ -1,46 +1,46 @@ -on: - - push - -name: Run phpcs checks - -jobs: - mutation: - name: PHP ${{ matrix.php }}-${{ matrix.os }} - - runs-on: ${{ matrix.os }} - - strategy: - matrix: - os: - - ubuntu-latest - - php: - - "8.1" - - "8.2" - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Install PHP - uses: shivammathur/setup-php@v2 - with: - php-version: "${{ matrix.php }}" - tools: composer:v2, cs2pr - coverage: none - - - name: Determine composer cache directory - run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV - - - name: Cache dependencies installed with composer - uses: actions/cache@v3 - with: - path: ${{ env.COMPOSER_CACHE_DIR }} - key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: | - php${{ matrix.php }}-composer- - - name: Install dependencies with composer - run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi - - - name: Run phpcs checks - run: vendor/bin/phpcs +on: + - push + +name: Run phpcs checks + +jobs: + mutation: + name: PHP ${{ matrix.php }}-${{ matrix.os }} + + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: + - ubuntu-latest + + php: + - "8.1" + - "8.2" + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: "${{ matrix.php }}" + tools: composer:v2, cs2pr + coverage: none + + - name: Determine composer cache directory + run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV + + - name: Cache dependencies installed with composer + uses: actions/cache@v3 + with: + path: ${{ env.COMPOSER_CACHE_DIR }} + key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: | + php${{ matrix.php }}-composer- + - name: Install dependencies with composer + run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi + + - name: Run phpcs checks + run: vendor/bin/phpcs diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 525c9c2..74550fc 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -1,46 +1,46 @@ -on: - - push - -name: Run static analysis - -jobs: - mutation: - name: PHP ${{ matrix.php }}-${{ matrix.os }} - - runs-on: ${{ matrix.os }} - - strategy: - matrix: - os: - - ubuntu-latest - - php: - - "8.1" - - "8.2" - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Install PHP - uses: shivammathur/setup-php@v2 - with: - php-version: "${{ matrix.php }}" - tools: composer:v2, cs2pr - coverage: none - - - name: Determine composer cache directory - run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV - - - name: Cache dependencies installed with composer - uses: actions/cache@v3 - with: - path: ${{ env.COMPOSER_CACHE_DIR }} - key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: | - php${{ matrix.php }}-composer- - - name: Install dependencies with composer - run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi - - - name: Run static analysis - run: vendor/bin/psalm --no-cache --output-format=github --show-info=false --threads=4 +on: + - push + +name: Run static analysis + +jobs: + mutation: + name: PHP ${{ matrix.php }}-${{ matrix.os }} + + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: + - ubuntu-latest + + php: + - "8.1" + - "8.2" + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: "${{ matrix.php }}" + tools: composer:v2, cs2pr + coverage: none + + - name: Determine composer cache directory + run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV + + - name: Cache dependencies installed with composer + uses: actions/cache@v3 + with: + path: ${{ env.COMPOSER_CACHE_DIR }} + key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: | + php${{ matrix.php }}-composer- + - name: Install dependencies with composer + run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi + + - name: Run static analysis + run: vendor/bin/psalm --no-cache --output-format=github --show-info=false --threads=4 diff --git a/.github/workflows/unit-tests.yaml b/.github/workflows/unit-tests.yaml index 9f0c3e2..d2ab8e7 100644 --- a/.github/workflows/unit-tests.yaml +++ b/.github/workflows/unit-tests.yaml @@ -1,47 +1,47 @@ -on: - - push - -name: Run PHPUnit tests - -jobs: - mutation: - name: PHP ${{ matrix.php }}-${{ matrix.os }} - - runs-on: ${{ matrix.os }} - - strategy: - matrix: - os: - - ubuntu-latest - - php: - - "8.1" - - "8.2" - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Install PHP - uses: shivammathur/setup-php@v2 - with: - php-version: "${{ matrix.php }}" - tools: composer:v2, cs2pr - coverage: none - - - name: Determine composer cache directory - run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV - - - name: Cache dependencies installed with composer - uses: actions/cache@v3 - with: - path: ${{ env.COMPOSER_CACHE_DIR }} - key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: | - php${{ matrix.php }}-composer- - - - name: Install dependencies with composer - run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi - - - name: Run PHPUnit tests - run: vendor/bin/phpunit --colors=always +on: + - push + +name: Run PHPUnit tests + +jobs: + mutation: + name: PHP ${{ matrix.php }}-${{ matrix.os }} + + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: + - ubuntu-latest + + php: + - "8.1" + - "8.2" + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: "${{ matrix.php }}" + tools: composer:v2, cs2pr + coverage: none + + - name: Determine composer cache directory + run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV + + - name: Cache dependencies installed with composer + uses: actions/cache@v3 + with: + path: ${{ env.COMPOSER_CACHE_DIR }} + key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: | + php${{ matrix.php }}-composer- + + - name: Install dependencies with composer + run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi + + - name: Run PHPUnit tests + run: vendor/bin/phpunit --colors=always diff --git a/.gitignore b/.gitignore index 6a96a2d..c1ae9d9 100644 --- a/.gitignore +++ b/.gitignore @@ -35,4 +35,3 @@ crashlytics-build.properties fabric.properties .phpunit.result.cache .phpcs-cache - diff --git a/README.md b/README.md index 1fe4e30..3518081 100644 --- a/README.md +++ b/README.md @@ -1,61 +1,61 @@ -# dot-authentication - -Authentication base package defining interfaces for authentication services to be used with DotKernel applications. - -![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/dot-authentication) -![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-authentication) - -[![GitHub issues](https://img.shields.io/github/issues/dotkernel/dot-authentication)](https://github.com/dotkernel/dot-authentication/issues) -[![GitHub forks](https://img.shields.io/github/forks/dotkernel/dot-authentication)](https://github.com/dotkernel/dot-authentication/network) -[![GitHub stars](https://img.shields.io/github/stars/dotkernel/dot-authentication)](https://github.com/dotkernel/dot-authentication/stargazers) -[![GitHub license](https://img.shields.io/github/license/dotkernel/dot-authentication)](https://github.com/dotkernel/dot-authentication/blob/2.1/LICENSE.md) -[![SymfonyInsight](https://insight.symfony.com/projects/8a0dfa12-fdda-43d7-bdbe-1c6996b30c12/big.svg)](https://insight.symfony.com/projects/8a0dfa12-fdda-43d7-bdbe-1c6996b30c12) - -## Installation - -Run the following command in you project directory -```bash -$ composer require dotkernel/dot-authentication -``` - -Please note that usually this package will be installed as a dependency to a concrete implementation, so usually you won't need to add this to you project manually. - -## AuthenticationInterface - -Defines the interface that should be implemented by any authentication service, in order to work with DotKernel applications. This is a result of the fact that the default packages used by DotKernel applications, that need access to the authentication service are type-hinted against this interface. - -Also, concrete implementations should be registered in the service manager using this interface's FQN. - -### Methods - -```php -public function authenticate(ServerRequestInterface $request): AuthenticationResult; -``` -* method to implement the actual authentication process. It should extract credentials from the `$request` object(Authorization header, custom request attributes etc.). It should return an `AuthenticationResult` object, defined in this package, which carry the authentication status and identity on success. - -```php -public function challenge(ServerRequestInterface $request): ResponseInterface; -``` -* this method should return a valid PSR-7 `ResponseInterface` used to notify the client or browser that it needs to authenticate first(usually using the `WWW-Authenticate` header - usefull for HTTP basic and digest authentication) - -```php -public function hasIdentity(): bool; -public function getIdentity(): ?IdentityInterface; -public function setIdentity(IdentityInterface $identity); -public function clearIdentity(); -``` - -* these methods are used to check if authenticated, get the authenticated identity object, force set an identity(maybe useful for auto-login) or clear an identity(logout) - - -## IdentityInterface - -You can use any object to represent an authenticated identity(user) as long as it implements this interface. It requires 2 methods, `getId()` which should return the unique identifier of the identity, and `getName(): string` which should return a string representation of the identity(for display purposes, usually the email or username) - -## AuthenticationResult - -Returned by the authentication service, on authentication success or failure. It composes one of the predefined authentication codes, which describes the authentication status, an error message in case the authentication has failed, and the identity object on success. - -## UnauthorizedException - -Exception to be thrown when accessing content that need authentication first. This can be used within an application to trigger an error and do a custom action(like redirecting to a login page). There is not a predefined way to handle this, DotKernel packages use this exception paired with a custom error handler to handle unauthorized errors. When using the frontend or admin applications, this is already setup among the authentication/authorization packages, and throwing an UnauthorizedException from anywhere your application, it will redirect to the login page by default. +# dot-authentication + +Authentication base package defining interfaces for authentication services to be used with DotKernel applications. + +![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/dot-authentication) +![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-authentication) + +[![GitHub issues](https://img.shields.io/github/issues/dotkernel/dot-authentication)](https://github.com/dotkernel/dot-authentication/issues) +[![GitHub forks](https://img.shields.io/github/forks/dotkernel/dot-authentication)](https://github.com/dotkernel/dot-authentication/network) +[![GitHub stars](https://img.shields.io/github/stars/dotkernel/dot-authentication)](https://github.com/dotkernel/dot-authentication/stargazers) +[![GitHub license](https://img.shields.io/github/license/dotkernel/dot-authentication)](https://github.com/dotkernel/dot-authentication/blob/2.1/LICENSE.md) +[![SymfonyInsight](https://insight.symfony.com/projects/8a0dfa12-fdda-43d7-bdbe-1c6996b30c12/big.svg)](https://insight.symfony.com/projects/8a0dfa12-fdda-43d7-bdbe-1c6996b30c12) + +## Installation + +Run the following command in you project directory +```bash +$ composer require dotkernel/dot-authentication +``` + +Please note that usually this package will be installed as a dependency to a concrete implementation, so usually you won't need to add this to you project manually. + +## AuthenticationInterface + +Defines the interface that should be implemented by any authentication service, in order to work with DotKernel applications. This is a result of the fact that the default packages used by DotKernel applications, that need access to the authentication service are type-hinted against this interface. + +Also, concrete implementations should be registered in the service manager using this interface's FQN. + +### Methods + +```php +public function authenticate(ServerRequestInterface $request): AuthenticationResult; +``` +* method to implement the actual authentication process. It should extract credentials from the `$request` object(Authorization header, custom request attributes etc.). It should return an `AuthenticationResult` object, defined in this package, which carry the authentication status and identity on success. + +```php +public function challenge(ServerRequestInterface $request): ResponseInterface; +``` +* this method should return a valid PSR-7 `ResponseInterface` used to notify the client or browser that it needs to authenticate first(usually using the `WWW-Authenticate` header - usefull for HTTP basic and digest authentication) + +```php +public function hasIdentity(): bool; +public function getIdentity(): ?IdentityInterface; +public function setIdentity(IdentityInterface $identity); +public function clearIdentity(); +``` + +* these methods are used to check if authenticated, get the authenticated identity object, force set an identity(maybe useful for auto-login) or clear an identity(logout) + + +## IdentityInterface + +You can use any object to represent an authenticated identity(user) as long as it implements this interface. It requires 2 methods, `getId()` which should return the unique identifier of the identity, and `getName(): string` which should return a string representation of the identity(for display purposes, usually the email or username) + +## AuthenticationResult + +Returned by the authentication service, on authentication success or failure. It composes one of the predefined authentication codes, which describes the authentication status, an error message in case the authentication has failed, and the identity object on success. + +## UnauthorizedException + +Exception to be thrown when accessing content that need authentication first. This can be used within an application to trigger an error and do a custom action(like redirecting to a login page). There is not a predefined way to handle this, DotKernel packages use this exception paired with a custom error handler to handle unauthorized errors. When using the frontend or admin applications, this is already setup among the authentication/authorization packages, and throwing an UnauthorizedException from anywhere your application, it will redirect to the login page by default. diff --git a/phpcs.xml b/phpcs.xml index 408bab1..1efe663 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -1,20 +1,20 @@ - - - - - - - - - - - - - - src - test - - - - + + + + + + + + + + + + + + src + test + + + + diff --git a/phpunit.xml b/phpunit.xml index b069646..76304d8 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,10 +1,10 @@ - - - - - ./test - - - + + + + + ./test + + + diff --git a/psalm.xml b/psalm.xml index 641f3ba..df50202 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,15 +1,15 @@ - - - - - - - - - + + + + + + + + + diff --git a/src/AuthenticationInterface.php b/src/AuthenticationInterface.php index 5fe68b9..ff20176 100644 --- a/src/AuthenticationInterface.php +++ b/src/AuthenticationInterface.php @@ -34,10 +34,10 @@ public function getIdentity(): ?IdentityInterface; /** * Sets the identity directly, useful for auto-login */ - public function setIdentity(IdentityInterface $identity); + public function setIdentity(IdentityInterface $identity): IdentityInterface; /** * Clears the stored identity */ - public function clearIdentity(); + public function clearIdentity(): IdentityInterface; } diff --git a/src/AuthenticationResult.php b/src/AuthenticationResult.php index 265d31f..cdcd7ed 100644 --- a/src/AuthenticationResult.php +++ b/src/AuthenticationResult.php @@ -44,7 +44,7 @@ public function getCode(): int return $this->code; } - public function setCode(int $code) + public function setCode(int $code): void { $this->code = $code; } @@ -54,7 +54,7 @@ public function getIdentity(): ?IdentityInterface return $this->identity; } - public function setIdentity(IdentityInterface $identity) + public function setIdentity(IdentityInterface $identity): void { $this->identity = $identity; } @@ -64,7 +64,7 @@ public function getMessage(): string return $this->message; } - public function setMessage(string $message) + public function setMessage(string $message): void { $this->message = $message; } diff --git a/src/Identity/IdentityInterface.php b/src/Identity/IdentityInterface.php index 80ddb8e..d1dfa35 100644 --- a/src/Identity/IdentityInterface.php +++ b/src/Identity/IdentityInterface.php @@ -12,7 +12,7 @@ interface IdentityInterface /** * @return mixed */ - public function getId(); + public function getId(): int; public function getName(): string; } diff --git a/test/AuthenticationResultTest.php b/test/AuthenticationResultTest.php index 83a59e6..01574fa 100644 --- a/test/AuthenticationResultTest.php +++ b/test/AuthenticationResultTest.php @@ -34,6 +34,7 @@ public function testAuth() $interface = $this->subject->hasIdentity(); $isValid = $this->subject->isValid(); + $this->assertInstanceOf(IdentityInterface::class, $name); $this->assertSame(2, $code); $this->assertSame('valid', $message); $this->assertSame('username', $name->getName()); From 6e3ba2e5a8957c2b6ddaffd669019fe611f9b378 Mon Sep 17 00:00:00 2001 From: poprazvan17 Date: Tue, 18 Jul 2023 11:31:02 +0300 Subject: [PATCH 6/6] modified from crlf to lf --- README.md | 1 + composer.json | 98 +++++++++++++++++++++++++-------------------------- 2 files changed, 50 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index 3518081..07540d1 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ Authentication base package defining interfaces for authentication services to b [![GitHub forks](https://img.shields.io/github/forks/dotkernel/dot-authentication)](https://github.com/dotkernel/dot-authentication/network) [![GitHub stars](https://img.shields.io/github/stars/dotkernel/dot-authentication)](https://github.com/dotkernel/dot-authentication/stargazers) [![GitHub license](https://img.shields.io/github/license/dotkernel/dot-authentication)](https://github.com/dotkernel/dot-authentication/blob/2.1/LICENSE.md) + [![SymfonyInsight](https://insight.symfony.com/projects/8a0dfa12-fdda-43d7-bdbe-1c6996b30c12/big.svg)](https://insight.symfony.com/projects/8a0dfa12-fdda-43d7-bdbe-1c6996b30c12) ## Installation diff --git a/composer.json b/composer.json index 23ff2e4..e432a9d 100644 --- a/composer.json +++ b/composer.json @@ -1,49 +1,49 @@ -{ - "name": "dotkernel/dot-authentication", - "type": "library", - "description": "Core interfaces for authentication implementations", - "license": "MIT", - "authors": [ - { - "name": "DotKernel Team", - "email": "team@dotkernel.com" - } - ], - "require": { - "php": "~8.1.0 || ~8.2.0", - "psr/http-message": "^1.0" - }, - "require-dev": { - "phpunit/phpunit": "^10.2", - "laminas/laminas-coding-standard": "^2.5", - "vimeo/psalm": "^5.13" - }, - "autoload": { - "psr-4": { - "Dot\\Authentication\\": "src/" - } - }, - "autoload-dev": { - "psr-4": { - "DotTest\\Authentication\\": "test/" - } - }, - "config": { - "sort-packages": true, - "allow-plugins": { - "dealerdirect/phpcodesniffer-composer-installer": true - } - }, - - "scripts": { - "check": [ - "@cs-check", - "@test" - ], - "cs-check": "phpcs", - "cs-fix": "phpcbf", - "test": "phpunit --colors=always", - "test-coverage": "phpunit --colors=always --coverage-clover clover.xml", - "static-analysis": "psalm --shepherd --stats" - } -} +{ + "name": "dotkernel/dot-authentication", + "type": "library", + "description": "Core interfaces for authentication implementations", + "license": "MIT", + "authors": [ + { + "name": "DotKernel Team", + "email": "team@dotkernel.com" + } + ], + "require": { + "php": "~8.1.0 || ~8.2.0", + "psr/http-message": "^1.0" + }, + "require-dev": { + "phpunit/phpunit": "^10.2", + "laminas/laminas-coding-standard": "^2.5", + "vimeo/psalm": "^5.13" + }, + "autoload": { + "psr-4": { + "Dot\\Authentication\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "DotTest\\Authentication\\": "test/" + } + }, + "config": { + "sort-packages": true, + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } + }, + + "scripts": { + "check": [ + "@cs-check", + "@test" + ], + "cs-check": "phpcs", + "cs-fix": "phpcbf", + "test": "phpunit --colors=always", + "test-coverage": "phpunit --colors=always --coverage-clover clover.xml", + "static-analysis": "psalm --shepherd --stats" + } +}