mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Improved API tests by adding fixtures
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user