Skip to content

Commit

Permalink
Remove httpMethodOverride
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Aug 2, 2021
1 parent 3162c7c commit 0eb043e
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 83 deletions.
9 changes: 0 additions & 9 deletions psalm-baseline.xml
Expand Up @@ -6,15 +6,6 @@
<code>$query</code>
</PropertyTypeCoercion>
</file>
<!-- https://github.com/vimeo/psalm/issues/5551 -->
<file src="tests/Controller/CRUDControllerTest.php">
<PossiblyInvalidFunctionCall occurrences="1">
<code>$disableHttpMethodParameterOverride()</code>
</PossiblyInvalidFunctionCall>
<UndefinedPropertyAssignment occurrences="1">
<code>self::$httpMethodParameterOverride</code>
</UndefinedPropertyAssignment>
</file>
<!-- This error is made on purpose for php version < 8 -->
<file src="tests/Fixtures/Entity/FooToStringNull.php">
<InvalidToString occurrences="1">
Expand Down
74 changes: 0 additions & 74 deletions tests/Controller/CRUDControllerTest.php
Expand Up @@ -139,11 +139,6 @@ final class CRUDControllerTest extends TestCase
*/
private $logger;

/**
* @var bool
*/
private $httpMethodParameterOverride = false;

/**
* @var Stub&FormFactoryInterface
*/
Expand All @@ -166,7 +161,6 @@ final class CRUDControllerTest extends TestCase

protected function setUp(): void
{
$this->httpMethodParameterOverride = Request::getHttpMethodParameterOverride();
$this->container = new Container();
$this->request = new Request();
$this->pool = new Pool($this->container, ['foo.admin']);
Expand Down Expand Up @@ -312,18 +306,6 @@ static function (string $name, object $object, array $parameters = []): string {
}
}

protected function tearDown(): void
{
parent::tearDown();

if (!$this->httpMethodParameterOverride && Request::getHttpMethodParameterOverride()) {
$disableHttpMethodParameterOverride = \Closure::bind(static function (): void {
self::$httpMethodParameterOverride = false;
}, null, Request::class);
$disableHttpMethodParameterOverride();
}
}

public function testRenderJson1(): void
{
$data = ['example' => '123', 'foo' => 'bar'];
Expand Down Expand Up @@ -1102,19 +1084,15 @@ public function testDeleteActionAjaxSuccess2(): void
->with(self::equalTo('delete'));

$this->request->setMethod(Request::METHOD_POST);
$this->request->request->set('_method', Request::METHOD_DELETE);
$this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');

$this->request->headers->set('X-Requested-With', 'XMLHttpRequest');

Request::enableHttpMethodParameterOverride();

$response = $this->controller->deleteAction($this->request);

self::assertInstanceOf(Response::class, $response);
self::assertSame(json_encode(['result' => 'ok']), $response->getContent());
self::assertSame([], $this->session->getFlashBag()->all());
self::assertSame(Request::METHOD_DELETE, $this->request->getMethod());
}

public function testDeleteActionAjaxError(): void
Expand Down Expand Up @@ -1238,45 +1216,6 @@ public function testDeleteActionSuccess2(string $expectedToStringValue, string $

$this->expectTranslate('flash_delete_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');

$this->request->setMethod(Request::METHOD_POST);
$this->request->request->set('_method', Request::METHOD_DELETE);

$this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');

Request::enableHttpMethodParameterOverride();

$response = $this->controller->deleteAction($this->request);

self::assertInstanceOf(RedirectResponse::class, $response);
self::assertSame(['flash_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
self::assertSame('list', $response->getTargetUrl());
self::assertSame(Request::METHOD_DELETE, $this->request->getMethod());
}

/**
* @dataProvider getToStringValues
*/
public function testDeleteActionSuccess3(string $expectedToStringValue, string $toStringValue): void
{
$this->request->attributes->set($this->admin->getIdParameter(), 21);

$object = new \stdClass();

$this->admin->expects(self::atLeastOnce())
->method('getObject')
->willReturn($object);

$this->admin->expects(self::once())
->method('checkAccess')
->with(self::equalTo('delete'));

$this->admin->expects(self::once())
->method('toString')
->with(self::equalTo($object))
->willReturn($toStringValue);

$this->expectTranslate('flash_delete_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');

$this->request->setMethod(Request::METHOD_POST);

$this->request->request->set('_sonata_csrf_token', 'csrf-token-123_sonata.delete');
Expand Down Expand Up @@ -1315,9 +1254,6 @@ public function testDeleteActionSuccessNoCsrfTokenProvider(string $expectedToStr
$this->expectTranslate('flash_delete_success', ['%name%' => $expectedToStringValue], 'SonataAdminBundle');

$this->request->setMethod(Request::METHOD_POST);
$this->request->request->set('_method', Request::METHOD_DELETE);

Request::enableHttpMethodParameterOverride();

$response = $this->controller->deleteAction($this->request);

Expand All @@ -1341,11 +1277,6 @@ public function testDeleteActionWrongRequestMethod(): void
->method('checkAccess')
->with(self::equalTo('delete'));

//without POST request parameter "_method" should not be used as real REST method
$this->request->query->set('_method', Request::METHOD_DELETE);

Request::enableHttpMethodParameterOverride();

$this->twig
->expects(self::once())
->method('render')
Expand Down Expand Up @@ -1414,19 +1345,14 @@ public function testDeleteActionInvalidCsrfToken(): void
->with(self::equalTo('delete'));

$this->request->setMethod(Request::METHOD_POST);
$this->request->request->set('_method', Request::METHOD_DELETE);
$this->request->request->set('_sonata_csrf_token', 'CSRF-INVALID');

Request::enableHttpMethodParameterOverride();

try {
$this->controller->deleteAction($this->request);
} catch (HttpException $e) {
self::assertSame('The csrf token is not valid, CSRF attack?', $e->getMessage());
self::assertSame(400, $e->getStatusCode());
}

self::assertSame(Request::METHOD_DELETE, $this->request->getMethod());
}

public function testDeleteActionChildManyToMany(): void
Expand Down

0 comments on commit 0eb043e

Please sign in to comment.