[TESTS][MODULES] Move Test Fixtures to tests/fixtures folder and add support for loading fixtures from components and plugins
This commit is contained in:
parent
18864ca9fa
commit
1d8bba3949
|
@ -112,7 +112,8 @@
|
|||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"App\\Tests\\": "tests/"
|
||||
"App\\Test\\Fixtures\\": "tests/fixtures/",
|
||||
"App\\Test\\": "tests/"
|
||||
}
|
||||
},
|
||||
"replace": {
|
||||
|
|
|
@ -15,6 +15,9 @@ services:
|
|||
resource: '../src/*'
|
||||
exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php,Routes}'
|
||||
|
||||
App\Test\Fixtures\:
|
||||
resource: '../tests/fixtures/*'
|
||||
|
||||
# controllers are imported separately to make sure services can be injected
|
||||
# as action arguments even if you don't extend any base controller class
|
||||
App\Controller\:
|
||||
|
|
|
@ -44,6 +44,7 @@ use Functional as F;
|
|||
use RecursiveDirectoryIterator;
|
||||
use RecursiveIteratorIterator;
|
||||
use Symfony\Component\Config\Loader\LoaderInterface;
|
||||
use Symfony\Component\Config\Resource\GlobResource;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
|
@ -101,29 +102,48 @@ class ModuleManager
|
|||
$module_paths = array_merge(glob(INSTALLDIR . '/components/*/*.php'), glob(INSTALLDIR . '/plugins/*/*.php'));
|
||||
$module_manager = new self();
|
||||
$entity_paths = [];
|
||||
$fixtures = [];
|
||||
foreach ($module_paths as $path) {
|
||||
$type = ucfirst(preg_replace('%' . INSTALLDIR . '/(component|plugin)s/.*%', '\1', $path));
|
||||
$dir = \dirname($path);
|
||||
$module = basename($dir); // component or plugin
|
||||
$fqcn = "\\{$type}\\{$module}\\{$module}";
|
||||
$module_manager->add($fqcn, $path);
|
||||
if (!\is_null($container) && file_exists($dir = $dir . '/Entity') && is_dir($dir)) {
|
||||
|
||||
// Register Entities
|
||||
if (!\is_null($container) && file_exists($entity_dir = $dir . '/Entity') && is_dir($entity_dir)) {
|
||||
// Happens at compile time, so it's hard to do integration testing. However,
|
||||
// everything would break if this did :')
|
||||
// @codeCoverageIgnoreStart
|
||||
$entity_paths[] = $dir;
|
||||
$entity_paths[] = $entity_dir;
|
||||
$container->findDefinition('doctrine.orm.default_metadata_driver')->addMethodCall(
|
||||
'addDriver',
|
||||
[new Reference('app.schemadef_driver'), "{$type}\\{$module}\\Entity"],
|
||||
);
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
// Register Test Fixtures
|
||||
if (!\is_null($container) && file_exists($fixtures_dir = $dir . '/tests/fixtures') && is_dir($fixtures_dir)) {
|
||||
$fixtures_files = glob("{$fixtures_dir}/*.php");
|
||||
self::$loader->addPsr4("{$type}\\{$module}\\Test\\Fixtures\\", $fixtures_dir);
|
||||
$container->addResource(new GlobResource($dir, '/tests/fixtures/*', false));
|
||||
|
||||
foreach ($fixtures_files as $fixture) {
|
||||
$class = Formatting::removeSuffix(Formatting::removePrefix($fixture, $fixtures_dir . '/'), '.php');
|
||||
$id = Formatting::removeSuffix(Formatting::camelCaseToSnakeCase($class), '_fixtures');
|
||||
$fqcn = "{$type}\\{$module}\\Test\\Fixtures\\{$class}";
|
||||
$container->autowire($fqcn, $fqcn);
|
||||
$fixtures[] = ['fixture' => new Reference($fqcn), 'groups' => [$type]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!\is_null($container)) {
|
||||
// @codeCoverageIgnoreStart
|
||||
$container->findDefinition('app.schemadef_driver')
|
||||
->addMethodCall('addPaths', ['$paths' => $entity_paths]);
|
||||
$container->findDefinition('doctrine.fixtures.loader')->addMethodCall('addFixtures', [$fixtures]);
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
|
@ -156,7 +176,7 @@ class ModuleManager
|
|||
} else {
|
||||
$rdi = new AppendIterator();
|
||||
$rdi->append(new RecursiveIteratorIterator(new RecursiveDirectoryIterator(INSTALLDIR . '/components', FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::SKIP_DOTS)));
|
||||
$rdi->append(new RecursiveIteratorIterator(new RecursiveDirectoryIterator(INSTALLDIR . '/plugins', FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::SKIP_DOTS)));
|
||||
$rdi->append(new RecursiveIteratorIterator(new RecursiveDirectoryIterator(INSTALLDIR . '/plugins', FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::SKIP_DOTS)));
|
||||
$time = file_exists(MODULE_CACHE_FILE) ? filemtime(MODULE_CACHE_FILE) : 0;
|
||||
|
||||
if ($_ENV['APP_ENV'] === 'test' || F\some($rdi, fn ($e) => $e->getMTime() > $time)) {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace App\DataFixtures;
|
||||
namespace App\Test\Fixtures;
|
||||
|
||||
use App\Core\ActorLocalRoles;
|
||||
use App\Core\VisibilityScope;
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace App\DataFixtures;
|
||||
namespace App\Test\Fixtures;
|
||||
|
||||
use App\Core\ActorLocalRoles;
|
||||
use App\Core\DB\DB;
|
Loading…
Reference in New Issue
Block a user