Improved API tests by adding fixtures

This commit is contained in:
Alejandro Celaya
2019-01-27 12:14:18 +01:00
parent ce515767ce
commit 05c7672de3
9 changed files with 196 additions and 3 deletions

View File

@@ -3,6 +3,9 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Common;
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
use Doctrine\Common\DataFixtures\Loader;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Process\Process;
use function file_exists;
use function realpath;
@@ -22,4 +25,20 @@ class TestHelper
$process->inheritEnvironmentVariables()
->mustRun();
}
public function seedFixtures(EntityManagerInterface $em, array $config): void
{
$paths = $config['paths'] ?? [];
if (empty($paths)) {
return;
}
$loader = new Loader();
foreach ($paths as $path) {
$loader->loadFromDirectory($path);
}
$executor = new ORMExecutor($em);
$executor->execute($loader->getFixtures(), true);
}
}