From 501b60fe5f102c6ee749c370c82d80d6b734ee57 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Sun, 9 Jun 2024 12:33:21 +0200 Subject: [PATCH 1/4] Fix phpunit static provider --- tests/UploadedFileTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/UploadedFileTest.php b/tests/UploadedFileTest.php index ec90abc..fa13a0c 100644 --- a/tests/UploadedFileTest.php +++ b/tests/UploadedFileTest.php @@ -430,7 +430,7 @@ public function testCreateUploadedFileWithInvalidUri() new UploadedFile($stream); } - public function providerCreateFromGlobals(): array + public static function providerCreateFromGlobals(): array { return [ // no nest: From 509df95b12835e85c41399452f8e739e6425e67f Mon Sep 17 00:00:00 2001 From: William Desportes Date: Sun, 9 Jun 2024 13:14:31 +0200 Subject: [PATCH 2/4] Remove the usage of mocks --- tests/ResponseTest.php | 13 +++++++------ tests/UriTest.php | 24 ++++++++++++------------ 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/tests/ResponseTest.php b/tests/ResponseTest.php index 7bd3206..0141888 100644 --- a/tests/ResponseTest.php +++ b/tests/ResponseTest.php @@ -22,6 +22,12 @@ use function fopen; use function property_exists; +final class TestException implements \Stringable { + public function __toString(): string { + return 'Slim OK'; + } +} + class ResponseTest extends TestCase { public function testConstructorWithDefaultArgs() @@ -141,13 +147,8 @@ public function testReasonPhraseContainsLineFeed() public function testWithStatusValidReasonPhraseObject() { - $mock = $this->getMockBuilder(stdClass::class)->addMethods(['__toString'])->getMock(); - $mock->expects($this->once()) - ->method('__toString') - ->will($this->returnValue('Slim OK')); - $response = new Response(); - $response = $response->withStatus(200, $mock); + $response = $response->withStatus(200, new TestException()); $this->assertEquals('Slim OK', $response->getReasonPhrase()); } diff --git a/tests/UriTest.php b/tests/UriTest.php index 92077ec..97c1347 100644 --- a/tests/UriTest.php +++ b/tests/UriTest.php @@ -15,6 +15,15 @@ use Slim\Psr7\Uri; use stdClass; +final class TestObject implements \Stringable { + + public function __construct(private readonly string $value) {} + + public function __toString(): string { + return $this->value; + } +} + class UriTest extends TestCase { public function uriFactory(): Uri @@ -133,10 +142,7 @@ public function testWithHost() public function testWithHostValidObject() { - $mock = $this->getMockBuilder(stdClass::class)->addMethods(['__toString'])->getMock(); - $mock->expects($this->once()) - ->method('__toString') - ->will($this->returnValue('host.test')); + $mock = new TestObject('host.test'); $uri = $this->uriFactory()->withHost($mock); $this->assertEquals('host.test', $uri->getHost()); @@ -298,10 +304,7 @@ public function testWithQueryEmpty() public function testWithQueryValidObject() { - $mock = $this->getMockBuilder(stdClass::class)->addMethods(['__toString'])->getMock(); - $mock->expects($this->once()) - ->method('__toString') - ->will($this->returnValue('xyz=123')); + $mock = new TestObject('xyz=123'); $uri = $this->uriFactory()->withQuery($mock); $this->assertEquals('xyz=123', $uri->getQuery()); @@ -350,10 +353,7 @@ public function testWithFragmentEmpty() public function testWithFragmentValidObject() { - $mock = $this->getMockBuilder(stdClass::class)->addMethods(['__toString'])->getMock(); - $mock->expects($this->once()) - ->method('__toString') - ->will($this->returnValue('other-fragment')); + $mock = new TestObject('other-fragment'); $uri = $this->uriFactory()->withFragment($mock); $this->assertEquals('other-fragment', $uri->getFragment()); From e17e0eb695309a0281417aecb067457baa7bc97d Mon Sep 17 00:00:00 2001 From: William Desportes Date: Sun, 9 Jun 2024 13:18:13 +0200 Subject: [PATCH 3/4] Use a new class StringableTestObject --- tests/ResponseTest.php | 8 +------- tests/StringableTestObject.php | 23 +++++++++++++++++++++++ tests/UriTest.php | 15 +++------------ 3 files changed, 27 insertions(+), 19 deletions(-) create mode 100644 tests/StringableTestObject.php diff --git a/tests/ResponseTest.php b/tests/ResponseTest.php index 0141888..7b73488 100644 --- a/tests/ResponseTest.php +++ b/tests/ResponseTest.php @@ -22,12 +22,6 @@ use function fopen; use function property_exists; -final class TestException implements \Stringable { - public function __toString(): string { - return 'Slim OK'; - } -} - class ResponseTest extends TestCase { public function testConstructorWithDefaultArgs() @@ -148,7 +142,7 @@ public function testReasonPhraseContainsLineFeed() public function testWithStatusValidReasonPhraseObject() { $response = new Response(); - $response = $response->withStatus(200, new TestException()); + $response = $response->withStatus(200, new StringableTestObject('Slim OK')); $this->assertEquals('Slim OK', $response->getReasonPhrase()); } diff --git a/tests/StringableTestObject.php b/tests/StringableTestObject.php new file mode 100644 index 0000000..36a6785 --- /dev/null +++ b/tests/StringableTestObject.php @@ -0,0 +1,23 @@ +value; + } +} diff --git a/tests/UriTest.php b/tests/UriTest.php index 97c1347..aeb3a85 100644 --- a/tests/UriTest.php +++ b/tests/UriTest.php @@ -15,15 +15,6 @@ use Slim\Psr7\Uri; use stdClass; -final class TestObject implements \Stringable { - - public function __construct(private readonly string $value) {} - - public function __toString(): string { - return $this->value; - } -} - class UriTest extends TestCase { public function uriFactory(): Uri @@ -142,7 +133,7 @@ public function testWithHost() public function testWithHostValidObject() { - $mock = new TestObject('host.test'); + $mock = new StringableTestObject('host.test'); $uri = $this->uriFactory()->withHost($mock); $this->assertEquals('host.test', $uri->getHost()); @@ -304,7 +295,7 @@ public function testWithQueryEmpty() public function testWithQueryValidObject() { - $mock = new TestObject('xyz=123'); + $mock = new StringableTestObject('xyz=123'); $uri = $this->uriFactory()->withQuery($mock); $this->assertEquals('xyz=123', $uri->getQuery()); @@ -353,7 +344,7 @@ public function testWithFragmentEmpty() public function testWithFragmentValidObject() { - $mock = new TestObject('other-fragment'); + $mock = new StringableTestObject('other-fragment'); $uri = $this->uriFactory()->withFragment($mock); $this->assertEquals('other-fragment', $uri->getFragment()); From b39ca1dd5df41c2db080a20a62b0fab4ebdce6f1 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Thu, 11 Jul 2024 11:43:07 +0200 Subject: [PATCH 4/4] Use coveralls GitHub action for tests and bump actions See: https://github.com/coverallsapp/github-action --- .github/workflows/tests.yml | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index bb85a67..0dff586 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,5 +1,8 @@ name: Tests +permissions: + contents: read + on: [push, pull_request] jobs: @@ -20,7 +23,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up PHP ${{ matrix.php }} uses: shivammathur/setup-php@v2 @@ -29,7 +32,7 @@ jobs: coverage: xdebug - name: Install dependencies with Composer - uses: ramsey/composer-install@v2 + uses: ramsey/composer-install@v3 - name: Coding standards if: matrix.analysis @@ -44,8 +47,10 @@ jobs: - 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 + uses: coverallsapp/github-action@v2 + with: + file: clover.xml + flag-name: php-${{ matrix.php }} + # See: https://github.com/coverallsapp/github-action?tab=readme-ov-file#complete-parallel-job-example + parallel: false # Until now only one job is set for analysis + github-token: ${{ secrets.GITHUB_TOKEN }}