Skip to content
This repository has been archived by the owner on Aug 28, 2018. It is now read-only.

Load fixture files recursively #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions Loader/YamlLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,39 @@ public function setReference($name, $object)
protected function loadFixtureFiles()
{
foreach ($this->bundles as $bundle) {
$file = '*';
$file = null;
if (strpos($bundle, '/')) {
list($bundle, $file) = explode('/', $bundle);
}

$path = $this->kernel->locateResource('@' . $bundle);
$files = glob($path . $this->directory . '/'.$file.'.yml');
$this->fixture_files = array_unique(array_merge($this->fixture_files, $files));
$path .= $this->directory;

$bundleFiles = [];
if (!empty($file)) {
$bundleFiles = glob($path . '/'.$file.'.yml');
} else {
$directory = new \RecursiveDirectoryIterator($path);
$iterator = new \RecursiveIteratorIterator($directory);
$files = new \RegexIterator($iterator, '/^.+\.yml$/i', \RecursiveRegexIterator::GET_MATCH);

foreach ($files as $file) {
$bundleFiles[] = $file[0];
}
}

uasort($bundleFiles, function($a, $b) {
$a = basename($a);
$b = basename($b);

if ($a == $b) {
return 0;
}

return ($a < $b) ? -1 : 1;
});

$this->fixture_files = array_unique(array_merge($this->fixture_files, $bundleFiles));
}
}

Expand Down Expand Up @@ -145,7 +171,7 @@ public function purgeDatabase($persistence, $databaseName = null, $withTruncate

// Instanciate purger and executor
$persister = $this->getPersister($persistence);
$entityManagers = ($databaseName)
$entityManagers = ($databaseName)
? array($persister->getManager($databaseName))
: $persister->getManagers();

Expand Down