Skip to content

Commit 78e5109

Browse files
committed
change Request and Response classes in tests to guzzlehttp/psr7 package
1 parent 40967c5 commit 78e5109

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

stuff/Handler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace Stuff\Webclient\Extension\Log;
66

77
use Exception;
8-
use Nyholm\Psr7\Response;
8+
use GuzzleHttp\Psr7\Response;
99
use Psr\Http\Message\ResponseInterface;
1010
use Psr\Http\Message\ServerRequestInterface;
1111
use Psr\Http\Server\RequestHandlerInterface;

tests/LoggedClientTest.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Tests\Webclient\Extension\Log;
66

7-
use Nyholm\Psr7\Request;
7+
use GuzzleHttp\Psr7\Request;
88
use PHPUnit\Framework\TestCase;
99
use Psr\Http\Client\ClientExceptionInterface;
1010
use Psr\Log\LogLevel;
@@ -35,14 +35,6 @@ class LoggedClientTest extends TestCase
3535
*/
3636
private $generator;
3737

38-
public function setUp()
39-
{
40-
parent::setUp();
41-
$this->logger = new Logger();
42-
$this->generator = new StuffIdGenerator($this->getIdGenerator());
43-
$this->formatter = $this->getFormatter();
44-
}
45-
4638
/**
4739
* @param int $status
4840
* @param string $requestLevel
@@ -54,6 +46,7 @@ public function setUp()
5446
*/
5547
public function testLogging(int $status, string $requestLevel, string $responseLevel)
5648
{
49+
$this->init();
5750
$levels = $this->getFreeLevels([$requestLevel, $responseLevel]);
5851
$otherLevel = $levels[0];
5952
$params = [
@@ -89,6 +82,7 @@ public function testLogging(int $status, string $requestLevel, string $responseL
8982
*/
9083
public function testExceptionHandling(string $requestLevel, string $errorLevel)
9184
{
85+
$this->init();
9286
$levels = $this->getFreeLevels([$requestLevel, $errorLevel]);
9387
$otherLevel = $levels[0];
9488
$params = [
@@ -240,4 +234,12 @@ private function getFreeLevels(array $allowed): array
240234
}
241235
return array_keys($levels);
242236
}
237+
238+
private function init()
239+
{
240+
// this code moved from setUp() method for support older phpunit versions
241+
$this->logger = new Logger();
242+
$this->generator = new StuffIdGenerator($this->getIdGenerator());
243+
$this->formatter = $this->getFormatter();
244+
}
243245
}

tests/RawHttpFormatterTest.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
namespace Tests\Webclient\Extension\Log;
66

7-
use Nyholm\Psr7\Request;
8-
use Nyholm\Psr7\Response;
7+
use GuzzleHttp\Psr7\Request;
8+
use GuzzleHttp\Psr7\Response;
99
use PHPUnit\Framework\TestCase;
1010
use Stuff\Webclient\Extension\Log\Error;
1111
use Webclient\Extension\Log\Formatter\RawHttpFormatter;
@@ -23,13 +23,6 @@ class RawHttpFormatterTest extends TestCase
2323
*/
2424
private $formatter;
2525

26-
public function setUp()
27-
{
28-
parent::setUp();
29-
$this->id = 'r1';
30-
$this->formatter = new RawHttpFormatter();
31-
}
32-
3326
/**
3427
* @param string $method
3528
* @param string $uri
@@ -41,6 +34,7 @@ public function setUp()
4134
*/
4235
public function testRequest(string $method, string $uri, array $headers, string $body, string $protocolVersion)
4336
{
37+
$this->init();
4438
$request = new Request($method, $uri, $headers, $body, $protocolVersion);
4539
$expected = 'Request ' . $this->id . PHP_EOL;
4640
$expected .= $method . ' ' . $uri . ' HTTP/' . $protocolVersion . PHP_EOL;
@@ -65,6 +59,7 @@ public function testRequest(string $method, string $uri, array $headers, string
6559
*/
6660
public function testResponse(int $status, string $phrase, array $headers, string $body, string $protocolVersion)
6761
{
62+
$this->init();
6863
$response = new Response($status, $headers, $body, $protocolVersion, $phrase);
6964
$expected = 'Response ' . $this->id . PHP_EOL;
7065
$expected .= 'HTTP/' . $protocolVersion . ' ' . $status . ' ' . $phrase . PHP_EOL;
@@ -82,6 +77,7 @@ public function testResponse(int $status, string $phrase, array $headers, string
8277
*/
8378
public function testError(string $message)
8479
{
80+
$this->init();
8581
$error = new Error($message);
8682
$expected = 'Connection ' . $this->id . PHP_EOL;
8783
$expected .= 'Error: ' . $message;
@@ -115,4 +111,10 @@ public function provideError(): array
115111
['Network error'],
116112
];
117113
}
114+
115+
private function init()
116+
{
117+
$this->id = 'r1';
118+
$this->formatter = new RawHttpFormatter();
119+
}
118120
}

0 commit comments

Comments
 (0)