Skip to content
Merged
Show file tree
Hide file tree
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
Fix #18 Preventing custom roles to duplicate files from default roles.
  • Loading branch information
Alexandre Gaigalas committed Apr 12, 2012
commit 348deefea5d8f031d328ca7f3bb0c4374b0f0b95
7 changes: 5 additions & 2 deletions src/Onion/Pear/PackageXmlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ function generate()
$customRoles = $config->get('roles');
if( $customRoles ) {
foreach( $customRoles as $pattern => $role ) {
if (in_array($pattern, $roles['test'])) {
continue;
}
$logger->debug( "treat \"$pattern\" as \"$role\" role" , 1 );
$files = $this->addPathByRole( $pattern , $role );
$filelist = array_merge( $filelist, $files);
Expand Down Expand Up @@ -264,15 +267,15 @@ function addPathByRole( $path , $role )
foreach( $iterator as $path ) {
if( $path->isFile() ) {
$filepath = $path->getPathname();
$list[] = $this->buildContentFile( $path, $role, $baseDir );
$list[(string) $path] = $this->buildContentFile( $path, $role, $baseDir );
}
}
}
else {
$files = glob($path);
foreach( $files as $filename ) {
$fileinfo = new SplFileInfo($filename);
$list[] = $this->buildContentFile( $fileinfo , $role );
$list[(string) $filename] = $this->buildContentFile( $fileinfo , $role );
}
}
return $list;
Expand Down
20 changes: 20 additions & 0 deletions tests/Onion/Pear/PackageXmlGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,24 @@ function test()

// do validations from xsd file.
}

function test2()
{
$logger = \Onion\Application::getLogger();
$logger->setLevel( 0 );

$config = new \Onion\PackageConfigReader();
$config->setLogger( $logger );

$package = $config->read( 'package.ini' );
$package->config->array['roles']['src'] = 'php';

$generator = new \Onion\Pear\PackageXmlGenerator( $package );
$generator->setLogger( $logger );

$installElement = '<install name="src/Onion/Application.php" as="Onion/Application.php"/>';
$generatedXml = $generator->generate();

is(1, substr_count($generatedXml, $installElement), 'Only one install should appear per file.');
}
}