diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..7208d53 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,46 @@ +name: CI + +on: [push, pull_request] + +jobs: + build-test: + runs-on: ubuntu-latest + strategy: + matrix: + php_version: [8.1, 8.2, 8.3, 8.4] + composer_flags: ['', '--prefer-lowest'] + + steps: + - uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php_version }} + extensions: xdebug + + - name: Install dependencies + uses: php-actions/composer@v5 + with: + php_version: ${{ matrix.php_version }} + args: ${{ matrix.composer_flags }} + command: update + + - name: Run tests + run: ./vendor/bin/phpunit --coverage-clover ./tests/logs/clover.xml + env: + XDEBUG_MODE: coverage + + - name: Run Codesniffer + run: vendor/bin/phpcs --standard=PSR2 ./src + + # - name: Submit coverage to Coveralls + # # We use php-coveralls library for this, as the official Coveralls GitHub Action lacks support for clover reports: + # # https://github.com/coverallsapp/github-action/issues/15 + # env: + # COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # COVERALLS_PARALLEL: true + # COVERALLS_FLAG_NAME: ${{ github.job }}-PHP-${{ matrix.php_version }} ${{ matrix.composer_flags }} + # run: | + # composer global require php-coveralls/php-coveralls + # ~/.composer/vendor/bin/php-coveralls -v diff --git a/.gitignore b/.gitignore index 7579f74..9248812 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ vendor composer.lock +.phpunit.cache +.phpunit.result.cache diff --git a/composer.json b/composer.json index 26af239..be608fd 100644 --- a/composer.json +++ b/composer.json @@ -1,16 +1,15 @@ { "name": "rareloop/psr7-server-request-extension", "require": { - "psr/http-message": "^1.0" + "psr/http-message": "^2", + "php": ">=8.1" }, "require-dev": { - "laminas/laminas-diactoros": "^2.4", - "phpunit/phpunit": "^6.0", - "mockery/mockery": "^1.0.0", - "brain/monkey": "^2.0.2", - "satooshi/php-coveralls": "^1.0", - "squizlabs/php_codesniffer": "^3.5", - "codedungeon/phpunit-result-printer": "^0.4.4" + "laminas/laminas-diactoros": "^3.6", + "phpunit/phpunit": "^10.5", + "mockery/mockery": "^1.6", + "brain/monkey": "^2.6.2", + "squizlabs/php_codesniffer": "^3.7.2" }, "autoload": { "psr-4": { diff --git a/phpunit.xml b/phpunit.xml index 2ebc93b..66eb280 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,23 +1,13 @@ - - - - tests - - - - - src/ - - + + + + tests + + + + + src/ + + diff --git a/tests/TestDiactorosServerRequest.php b/tests/TestDiactorosServerRequest.php index 9370288..2e76e99 100644 --- a/tests/TestDiactorosServerRequest.php +++ b/tests/TestDiactorosServerRequest.php @@ -4,7 +4,7 @@ use Rareloop\Psr7ServerRequestExtension\InteractsWithInput; use Rareloop\Psr7ServerRequestExtension\InteractsWithUri; -use Zend\Diactoros\ServerRequest; +use Laminas\Diactoros\ServerRequest; class TestDiactorosServerRequest extends ServerRequest { diff --git a/tests/Unit/Psr7ServerRequestExtensionTest.php b/tests/Unit/Psr7ServerRequestExtensionTest.php index d8d7d6c..4bce977 100644 --- a/tests/Unit/Psr7ServerRequestExtensionTest.php +++ b/tests/Unit/Psr7ServerRequestExtensionTest.php @@ -2,12 +2,13 @@ namespace Rareloop\Psr7ServerRequestExtension\Test; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Rareloop\Psr7ServerRequestExtension\Test\TestDiactorosServerRequest as ServerRequest; class Psr7ServerRequestExtensionTest extends TestCase { - /** @test */ + #[Test] public function can_get_path() { $request = new ServerRequest([], [], '/test/123', 'GET'); @@ -15,7 +16,7 @@ public function can_get_path() $this->assertSame('/test/123', $request->path()); } - /** @test */ + #[Test] public function can_get_url_without_query_string() { $request = new ServerRequest([], [], 'https://test.com/test/123?foo=bar', 'GET'); @@ -23,7 +24,7 @@ public function can_get_url_without_query_string() $this->assertSame('https://test.com/test/123', $request->url()); } - /** @test */ + #[Test] public function can_get_url_with_query_string() { $request = new ServerRequest([], [], 'https://test.com/test/123?foo=bar', 'GET'); @@ -31,7 +32,7 @@ public function can_get_url_with_query_string() $this->assertSame('https://test.com/test/123?foo=bar', $request->fullUrl()); } - /** @test */ + #[Test] public function no_trailing_question_mark_is_added_when_no_query_params_are_present() { $request = new ServerRequest([], [], 'https://test.com/test/123', 'GET'); @@ -39,7 +40,7 @@ public function no_trailing_question_mark_is_added_when_no_query_params_are_pres $this->assertSame('https://test.com/test/123', $request->fullUrl()); } - /** @test */ + #[Test] public function can_check_method() { $request = new ServerRequest([], [], '/test/123', 'GET'); @@ -50,7 +51,7 @@ public function can_check_method() $this->assertFalse($request->isMethod('POST')); } - /** @test */ + #[Test] public function can_get_all_input() { $request = new ServerRequest([], [], '/test/123', 'GET', 'php://input', [], [], ['foo' => 'bar'], ['baz' => 'qux']); @@ -61,7 +62,7 @@ public function can_get_all_input() $this->assertSame('qux', $input['baz']); } - /** @test */ + #[Test] public function can_get_specific_input_with_key() { $request = new ServerRequest([], [], '/test/123', 'GET', 'php://input', [], [], ['foo' => 'bar'], ['baz' => 'qux']); @@ -70,7 +71,7 @@ public function can_get_specific_input_with_key() $this->assertSame('qux', $request->input('baz')); } - /** @test */ + #[Test] public function can_get_default_when_key_is_not_found_in_input() { $request = new ServerRequest([], [], '/test/123', 'GET'); @@ -78,7 +79,7 @@ public function can_get_default_when_key_is_not_found_in_input() $this->assertSame('bar', $request->input('foo', 'bar')); } - /** @test */ + #[Test] public function can_check_if_input_has_a_specific_key() { $request = new ServerRequest([], [], '/test/123', 'GET', 'php://input', [], [], ['foo' => 'bar']); @@ -87,7 +88,7 @@ public function can_check_if_input_has_a_specific_key() $this->assertFalse($request->has('baz')); } - /** @test */ + #[Test] public function can_check_if_input_has_collection_of_keys() { $request = new ServerRequest([], [], '/test/123', 'GET', 'php://input', [], [], ['foo' => 'bar'], ['baz' => 'qux']); @@ -95,7 +96,7 @@ public function can_check_if_input_has_collection_of_keys() $this->assertTrue($request->has(['foo', 'baz'])); } - /** @test */ + #[Test] public function can_get_all_query() { $request = new ServerRequest([], [], '/test/123', 'GET', 'php://input', [], [], ['foo' => 'bar'], ['baz' => 'qux']); @@ -106,7 +107,7 @@ public function can_get_all_query() $this->assertFalse(isset($input['baz'])); } - /** @test */ + #[Test] public function can_get_specific_query_with_key() { $request = new ServerRequest([], [], '/test/123', 'GET', 'php://input', [], [], ['foo' => 'bar'], ['baz' => 'qux']); @@ -114,7 +115,7 @@ public function can_get_specific_query_with_key() $this->assertSame('bar', $request->query('foo')); } - /** @test */ + #[Test] public function can_get_default_when_key_is_not_found_in_query() { $request = new ServerRequest([], [], '/test/123', 'GET'); @@ -122,7 +123,7 @@ public function can_get_default_when_key_is_not_found_in_query() $this->assertSame('bar', $request->query('foo', 'bar')); } - /** @test */ + #[Test] public function can_get_all_post() { $request = new ServerRequest([], [], '/test/123', 'GET', 'php://input', [], [], ['foo' => 'bar'], ['baz' => 'qux']); @@ -133,7 +134,7 @@ public function can_get_all_post() $this->assertFalse(isset($input['foo'])); } - /** @test */ + #[Test] public function can_get_specific_post_with_key() { $request = new ServerRequest([], [], '/test/123', 'GET', 'php://input', [], [], ['foo' => 'bar'], ['baz' => 'qux']); @@ -141,7 +142,7 @@ public function can_get_specific_post_with_key() $this->assertSame('qux', $request->post('baz')); } - /** @test */ + #[Test] public function can_get_default_when_key_is_not_found_in_post() { $request = new ServerRequest([], [], '/test/123', 'GET');