From 0d9d78b74d8092f713e86ac04021db6177612c21 Mon Sep 17 00:00:00 2001 From: Marco Rieger Date: Thu, 30 Mar 2023 11:13:49 +0200 Subject: [PATCH] Add/php 8 2 (#11) * add 8-2 test suite * add composer.lock * update composer * remove composer.lock * upgrade psalm * fix typecheck * fix composer * fix composer * fix composer * use correct semver * test psalm from composer * psalm 5.6 * use whatever psalm is available * use manual download --- .github/workflows/main.yml | 10 +++++--- .gitignore | 3 +++ composer.json | 2 +- phpunit.xml.dist | 24 +++++++++---------- psalm.xml | 6 ++--- .../Authentication/Provider/AppRole.php | 9 ++++--- .../Response/BulkEndpointResponse.php | 8 ++++--- src/VaultPHP/Response/EndpointResponse.php | 4 ++-- src/VaultPHP/Response/MetaData.php | 2 +- .../Request/DecryptData/DecryptData.php | 6 ++--- .../Request/EncryptData/EncryptData.php | 6 ++--- .../Request/UpdateKeyConfigRequest.php | 8 +++---- ...t.php => AbstractSecretEngineTestCase.php} | 2 +- .../Engines/Transit/CreateKeyTest.php | 4 ++-- .../Engines/Transit/DecryptDataBulkTest.php | 4 ++-- .../Engines/Transit/DecryptDataTest.php | 4 ++-- .../Engines/Transit/DeleteKeyTest.php | 4 ++-- .../Engines/Transit/EncryptDataBulkTest.php | 4 ++-- .../Engines/Transit/EncryptDataTest.php | 4 ++-- .../Engines/Transit/ListKeyTest.php | 4 ++-- .../Engines/Transit/UpdateKeyConfigTest.php | 4 ++-- 21 files changed, 66 insertions(+), 56 deletions(-) rename tests/VaultPHP/SecretEngines/{SecretEngineTest.php => AbstractSecretEngineTestCase.php} (95%) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d6c06df..6e56458 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-versions: ['5.6', '7.4', '8.0'] + php-versions: ['5.x', '7.x', '8.x'] name: Testing PHP ${{ matrix.php-versions }} steps: - name: Checkout @@ -26,15 +26,19 @@ jobs: run: composer test typecheck: runs-on: ubuntu-latest - name: Typechecks against PSALM + name: TypeChecks against PSALM steps: - name: Checkout uses: actions/checkout@v2 + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.x' - name: Check PHP Version run: php -v - name: Install Dependencies run: composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist - name: Downloading - run: wget https://github.com/vimeo/psalm/releases/download/3.12.1/psalm.phar + run: wget https://github.com/vimeo/psalm/releases/download/5.9.0/psalm.phar - name: Typechecking run: php psalm.phar diff --git a/.gitignore b/.gitignore index cac762f..fff2e99 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ /vendor/ /.idea/ +/.phpunit.cache/ +.phpunit.result.cache +composer.lock diff --git a/composer.json b/composer.json index b4c6d89..404b5d9 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "type": "library", "license": "MIT", "homepage": "https://www.mittwald.de/", - "description": "PHP library for Vault", + "description": "A PHP client library for 'Vault by HashiCorp'", "require": { "ext-json": "*", "guzzlehttp/psr7": "^1.6", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index ae314b9..270c157 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,13 +1,13 @@ - - - - - ./src/ - - - - - ./tests - - + + + + + ./src/ + + + + + ./tests + + diff --git a/psalm.xml b/psalm.xml index 4057dcb..3190338 100644 --- a/psalm.xml +++ b/psalm.xml @@ -2,12 +2,10 @@ diff --git a/src/VaultPHP/Authentication/Provider/AppRole.php b/src/VaultPHP/Authentication/Provider/AppRole.php index 407d035..7b90cd6 100644 --- a/src/VaultPHP/Authentication/Provider/AppRole.php +++ b/src/VaultPHP/Authentication/Provider/AppRole.php @@ -19,14 +19,17 @@ class AppRole extends AbstractAuthenticationProvider { /** @var string */ private $roleId; + + /** @var string */ private $secretId; - /** @var string */ - private $endpoint = '/v1/auth/approle/login'; + /** @var string */ + private $endpoint = '/v1/auth/approle/login'; /** * AppRole constructor. - * @param string $AppRole + * @param $roleId + * @param $secretId */ public function __construct($roleId, $secretId) { diff --git a/src/VaultPHP/Response/BulkEndpointResponse.php b/src/VaultPHP/Response/BulkEndpointResponse.php index b285919..c8b040f 100644 --- a/src/VaultPHP/Response/BulkEndpointResponse.php +++ b/src/VaultPHP/Response/BulkEndpointResponse.php @@ -9,7 +9,9 @@ /** * Class BulkEndpointResponse - * @package VaultPHP\Response + * + * @template-implements Iterator + * @template-implements ArrayAccess */ class BulkEndpointResponse extends EndpointResponse implements Iterator, ArrayAccess, Countable { @@ -48,7 +50,7 @@ public function getBatchResults() { } /** - * @return mixed + * @return int|null */ public function current() { @@ -68,7 +70,7 @@ public function next() */ public function key() { - return (int) $this->iteratorPosition; + return $this->iteratorPosition; } /** diff --git a/src/VaultPHP/Response/EndpointResponse.php b/src/VaultPHP/Response/EndpointResponse.php index 94fb98b..67c6e23 100644 --- a/src/VaultPHP/Response/EndpointResponse.php +++ b/src/VaultPHP/Response/EndpointResponse.php @@ -18,7 +18,7 @@ class EndpointResponse implements EndpointResponseInterface * @param array|object $data * @param array $meta */ - public function __construct($data = [], $meta = []) + final public function __construct($data = [], $meta = []) { $this->metaData = new MetaData($meta); $this->populateData($data); @@ -106,6 +106,6 @@ public function getMetaData() */ public function hasErrors() { - return (bool) $this->getMetaData()->hasErrors(); + return $this->getMetaData()->hasErrors(); } } diff --git a/src/VaultPHP/Response/MetaData.php b/src/VaultPHP/Response/MetaData.php index f5ec416..878c58c 100644 --- a/src/VaultPHP/Response/MetaData.php +++ b/src/VaultPHP/Response/MetaData.php @@ -143,6 +143,6 @@ public function containsError($error) { public function hasErrors() { $errors = $this->getErrors(); - return $errors !== NULL && is_array($errors) && count($errors) >= 1; + return is_array($errors) && count($errors) >= 1; } } diff --git a/src/VaultPHP/SecretEngines/Engines/Transit/Request/DecryptData/DecryptData.php b/src/VaultPHP/SecretEngines/Engines/Transit/Request/DecryptData/DecryptData.php index 3d57269..c7be890 100644 --- a/src/VaultPHP/SecretEngines/Engines/Transit/Request/DecryptData/DecryptData.php +++ b/src/VaultPHP/SecretEngines/Engines/Transit/Request/DecryptData/DecryptData.php @@ -45,7 +45,7 @@ public function getCiphertext() /** * @param string $ciphertext - * @return $this + * @return self */ public function setCiphertext($ciphertext) { @@ -63,7 +63,7 @@ public function getNonce() /** * @param string|null $nonce - * @return $this + * @return self */ public function setNonce($nonce) { @@ -81,7 +81,7 @@ public function getContext() /** * @param string|null $context - * @return $this + * @return self */ public function setContext($context) { diff --git a/src/VaultPHP/SecretEngines/Engines/Transit/Request/EncryptData/EncryptData.php b/src/VaultPHP/SecretEngines/Engines/Transit/Request/EncryptData/EncryptData.php index 52cd6b1..6a3ba3d 100644 --- a/src/VaultPHP/SecretEngines/Engines/Transit/Request/EncryptData/EncryptData.php +++ b/src/VaultPHP/SecretEngines/Engines/Transit/Request/EncryptData/EncryptData.php @@ -45,7 +45,7 @@ public function getPlaintext() /** * @param string $plaintext - * @return $this + * @return self */ public function setPlaintext($plaintext) { @@ -63,7 +63,7 @@ public function getNonce() /** * @param string|null $nonce - * @return $this + * @return self */ public function setNonce($nonce) { @@ -81,7 +81,7 @@ public function getContext() /** * @param string|null $context - * @return $this + * @return self */ public function setContext($context) { diff --git a/src/VaultPHP/SecretEngines/Engines/Transit/Request/UpdateKeyConfigRequest.php b/src/VaultPHP/SecretEngines/Engines/Transit/Request/UpdateKeyConfigRequest.php index c2dcfca..11556d7 100644 --- a/src/VaultPHP/SecretEngines/Engines/Transit/Request/UpdateKeyConfigRequest.php +++ b/src/VaultPHP/SecretEngines/Engines/Transit/Request/UpdateKeyConfigRequest.php @@ -56,7 +56,7 @@ public function setDeletionAllowed($allow) */ public function setMinDecryptionVersion($min_decryption_version) { - $this->min_decryption_version = (int)$min_decryption_version; + $this->min_decryption_version = $min_decryption_version; return $this; } @@ -66,7 +66,7 @@ public function setMinDecryptionVersion($min_decryption_version) */ public function setMinEncryptionVersion($min_encryption_version) { - $this->min_encryption_version = (int)$min_encryption_version; + $this->min_encryption_version = $min_encryption_version; return $this; } @@ -76,7 +76,7 @@ public function setMinEncryptionVersion($min_encryption_version) */ public function setExportable($exportable) { - $this->exportable = (bool)$exportable; + $this->exportable = $exportable; return $this; } @@ -86,7 +86,7 @@ public function setExportable($exportable) */ public function setAllowPlaintextBackup($allow_plaintext_backup) { - $this->allow_plaintext_backup = (bool)$allow_plaintext_backup; + $this->allow_plaintext_backup = $allow_plaintext_backup; return $this; } diff --git a/tests/VaultPHP/SecretEngines/SecretEngineTest.php b/tests/VaultPHP/SecretEngines/AbstractSecretEngineTestCase.php similarity index 95% rename from tests/VaultPHP/SecretEngines/SecretEngineTest.php rename to tests/VaultPHP/SecretEngines/AbstractSecretEngineTestCase.php index b33fd27..fe2a6c9 100644 --- a/tests/VaultPHP/SecretEngines/SecretEngineTest.php +++ b/tests/VaultPHP/SecretEngines/AbstractSecretEngineTestCase.php @@ -13,7 +13,7 @@ * Class SecretEngineTest * @package Test\VaultPHP\SecretEngines */ -abstract class SecretEngineTest extends TestCase +abstract class AbstractSecretEngineTestCase extends TestCase { protected function createApiClient($expectedMethod, $expectedPath, $expectedData, $responseData, $responseStatus = 200) { diff --git a/tests/VaultPHP/SecretEngines/Engines/Transit/CreateKeyTest.php b/tests/VaultPHP/SecretEngines/Engines/Transit/CreateKeyTest.php index 208af2d..e74c48d 100644 --- a/tests/VaultPHP/SecretEngines/Engines/Transit/CreateKeyTest.php +++ b/tests/VaultPHP/SecretEngines/Engines/Transit/CreateKeyTest.php @@ -2,7 +2,7 @@ namespace Test\VaultPHP\SecretEngines\Engines\Transit; -use Test\VaultPHP\SecretEngines\SecretEngineTest; +use Test\VaultPHP\SecretEngines\AbstractSecretEngineTestCase; use VaultPHP\SecretEngines\Engines\Transit\Request\CreateKeyRequest; use VaultPHP\SecretEngines\Engines\Transit\Response\CreateKeyResponse; use VaultPHP\SecretEngines\Engines\Transit\EncryptionType; @@ -12,7 +12,7 @@ * Class CreateKeyTest * @package Test\VaultPHP\SecretEngines\Transit */ -final class CreateKeyTest extends SecretEngineTest +final class CreateKeyTest extends AbstractSecretEngineTestCase { public function testApiCall() { diff --git a/tests/VaultPHP/SecretEngines/Engines/Transit/DecryptDataBulkTest.php b/tests/VaultPHP/SecretEngines/Engines/Transit/DecryptDataBulkTest.php index fdcca99..9567f60 100644 --- a/tests/VaultPHP/SecretEngines/Engines/Transit/DecryptDataBulkTest.php +++ b/tests/VaultPHP/SecretEngines/Engines/Transit/DecryptDataBulkTest.php @@ -2,7 +2,7 @@ namespace Test\VaultPHP\SecretEngines\Engines\Transit; -use Test\VaultPHP\SecretEngines\SecretEngineTest; +use Test\VaultPHP\SecretEngines\AbstractSecretEngineTestCase; use VaultPHP\SecretEngines\Engines\Transit\Request\DecryptData\DecryptData; use VaultPHP\SecretEngines\Engines\Transit\Request\DecryptData\DecryptDataBulkRequest; use VaultPHP\SecretEngines\Engines\Transit\Response\DecryptDataResponse; @@ -12,7 +12,7 @@ * Class DecryptDataBulkTest * @package Test\VaultPHP\SecretEngines\Transit */ -final class DecryptDataBulkTest extends SecretEngineTest +final class DecryptDataBulkTest extends AbstractSecretEngineTestCase { public function testApiCall() { diff --git a/tests/VaultPHP/SecretEngines/Engines/Transit/DecryptDataTest.php b/tests/VaultPHP/SecretEngines/Engines/Transit/DecryptDataTest.php index 524e4be..3b95fb2 100644 --- a/tests/VaultPHP/SecretEngines/Engines/Transit/DecryptDataTest.php +++ b/tests/VaultPHP/SecretEngines/Engines/Transit/DecryptDataTest.php @@ -2,7 +2,7 @@ namespace Test\VaultPHP\SecretEngines\Engines\Transit; -use Test\VaultPHP\SecretEngines\SecretEngineTest; +use Test\VaultPHP\SecretEngines\AbstractSecretEngineTestCase; use VaultPHP\SecretEngines\Engines\Transit\Request\DecryptData\DecryptDataRequest; use VaultPHP\SecretEngines\Engines\Transit\Response\DecryptDataResponse; use VaultPHP\SecretEngines\Engines\Transit\Transit; @@ -11,7 +11,7 @@ * Class DecryptDataTest * @package Test\VaultPHP\SecretEngines\Transit */ -final class DecryptDataTest extends SecretEngineTest +final class DecryptDataTest extends AbstractSecretEngineTestCase { public function testApiCall() { diff --git a/tests/VaultPHP/SecretEngines/Engines/Transit/DeleteKeyTest.php b/tests/VaultPHP/SecretEngines/Engines/Transit/DeleteKeyTest.php index be68a45..4e04952 100644 --- a/tests/VaultPHP/SecretEngines/Engines/Transit/DeleteKeyTest.php +++ b/tests/VaultPHP/SecretEngines/Engines/Transit/DeleteKeyTest.php @@ -2,7 +2,7 @@ namespace Test\VaultPHP\SecretEngines\Engines\Transit; -use Test\VaultPHP\SecretEngines\SecretEngineTest; +use Test\VaultPHP\SecretEngines\AbstractSecretEngineTestCase; use VaultPHP\SecretEngines\Engines\Transit\Response\DeleteKeyResponse; use VaultPHP\SecretEngines\Engines\Transit\Transit; @@ -10,7 +10,7 @@ * Class DeleteKeyTest * @package Test\VaultPHP\SecretEngines\Transit */ -final class DeleteKeyTest extends SecretEngineTest +final class DeleteKeyTest extends AbstractSecretEngineTestCase { public function testApiCall() { diff --git a/tests/VaultPHP/SecretEngines/Engines/Transit/EncryptDataBulkTest.php b/tests/VaultPHP/SecretEngines/Engines/Transit/EncryptDataBulkTest.php index 9630b69..38adf2a 100644 --- a/tests/VaultPHP/SecretEngines/Engines/Transit/EncryptDataBulkTest.php +++ b/tests/VaultPHP/SecretEngines/Engines/Transit/EncryptDataBulkTest.php @@ -2,7 +2,7 @@ namespace Test\VaultPHP\SecretEngines\Engines\Transit; -use Test\VaultPHP\SecretEngines\SecretEngineTest; +use Test\VaultPHP\SecretEngines\AbstractSecretEngineTestCase; use VaultPHP\SecretEngines\Engines\Transit\Request\EncryptData\EncryptData; use VaultPHP\SecretEngines\Engines\Transit\Request\EncryptData\EncryptDataBulkRequest; use VaultPHP\SecretEngines\Engines\Transit\Response\EncryptDataResponse; @@ -12,7 +12,7 @@ * Class EncryptDataBulkTest * @package Test\VaultPHP\SecretEngines\Transit */ -final class EncryptDataBulkTest extends SecretEngineTest +final class EncryptDataBulkTest extends AbstractSecretEngineTestCase { public function testApiCall() { diff --git a/tests/VaultPHP/SecretEngines/Engines/Transit/EncryptDataTest.php b/tests/VaultPHP/SecretEngines/Engines/Transit/EncryptDataTest.php index 54a5ce3..c646c60 100644 --- a/tests/VaultPHP/SecretEngines/Engines/Transit/EncryptDataTest.php +++ b/tests/VaultPHP/SecretEngines/Engines/Transit/EncryptDataTest.php @@ -2,7 +2,7 @@ namespace Test\VaultPHP\SecretEngines\Engines\Transit; -use Test\VaultPHP\SecretEngines\SecretEngineTest; +use Test\VaultPHP\SecretEngines\AbstractSecretEngineTestCase; use VaultPHP\SecretEngines\Engines\Transit\EncryptionType; use VaultPHP\SecretEngines\Engines\Transit\Request\EncryptData\EncryptDataRequest; use VaultPHP\SecretEngines\Engines\Transit\Response\EncryptDataResponse; @@ -12,7 +12,7 @@ * Class EncryptDataTest * @package Test\VaultPHP\SecretEngines\Transit */ -final class EncryptDataTest extends SecretEngineTest +final class EncryptDataTest extends AbstractSecretEngineTestCase { public function testApiCall() { diff --git a/tests/VaultPHP/SecretEngines/Engines/Transit/ListKeyTest.php b/tests/VaultPHP/SecretEngines/Engines/Transit/ListKeyTest.php index e3f9951..b1d9f7d 100644 --- a/tests/VaultPHP/SecretEngines/Engines/Transit/ListKeyTest.php +++ b/tests/VaultPHP/SecretEngines/Engines/Transit/ListKeyTest.php @@ -2,7 +2,7 @@ namespace Test\VaultPHP\SecretEngines\Engines\Transit; -use Test\VaultPHP\SecretEngines\SecretEngineTest; +use Test\VaultPHP\SecretEngines\AbstractSecretEngineTestCase; use VaultPHP\SecretEngines\Engines\Transit\Response\ListKeysResponse; use VaultPHP\SecretEngines\Engines\Transit\Transit; @@ -10,7 +10,7 @@ * Class ListKeyTest * @package Test\VaultPHP\SecretEngines\Transit */ -final class ListKeyTest extends SecretEngineTest +final class ListKeyTest extends AbstractSecretEngineTestCase { public function testApiCall() { diff --git a/tests/VaultPHP/SecretEngines/Engines/Transit/UpdateKeyConfigTest.php b/tests/VaultPHP/SecretEngines/Engines/Transit/UpdateKeyConfigTest.php index 3c70220..38f6696 100644 --- a/tests/VaultPHP/SecretEngines/Engines/Transit/UpdateKeyConfigTest.php +++ b/tests/VaultPHP/SecretEngines/Engines/Transit/UpdateKeyConfigTest.php @@ -2,7 +2,7 @@ namespace Test\VaultPHP\SecretEngines\Engines\Transit; -use Test\VaultPHP\SecretEngines\SecretEngineTest; +use Test\VaultPHP\SecretEngines\AbstractSecretEngineTestCase; use VaultPHP\SecretEngines\Engines\Transit\Request\UpdateKeyConfigRequest; use VaultPHP\SecretEngines\Engines\Transit\Response\UpdateKeyConfigResponse; use VaultPHP\SecretEngines\Engines\Transit\Transit; @@ -11,7 +11,7 @@ * Class UpdateKeyConfigTest * @package Test\VaultPHP\SecretEngines\Transit */ -final class UpdateKeyConfigTest extends SecretEngineTest +final class UpdateKeyConfigTest extends AbstractSecretEngineTestCase { public function testApiCall() {