Skip to content

Commit

Permalink
Use a new class StringableTestObject
Browse files Browse the repository at this point in the history
  • Loading branch information
williamdes committed Jul 11, 2024
1 parent 509df95 commit e17e0eb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
8 changes: 1 addition & 7 deletions tests/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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());
}

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;
}
}
15 changes: 3 additions & 12 deletions tests/UriTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit e17e0eb

Please sign in to comment.