EasyAdmin 3 バックエンドで機能テストを実行したいと考えています。
基本的に、通常のユーザーがページにアクセスしたり、フィールドを表示したり、許可されていないアクションを表示/実行したりできないようにしたいと考えています。
最善の方法は何ですか?始めるのに見逃した便利なリソースはありますか?
EasyAdmin 3 バックエンドで機能テストを実行したいと考えています。
基本的に、通常のユーザーがページにアクセスしたり、フィールドを表示したり、許可されていないアクションを表示/実行したりできないようにしたいと考えています。
最善の方法は何ですか?始めるのに見逃した便利なリソースはありますか?
EasyAdmin 3 Crud コントローラーは、基本的に通常の Symfony コントローラーであるため、他の Symfony コントローラーと同様にテストできます。
<?php
// tests/Controller/AdminControllerTest.php
namespace App\Tests\Controller;
use App\Repository\UserRepository;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class AdminControllerTest extends WebTestCase
{
// ...
public function testVisitingWhileLoggedIn()
{
$client = static::createClient();
$userRepository = static::$container->get(UserRepository::class);
// retrieve the test user
$testUser = $userRepository->findOneByEmail('john.doe@example.com');
// simulate $testUser being logged in
$client->loginUser($testUser);
// test e.g. the admin page
$client->request('GET', '/admin');
$this->assertResponseStatusCodeSame(403);
}
}
EasyAdmin Crud Doc https://symfony.com/doc/current/bundles/EasyAdminBundle/crud.html
Symfony のテストhttps://symfony.com/doc/current/testing.html