Skip to content

Commit

Permalink
fix(testing-bundle): add "real" request method to test requests
Browse files Browse the repository at this point in the history
Fix: #165
  • Loading branch information
calvinalkan committed Dec 6, 2022
1 parent 0aa41b3 commit b063298
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/Snicco/Bundle/testing/src/Functional/Browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Webmozart\Assert\Assert;

use function array_keys;
use function array_merge;
use function in_array;
use function is_array;
use function parse_str;
Expand Down Expand Up @@ -131,7 +132,9 @@ protected function filterRequest(BrowserKitRequest $request): Request
$psr_server_request = $this->request_factory->createServerRequest(
$request->getMethod(),
$request->getUri(),
$request->getServer(),
array_merge([
'REQUEST_METHOD' => $request->getMethod(),
], $request->getServer())
);

$psr_server_request = $this->addHeadersFromServer($request, $psr_server_request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,32 @@ public function that_the_raw_content_is_transformed_and_used_in_the_psr7_request
->assertNotDelegated();
}

/**
* @test
*/
public function that_the_real_request_method_is_added_correctly(): void
{
$browser = $this->getBrowser();

$browser->request('POST', '/real-method');
$browser->getResponse()
->assertOk()
->assertSeeText('POST')
->assertNotDelegated();

$browser->request('PUT', '/real-method');
$browser->getResponse()
->assertOk()
->assertSeeText('PUT')
->assertNotDelegated();

$browser->request('GET', '/real-method');
$browser->getResponse()
->assertOk()
->assertSeeText('GET')
->assertNotDelegated();
}

/**
* @test
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ public function rawBody(Request $request): Response
->html((string) $request->getBody());
}

public function realMethod(Request $request): Response
{
return $this->respondWith()
->html($request->realMethod());
}

public function admin(): Response
{
return $this->respondWith()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

$router->post('raw-body', '/raw-body', [WebTestCaseController::class, 'rawBody']);

$router->any('real-method', '/real-method', [WebTestCaseController::class, 'realMethod']);

$router->get(
'force-exception-middleware',
'/force-exception-middleware',
Expand Down
2 changes: 1 addition & 1 deletion src/Snicco/Middleware/wp-nonce/src/WPNonce.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __invoke(string $route_name = null, array $args = []): string

return $this->createNonce($nonce_action);
}

/**
* @psalm-suppress DeprecatedClass
*/
Expand Down

0 comments on commit b063298

Please sign in to comment.