Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix phpunit deprecations #311

Merged
merged 4 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: Tests

permissions:
contents: read

on: [push, pull_request]

jobs:
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 }}
7 changes: 1 addition & 6 deletions tests/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,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 StringableTestObject('Slim OK'));
$this->assertEquals('Slim OK', $response->getReasonPhrase());
}

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

/**
* Slim Framework (https://slimframework.com)
*
* @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
*/

declare(strict_types=1);

namespace Slim\Tests\Psr7;

final class StringableTestObject implements \Stringable
{
public function __construct(private string $value)
{
}

public function __toString(): string
{
return $this->value;
}
}
2 changes: 1 addition & 1 deletion tests/UploadedFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ public function testCreateUploadedFileWithInvalidUri()
new UploadedFile($stream);
}

public function providerCreateFromGlobals(): array
public static function providerCreateFromGlobals(): array
{
return [
// no nest: <input name="avatar" type="file">
Expand Down
15 changes: 3 additions & 12 deletions tests/UriTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,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 StringableTestObject('host.test');

$uri = $this->uriFactory()->withHost($mock);
$this->assertEquals('host.test', $uri->getHost());
Expand Down Expand Up @@ -298,10 +295,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 StringableTestObject('xyz=123');

$uri = $this->uriFactory()->withQuery($mock);
$this->assertEquals('xyz=123', $uri->getQuery());
Expand Down Expand Up @@ -350,10 +344,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 StringableTestObject('other-fragment');

$uri = $this->uriFactory()->withFragment($mock);
$this->assertEquals('other-fragment', $uri->getFragment());
Expand Down
Loading