Skip to content

Commit

Permalink
add test case covering long-running process.
Browse files Browse the repository at this point in the history
  • Loading branch information
Warxcell committed Jul 28, 2022
1 parent 6a1c337 commit af31e54
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
1 change: 1 addition & 0 deletions phpunit.xml.dist
Expand Up @@ -33,5 +33,6 @@ It's auto-generated by sonata-project/dev-kit package.
<php>
<ini name="precision" value="8" />
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0" />
<env name="KERNEL_CLASS" value="Sonata\AdminBundle\Tests\App\AppKernel" />
</php>
</phpunit>
34 changes: 34 additions & 0 deletions tests/App/EventListener/ConfigureMenu.php
@@ -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');
}
}
40 changes: 40 additions & 0 deletions tests/Functional/Controller/MenuTest.php
@@ -0,0 +1,40 @@
<?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 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();

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), $menu->innerText());
}
}
}

0 comments on commit af31e54

Please sign in to comment.