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