Skip to content

Commit

Permalink
test(feat): add Doctrine fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
chiqui3d committed May 7, 2023
1 parent 5bec106 commit 8e0b776
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
15 changes: 9 additions & 6 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@

require __DIR__.'/../vendor/autoload.php';

DG\BypassFinals::enable();


(new Dotenv())->bootEnv(__DIR__.'/.env');

DG\BypassFinals::enable();
// Create and boot 'test' kernel
$kernel = new TestKernel('test', (bool)$_ENV['APP_DEBUG']);
$kernel->boot();
Expand All @@ -38,7 +37,6 @@
'--force' => true,
])
);

$application->run(
new ArrayInput([
'command' => 'doctrine:database:create',
Expand All @@ -49,9 +47,14 @@
new ArrayInput([
'command' => 'doctrine:schema:update',
'--force' => true,
'--complete' => true,
'--complete' => true
])
);

$queryFixtures = "INSERT INTO user (username,password,email,roles) VALUES ('jcarlos','password','jcarlos@test.test','[\"ROLE_USER\"]'),('pedro','password','pedro@test.test','[\"ROLE_USER\"]')";
$application->run(new StringInput(sprintf('%s "%s"', 'dbal:run-sql', \addslashes($queryFixtures))));
$application->run(
new ArrayInput([
'command' => 'doctrine:fixtures:load',
'--no-interaction' => true,
'--env' => 'test'
])
);
32 changes: 32 additions & 0 deletions tests/src/DataFixtures/UserFixtures.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);


namespace Ranky\MediaBundle\Tests\DataFixtures;

use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
use Ranky\MediaBundle\Tests\Dummy\User\Domain\User;

class UserFixtures extends Fixture
{
public function load(ObjectManager $manager): void
{
$user = new User();
$user->setUsername('jcarlos');
$user->setPassword('password');
$user->setEmail('jcarlos@test.test');
$user->setRoles(['ROLE_USER']);
$manager->persist($user);

$user = new User();
$user->setUsername('pedro');
$user->setPassword('password');
$user->setEmail('pedro@test.test');
$user->setRoles(['ROLE_ADMIN']);
$manager->persist($user);

$manager->flush();
}
}
2 changes: 2 additions & 0 deletions tests/src/TestKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Ranky\MediaBundle\Tests;

use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle;
use FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle;
use Ranky\MediaBundle\RankyMediaBundle;
use Ranky\SharedBundle\RankySharedBundle;
Expand All @@ -26,6 +27,7 @@ public function registerBundles(): array
return [
new FrameworkBundle(),
new DoctrineBundle(),
new DoctrineFixturesBundle(),
new SecurityBundle(),
new TwigBundle(),
new RankySharedBundle(),
Expand Down

0 comments on commit 8e0b776

Please sign in to comment.