Skip to content

Commit 81c14fc

Browse files
committed
Added request method checking
1 parent d16053f commit 81c14fc

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

src/PathMock.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,19 @@ final class PathMock implements MockInterface
1313
/** @var ResponseInterface */
1414
private $response;
1515

16-
public function __construct(string $path, ResponseInterface $response)
16+
/** @var string */
17+
private $method;
18+
19+
public function __construct(string $path, ResponseInterface $response, string $method = 'GET')
1720
{
1821
$this->path = $path;
1922
$this->response = $response;
23+
$this->method = $method;
2024
}
2125

2226
public function match(RequestInterface $request): bool
2327
{
24-
return $request->getUri()->getPath() === $this->path;
28+
return $request->getMethod() === $this->method && $request->getUri()->getPath() === $this->path;
2529
}
2630

2731
public function response(RequestInterface $request): ResponseInterface

tests/PathMockTest.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/**
1111
* @internal
1212
*/
13-
class PathMockTest extends TestCase
13+
final class PathMockTest extends TestCase
1414
{
1515
public function testMatch(): void
1616
{
@@ -32,4 +32,25 @@ public function testResponse(): void
3232
$mock = new PathMock('/path', $response);
3333
self::assertSame($response, $mock->response(new Request('GET', '/path')));
3434
}
35+
36+
public function testMatchMethod(): void
37+
{
38+
$response = new Response();
39+
$mock = new PathMock('/path', $response, 'POST');
40+
self::assertTrue($mock->match(new Request('POST', '/path')));
41+
}
42+
43+
public function testNoMatchMethod(): void
44+
{
45+
$response = new Response();
46+
$mock = new PathMock('/', $response);
47+
self::assertFalse($mock->match(new Request('POST', '/path')));
48+
}
49+
50+
public function testResponseMethod(): void
51+
{
52+
$response = new Response();
53+
$mock = new PathMock('/path', $response, 'POST');
54+
self::assertSame($response, $mock->response(new Request('POST', '/path')));
55+
}
3556
}

0 commit comments

Comments
 (0)