Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.x into Master #7357

Merged
merged 3 commits into from Aug 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -92,7 +92,7 @@
"symfony/maker-bundle": "^1.25",
"symfony/phpunit-bridge": "^5.3",
"symfony/yaml": "^4.4 || ^5.3",
"vimeo/psalm": "^4.7.2"
"vimeo/psalm": "^4.9.2"
},
"suggest": {
"twig/extra-bundle": "Auto configures the Twig Intl extension"
Expand Down
6 changes: 0 additions & 6 deletions psalm-baseline.xml
Expand Up @@ -6,12 +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>
</file>
<!-- This error is made on purpose for php version < 8 -->
<file src="tests/Fixtures/Entity/FooToStringNull.php">
<InvalidToString occurrences="1">
Expand Down
75 changes: 0 additions & 75 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,16 +1254,12 @@ 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);

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());
}

public function testDeleteActionWrongRequestMethod(): void
Expand All @@ -1341,11 +1276,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 +1344,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
4 changes: 2 additions & 2 deletions tests/Twig/Extension/SonataAdminExtensionTest.php
Expand Up @@ -43,12 +43,12 @@ final class SonataAdminExtensionTest extends TestCase
private $environment;

/**
* @var AdminInterface<object>&MockObject
* @var AdminInterface<\stdClass>&MockObject
*/
private $admin;

/**
* @var AdminInterface<object>&MockObject
* @var AdminInterface<\stdClass>&MockObject
*/
private $adminBar;

Expand Down