Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix menu in long-running process (RoadRunner, ReactPHP, Amphp) (#7885)
* Make Menu non-shared In order to have new instance for every request in Long-running process (ReactPHP, Amphp, RoadRunner) * add test case covering long-running process. * add test case covering long-running process. * add test case covering long-running process. * Fix test on SF4.4 * Fix test on SF4.4 * add description * Ignore psalm.
- Loading branch information
Showing
4 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\AdminBundle\Tests\App\EventListener; | ||
|
||
use Sonata\AdminBundle\Event\ConfigureMenuEvent; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
final class ConfigureMenu implements EventSubscriberInterface | ||
{ | ||
private int $counter = 0; | ||
|
||
public static function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
ConfigureMenuEvent::SIDEBAR => 'configureMenu', | ||
]; | ||
} | ||
|
||
public function configureMenu(ConfigureMenuEvent $configureMenuEvent): void | ||
{ | ||
$configureMenuEvent->getMenu()->addChild(sprintf('Dynamic Menu %s', ++$this->counter))->setAttribute('class', 'dynamic-menu'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\AdminBundle\Tests\Functional\Controller; | ||
|
||
use Sonata\AdminBundle\Tests\App\AppKernel; | ||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
final class MenuTest extends WebTestCase | ||
{ | ||
public function testDynamicMenuInLongRunningProcess(): void | ||
{ | ||
$client = static::createClient(); | ||
$client->disableReboot(); // forces requests to land at same Kernel, simulating long-running process like one used in roadrunner/reactphp/amphp | ||
|
||
for ($i = 1; $i < 5; ++$i) { | ||
$client->request(Request::METHOD_GET, '/admin/dashboard'); | ||
|
||
static::assertSame(Response::HTTP_OK, $client->getResponse()->getStatusCode()); | ||
|
||
$crawler = $client->getCrawler(); | ||
|
||
$menu = $crawler->filter('.sidebar-menu .dynamic-menu a'); | ||
|
||
static::assertCount(1, $menu); | ||
static::assertSame(sprintf('Dynamic Menu %s', $i), trim($menu->text())); | ||
} | ||
} | ||
|
||
protected static function getKernelClass(): string | ||
{ | ||
return AppKernel::class; | ||
} | ||
} |