SonataAdminBundle: Symfony web test cases on search are not working since updates
Environment
Sonata packages
show
$ composer show --latest 'sonata-project/*'
sonata-project/admin-bundle 3.97.0 3.97.0 The missing Symfony Admin Generator
sonata-project/block-bundle 3.23.0 4.5.3 Symfony SonataBlockBundle
sonata-project/cache 2.1.1 2.1.1 Cache library
sonata-project/core-bundle 3.20.0 3.20.0 Symfony SonataCoreBundle (abandoned)
Package sonata-project/core-bundle is abandoned, you should avoid using it. No replacement was suggested.
sonata-project/doctrine-extensions 1.12.0 1.12.0 Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 3.33.0 3.33.0 Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/exporter 1.11.1 2.6.2 Lightweight Exporter library
sonata-project/form-extensions 0.1.2 1.9.0 Symfony form extensions
sonata-project/intl-bundle 2.7.0 2.10.1 Symfony SonataIntlBundle
sonata-project/twig-extensions 0.1.1 1.5.1 Sonata twig extensions
Symfony packages
show
$ composer show --latest 'symfony/*'
symfony/asset v5.2.4 v5.2.4 Manages URL generation and versioning of web assets such as CSS ...
symfony/browser-kit v5.2.0 v5.2.4 Symfony BrowserKit Component
symfony/cache v5.2.6 v5.2.6 Provides an extended PSR-6, PSR-16 (and tags) implementation
symfony/cache-contracts v2.4.0 v2.4.0 Generic abstractions related to caching
symfony/config v4.4.20 v5.2.4 Helps you find, load, combine, autofill and validate configurati...
symfony/console v4.4.21 v5.2.6 Eases the creation of beautiful and testable command line interf...
symfony/contracts v1.1.0 v2.4.0 A set of abstractions extracted out of the Symfony components
symfony/css-selector v5.0.8 v5.2.4 Symfony CssSelector Component
symfony/debug v4.4.20 v4.4.20 Provides tools to ease debugging PHP code
symfony/debug-bundle v4.4.8 v5.2.4 Symfony DebugBundle
symfony/dependency-injection v4.4.21 v5.2.6 Allows you to standardize and centralize the way objects are con...
symfony/deprecation-contracts v2.4.0 v2.4.0 A generic function and convention to trigger deprecation notices
symfony/doctrine-bridge v4.4.21 v5.2.6 Provides integration for Doctrine with various Symfony components
symfony/dom-crawler v5.2.0 v5.2.4 Symfony DomCrawler Component
symfony/dotenv v4.4.8 v5.2.4 Registers environment variables from a .env file
symfony/error-handler v4.4.21 v5.2.6 Provides tools to manage errors and ease debugging PHP code
symfony/event-dispatcher v4.4.20 v5.2.4 Provides tools that allow your application components to communi...
symfony/event-dispatcher-contracts v1.1.9 v2.4.0 Generic abstractions related to dispatching event
symfony/expression-language v4.4.20 v5.2.4 Provides an engine that can compile and evaluate expressions
symfony/filesystem v4.4.21 v5.2.6 Provides basic utilities for the filesystem
symfony/finder v5.2.4 v5.2.4 Finds files and directories via an intuitive fluent interface
symfony/flex v1.11.0 v1.12.2 Composer plugin for Symfony
symfony/form v4.4.21 v5.2.6 Allows to easily create, process and reuse HTML forms
symfony/framework-bundle v4.4.21 v5.2.6 Provides a tight integration between Symfony components and the ...
symfony/http-client v5.0.11 v5.2.6 Symfony HttpClient component
symfony/http-client-contracts v2.4.0 v2.4.0 Generic abstractions related to HTTP clients
symfony/http-foundation v4.4.20 v5.2.4 Defines an object-oriented layer for the HTTP specification
symfony/http-kernel v4.4.21 v5.2.6 Provides a structured process for converting a Request into a Re...
symfony/inflector v5.2.6 v5.2.6 Converts words between their singular and plural forms (English ...
symfony/intl v4.4.20 v5.2.4 Provides a PHP replacement layer for the C intl extension that i...
symfony/lock v4.4.8 v5.2.6 Symfony Lock Component
symfony/messenger v4.4.19 v5.2.5 Helps applications send and receive messages to/from other appli...
symfony/mime v5.2.6 v5.2.6 Allows manipulating MIME messages
symfony/monolog-bridge v5.0.8 v5.2.5 Symfony Monolog Bridge
symfony/monolog-bundle v3.5.0 v3.7.0 Symfony MonologBundle
symfony/options-resolver v4.4.20 v5.2.4 Provides an improved replacement for the array_replace PHP function
symfony/orm-pack v2.1.0 v2.1.0 A pack for the Doctrine ORM
symfony/phpunit-bridge v4.4.8 v5.2.6 Symfony PHPUnit Bridge
symfony/polyfill-ctype v1.22.1 v1.22.1 Symfony polyfill for ctype functions
symfony/polyfill-iconv v1.15.0 v1.22.1 Symfony polyfill for the Iconv extension
symfony/polyfill-intl-grapheme v1.22.1 v1.22.1 Symfony polyfill for intl's grapheme_* functions
symfony/polyfill-intl-icu v1.22.1 v1.22.1 Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-intl-idn v1.22.1 v1.22.1 Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
symfony/polyfill-intl-normalizer v1.22.1 v1.22.1 Symfony polyfill for intl's Normalizer class and related functions
symfony/polyfill-mbstring v1.22.1 v1.22.1 Symfony polyfill for the Mbstring extension
symfony/polyfill-php72 v1.22.1 v1.22.1 Symfony polyfill backporting some PHP 7.2+ features to lower PHP...
symfony/polyfill-php73 v1.22.1 v1.22.1 Symfony polyfill backporting some PHP 7.3+ features to lower PHP...
symfony/polyfill-php80 v1.22.1 v1.22.1 Symfony polyfill backporting some PHP 8.0+ features to lower PHP...
symfony/polyfill-uuid v1.18.1 v1.22.1 Symfony polyfill for uuid functions
symfony/process v4.4.8 v5.2.4 Symfony Process Component
symfony/property-access v4.4.20 v5.2.4 Provides functions to read and write from/to an object or array ...
symfony/property-info v5.2.4 v5.2.4 Extracts information about PHP class' properties using metadata ...
symfony/proxy-manager-bridge v4.4.20 v5.2.4 Provides integration for ProxyManager with various Symfony compo...
symfony/psr-http-message-bridge v1.3.0 v2.1.0 PSR HTTP message bridge
symfony/routing v4.4.20 v5.2.6 Maps an HTTP request to a set of configuration variables
symfony/security v4.4.21 v4.4.21 Provides a complete security system for your web application
symfony/security-acl v3.1.1 v3.1.1 Symfony Security Component - ACL (Access Control List)
symfony/security-bundle v4.4.21 v5.2.6 Provides a tight integration of the Security component into the ...
symfony/serializer v4.4.20 v5.2.4 Handles serializing and deserializing data structures, including...
symfony/serializer-pack v1.0.4 v1.0.4 A pack for the Symfony serializer
symfony/service-contracts v2.4.0 v2.4.0 Generic abstractions related to writing services
symfony/stopwatch v5.2.4 v5.2.4 Provides a way to profile code
symfony/string v5.2.6 v5.2.6 Provides an object-oriented API to strings and deals with bytes,...
symfony/swiftmailer-bundle v3.4.0 v3.5.2 Symfony SwiftmailerBundle
symfony/templating v4.4.20 v5.2.4 Provides all the tools needed to build any kind of template system
symfony/translation v4.4.21 v5.2.6 Provides tools to internationalize your application
symfony/translation-contracts v2.4.0 v2.4.0 Generic abstractions related to translation
symfony/twig-bridge v4.4.21 v5.2.6 Provides integration for Twig with various Symfony components
symfony/twig-bundle v4.4.20 v5.2.4 Provides a tight integration of Twig into the Symfony full-stack...
symfony/validator v4.4.21 v5.2.6 Provides tools to validate values
symfony/var-dumper v4.4.21 v5.2.6 Provides mechanisms for walking through any arbitrary PHP variable
symfony/var-exporter v5.2.4 v5.2.4 Allows exporting any serializable PHP data structure to plain PH...
symfony/web-link v4.4.21 v5.2.5 Manages links between resources
symfony/web-profiler-bundle v4.4.8 v5.2.6 Symfony WebProfilerBundle
symfony/webpack-encore-bundle v1.7.3 v1.11.1 Integration with your Symfony app & Webpack Encore!
symfony/yaml v4.4.21 v5.2.5 Loads and dumps YAML files
PHP version
$ php -v
PHP 7.4.13 (cli) (built: Dec 1 2020 04:25:48) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.13, Copyright (c), by Zend Technologies
Subject
Since project update section including Sonata (see diff below), the following web test case if broken:
<?php
declare(strict_types=1);
namespace App\Tests\Controller;
use App\Entity\Payment;
use App\Enum\PaymentMethod;
use App\Manager\BillingManager;
use App\Tests\Fixtures\Entity\Factory\MockEntityFactory;
use Sonata\AdminBundle\Admin\AdminInterface;
final class AdminControllerTest extends WebTestCase
{
public function testSecurityAccess(): void
{
$client = $this->makeAuthenticatedClient();
$client->request('GET', $this->getUrl('sonata_admin_dashboard'));
$this->assertStatusCode(403, $client);
}
/**
* @dataProvider getSearchTestData
*/
public function testSearch(string $username, string $query, string $expectedLink): void
{
$client = $this->makeClient();
$this->loginClient($client, $this->getReference($username), 'main');
$crawler = $client->request('GET', $this->getUrl('sonata_admin_search', ['q' => $query]));
$this->assertStatusCode(200, $client);
self::assertStringContainsString($expectedLink, $crawler->text());
}
/**
* @return string[][]
*/
public function getSearchTestData(): array
{
return [
['user_super_admin', 'default', 'John DOE'],
['user_super_admin', 'default', 'default.net (Hello World)'],
['user_support', 'default', 'John DOE'],
['user_support', 'default', 'default.net (Hello World)'],
['user_commercial', 'default', 'John DOE'],
['user_commercial', 'default', 'default.net (Hello World)'],
];
}
/**
* {@inheritdoc}
*/
protected function getFixturesFiles(): array
{
return \array_merge([
__DIR__.'/../fixtures/orm/server.yml',
], parent::getFixturesFiles());
}
}
As you can see, it’s a simple search request with result parsing. The facts are:
- The first test produced by
getSearchTestDatais working, not the others. - If I comment the first working test case, the second is now working, but not the others and so one/
- If I duplicate the
$client->request(...line, the first test is directly failing. So it looks like to be cache issue or something like that.
The error talks about wrong parameters count matching:
An exception has been thrown during the rendering of a template ("Too many parameters: the query defines 1 parameters and you bound 6").
#0 /app/vendor/php/twig/twig/src/Template.php(254): Twig\Template->displayBlock()
#1 /app/var/cache/test/twig/1f/1ff9991e64b263798a51c53069e2112f3c4e20f948a678919c3050be71fca03e.php(88): Twig\Template->renderBlock()
#2 /app/vendor/php/twig/twig/src/Template.php(405): __TwigTemplate_d8638b4c611d530b87eb583bf911564e435be5fd65394b1e813e6ba99073dede->doDisplay()
#3 /app/vendor/php/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling()
#4 /app/var/cache/test/twig/b5/b50f61e182d0d7bfab2f836f6108db48bce5463f2614612b3ff744d07c085196.php(54): Twig\Template->display()
#5 /app/vendor/php/twig/twig/src/Template.php(405): __TwigTemplate_020c7a76e8697b40c336b5293b36074cc9c8202fb00f60598eb7671f966bcaeb->doDisplay()
#6 /app/vendor/php/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling()
#7 /app/var/cache/test/twig/47/475779e5fc04a8f6d9e88fb4ec44db2663cc386f35bde619bc2ffb2387c66220.php(49): Twig\Template->display()
#8 /app/vendor/php/twig/twig/src/Template.php(405): __TwigTemplate_9d3c57896179d3c61683a1bea2880930692cdc4ec2ddd801837081ed6d67f03f->doDisplay()
#9 /app/vendor/php/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling()
#10 /app/vendor/php/twig/twig/src/Template.php(390): Twig\Template->display()
#11 /app/vendor/php/twig/twig/src/TemplateWrapper.php(45): Twig\Template->render()
#12 /app/vendor/php/twig/twig/src/Environment.php(318): Twig\TemplateWrapper->render()
#13 /app/vendor/php/sonata-project/admin-bundle/src/Action/SearchAction.php(86): Twig\Environment->render()
#14 /app/vendor/php/symfony/http-kernel/HttpKernel.php(158): Sonata\AdminBundle\Action\SearchAction->__invoke()
#15 /app/vendor/php/symfony/http-kernel/HttpKernel.php(80): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#16 /app/vendor/php/symfony/http-kernel/Kernel.php(201): Symfony\Component\HttpKernel\HttpKernel->handle()
#17 /app/vendor/php/symfony/http-kernel/Client.php(65): Symfony\Component\HttpKernel\Kernel->handle()
#18 /app/vendor/php/symfony/framework-bundle/Client.php(131): Symfony\Component\HttpKernel\Client->doRequest()
#19 /app/vendor/php/symfony/browser-kit/AbstractBrowser.php(384): Symfony\Bundle\FrameworkBundle\Client->doRequest()
#20 /app/tests/Controller/AdminControllerTest.php(30): Symfony\Component\BrowserKit\AbstractBrowser->request()
#21 /app/vendor/php/phpunit/phpunit/src/Framework/TestCase.php(1413): App\Tests\Controller\AdminControllerTest->testSearch()
#22 /app/vendor/php/phpunit/phpunit/src/Framework/TestCase.php(1030): PHPUnit\Framework\TestCase->runTest()
#23 /app/vendor/php/phpunit/phpunit/src/Framework/TestResult.php(692): PHPUnit\Framework\TestCase->runBare()
#24 /app/vendor/php/phpunit/phpunit/src/Framework/TestCase.php(771): PHPUnit\Framework\TestResult->run()
#25 /app/vendor/php/phpunit/phpunit/src/Framework/TestSuite.php(638): PHPUnit\Framework\TestCase->run()
#26 /app/vendor/php/phpunit/phpunit/src/Framework/TestSuite.php(638): PHPUnit\Framework\TestSuite->run()
#27 /app/vendor/php/phpunit/phpunit/src/Framework/TestSuite.php(638): PHPUnit\Framework\TestSuite->run()
#28 /app/vendor/php/phpunit/phpunit/src/Framework/TestSuite.php(638): PHPUnit\Framework\TestSuite->run()
#29 /app/vendor/php/phpunit/phpunit/src/TextUI/TestRunner.php(657): PHPUnit\Framework\TestSuite->run()
#30 /app/vendor/php/phpunit/phpunit/src/TextUI/Command.php(108): PHPUnit\TextUI\TestRunner->run()
#31 /app/vendor/php/phpunit/phpunit/src/TextUI/Command.php(68): PHPUnit\TextUI\Command->run()
#32 /app/vendor/php/phpunit/phpunit/phpunit(61): PHPUnit\TextUI\Command::main()
#33 {main}
Failed asserting that 500 matches expected 200.
/app/vendor/php/liip/functional-test-bundle/src/Utils/HttpAssertions.php:83
/app/vendor/php/liip/functional-test-bundle/src/Test/WebTestCase.php:443
/app/tests/Controller/AdminControllerTest.php:32
After some dump digging, I detected that the queries between the first working request and the others are indeed different:
# Working request
SELECT o FROM App\Entity\User o WHERE o.username LIKE :username_0 OR o.firstname LIKE :firstname_1 OR o.lastname LIKE :lastname_2 OR o.company LIKE :company_3 OR o.email LIKE :email_4 ORDER BY o.id ASC
# Not working requests
SELECT o FROM App\Entity\User o ORDER BY o.id ASC
As you can see, the WHERE clause looks to be dropped, or not build.
The question is: Why? And I didn’t find the source of the issue for now.
As only the first request is working, I mainly suspect https://github.com/sonata-project/SonataAdminBundle/commit/5386609a0f65905231ac8549cd31689211d22cf6 where the datagrid is prevented to be built if already loaded.
However, I maybe wrong and I cannot prove it because removing this part caue infinite loops on my tests.
Update diff
diff --git a/composer.json b/composer.json
index cf5e6b507..3368a7473 100644
--- a/composer.json
+++ b/composer.json
@@ -35,24 +35,24 @@
"ext-openssl": "^7.1",
"a2lix/translation-form-bundle": "^3.0",
"algatux/influxdb-bundle": "^2.3",
- "api-platform/api-pack": "^1.1",
- "api-platform/core": "^2.3.5",
+ "api-platform/api-pack": "^1.3",
+ "api-platform/core": "^2.6",
"behat/transliterator": "^1.2",
"cebe/markdown": "^1.1",
"digitick/sepa-xml": "^1.0",
"doctrine/annotations": "^1.6",
"doctrine/cache": "^1.7",
"doctrine/collections": "^1.5",
- "doctrine/common": "^2.9",
+ "doctrine/common": "^3.0",
"doctrine/dbal": "^2.6",
- "doctrine/doctrine-bundle": "^1.6",
+ "doctrine/doctrine-bundle": "^2.3",
"doctrine/doctrine-cache-bundle": "^1.3",
- "doctrine/doctrine-migrations-bundle": "^1.0",
+ "doctrine/doctrine-migrations-bundle": "^3.1",
"doctrine/event-manager": "^1.0",
- "doctrine/inflector": "^1.3",
- "doctrine/migrations": "^1.6",
- "doctrine/orm": "^2.6",
- "doctrine/persistence": "^1.0",
+ "doctrine/inflector": "^1.4",
+ "doctrine/migrations": "^3.1",
+ "doctrine/orm": "^2.8",
+ "doctrine/persistence": "^2.0",
"egulias/email-validator": "^2.1",
"emojione/emojione": "^4.0",
"endroid/qr-code-bundle": "^3.3",
@@ -67,16 +67,16 @@
"guzzlehttp/guzzle": "^6.0",
"hackzilla/password-generator": "^1.4",
"hackzilla/password-generator-bundle": "^3.0",
- "hautelook/alice-bundle": "^2.0",
+ "hautelook/alice-bundle": "^2.9",
"incenteev/composer-parameter-handler": "^2.0",
"influxdb/influxdb-php": "^1.14",
"internations/solr-utils": "^0.8",
"jms/translation-bundle": "^1.4",
- "knplabs/doctrine-behaviors": "^1.4",
+ "knplabs/doctrine-behaviors": "^2.0",
"knplabs/knp-components": "^1.3",
"knplabs/knp-markdown-bundle": "^1.3",
- "knplabs/knp-menu": "^2.3",
- "knplabs/knp-menu-bundle": "^2.0",
+ "knplabs/knp-menu": "^3.1",
+ "knplabs/knp-menu-bundle": "^3.1",
"knplabs/knp-paginator-bundle": "^2.4.3",
"knpuniversity/oauth2-client-bundle": "^2.1",
"kriswallsmith/spork": "^0.3",
@@ -111,20 +111,21 @@
"ramsey/uuid": "^4.0",
"rollerworks/password-strength-bundle": "^2.0",
"rollerworks/password-strength-validator": "^1.0",
- "sensio/framework-extra-bundle": "^5.2",
+ "sensio/framework-extra-bundle": "^5.6.1",
"sentry/sentry-symfony": "^3.5",
"simplethings/entity-audit-bundle": "^1.0.1",
"sllh/iso-codes-validator": "^4.0",
"snc/redis-bundle": "^3.2.2",
- "sonata-project/admin-bundle": "^3.3",
- "sonata-project/block-bundle": "^3.12",
- "sonata-project/core-bundle": "^3.9",
+ "sonata-project/admin-bundle": "^3.96",
+ "sonata-project/block-bundle": "^3.23",
+ "sonata-project/core-bundle": "^3.20",
"sonata-project/doctrine-extensions": "^1.0",
- "sonata-project/doctrine-orm-admin-bundle": "^3.0.3",
+ "sonata-project/doctrine-orm-admin-bundle": "^3.32",
"sonata-project/exporter": "^1.9",
"sonata-project/intl-bundle": "^2.2",
- "stof/doctrine-extensions-bundle": "^1.1",
+ "stof/doctrine-extensions-bundle": "^1.6",
"swiftmailer/swiftmailer": "^6.0",
+ "symfony/cache": "^5.2",
"symfony/config": "^4.2",
"symfony/console": "^4.3",
"symfony/contracts": "^1.0",
@@ -146,7 +147,7 @@
"symfony/options-resolver": "^4.1",
"symfony/process": "^4.1",
"symfony/property-access": "^4.1",
- "symfony/property-info": "^4.1",
+ "symfony/property-info": "^5.2",
"symfony/proxy-manager-bridge": "^4.1",
"symfony/psr-http-message-bridge": "^1.0",
"symfony/routing": "^4.1",
@@ -174,20 +175,19 @@
},
"require-dev": {
"dama/doctrine-test-bundle": "^5.0",
- "doctrine/doctrine-fixtures-bundle": "^3.0",
+ "doctrine/doctrine-fixtures-bundle": "^3.4",
"fzaninotto/faker": "^1.7",
"liip/functional-test-bundle": "^4.2",
"liip/test-fixtures-bundle": "^1.11",
"php-http/mock-client": "^1.1",
"roave/security-advisories": "dev-master",
- "sonata-project/easy-extends-bundle": "^2.5",
"symfony/debug-bundle": "^4.0",
"symfony/phpunit-bridge": "^4.3.4",
"symfony/var-dumper": "^4.0",
"symfony/web-profiler-bundle": "^4.0"
},
"conflict": {
- "api-platform/core": "2.5.4 - 2.5.5",
+ "a2lix/auto-form-bundle": "<0.3.3",
"fzaninotto/faker": "<=1.5.0",
"hautelook/alice-bundle": "2.1.0 - 2.2.0",
"knplabs/knp-markdown-bundle": "1.5.0",
Minimal repository with the bug
Steps to reproduce
N/A for now, some help would be welcomed.
Expected results
Working functionnal tests.
Actual results
Only the first test is working.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 15 (15 by maintainers)
I’ll try to find some time this weekend.
You’re having an issue in your tests only. The tear down method could have some impacts
You was right, downgrading to 3.31.0 resolves the problem. 👍