setup phpunit for testing

This commit is contained in:
Jannis Portmann 2021-05-06 11:31:06 +02:00
parent 1680667cf1
commit af34c70b90
8 changed files with 629 additions and 4 deletions

View file

@ -0,0 +1,28 @@
<?php
namespace App\Tests\Controller;
use App\Repository\UserRepository;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class UserControllerTest extends WebTestCase
{
public function testUserPage(): void
{
$client = static::createClient();
$userRepository = static::$container->get(UserRepository::class);
$client->catchExceptions(false);
// retrieve the test user
$testUser = $userRepository->findOneByEmail('jannis@thisfro.ch');
// simulate $testUser being logged in
$client->loginUser($testUser);
// test e.g. the profile page
$client->request('GET', '/user');
$this->assertResponseIsSuccessful();
$this->assertSelectorTextContains('h1', 'Hello thisfro!');
}
}

11
tests/bootstrap.php Normal file
View file

@ -0,0 +1,11 @@
<?php
use Symfony\Component\Dotenv\Dotenv;
require dirname(__DIR__).'/vendor/autoload.php';
if (file_exists(dirname(__DIR__).'/config/bootstrap.php')) {
require dirname(__DIR__).'/config/bootstrap.php';
} elseif (method_exists(Dotenv::class, 'bootEnv')) {
(new Dotenv())->bootEnv(dirname(__DIR__).'/.env');
}