Skip to content

Commit

Permalink
Fix the auto-discovery of files with empty paths for PSR-0 autoloaders (
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry authored Oct 31, 2018
1 parent 58c7942 commit 04fc36c
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/Box.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,8 @@ public function getPhar(): Phar
/**
* Signs the PHAR using a private key file.
*
* @param string $file the private key file name
* @param string|null $password the private key password
* @param string $file the private key file name
* @param null|string $password the private key password
*/
public function signUsingFile(string $file, ?string $password = null): void
{
Expand All @@ -348,8 +348,8 @@ public function signUsingFile(string $file, ?string $password = null): void
/**
* Signs the PHAR using a private key.
*
* @param string $key The private key
* @param string|null $password The private key password
* @param string $key The private key
* @param null|string $password The private key password
*/
public function sign(string $key, ?string $password): void
{
Expand Down
4 changes: 1 addition & 3 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -1284,9 +1284,7 @@ static function (SplFileInfo $fileInfo): ?bool {
$composerPaths = (array) $path;

foreach ($composerPaths as $composerPath) {
if ('' !== trim($composerPath)) {
$paths[] = $composerPath;
}
$paths[] = '' !== trim($composerPath) ? $composerPath : $basePath;
}
}
}
Expand Down
88 changes: 88 additions & 0 deletions tests/ConfigurationFileNoConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,94 @@ public function test_all_the_files_found_in_the_composer_json_are_taken_by_defau
$this->assertCount(0, $this->config->getBinaryFiles());
}

public function test_find_psr0_files(): void
{
mkdir('PSR0_0');
touch('PSR0_0/file0');
touch('PSR0_0/file1');

dump_file(
'composer.json',
<<<'JSON'
{
"autoload": {
"psr-0": {
"Acme\\": " PSR0_0 "
}
}
}
JSON
);

// Relative to the current working directory for readability
$expected = [
'composer.json',
'PSR0_0/file0',
'PSR0_0/file1',
];

$noFileConfig = $this->getNoFileConfig();

$actual = $this->normalizePaths($noFileConfig->getFiles());

$this->assertEquals($expected, $actual);
$this->assertCount(0, $noFileConfig->getBinaryFiles());

$this->reloadConfig();

$actual = $this->normalizePaths($this->config->getFiles());

$this->assertEquals($expected, $actual);
$this->assertCount(0, $this->config->getBinaryFiles());
}

public function test_psr0_with_empty_directory_in_composer_json(): void
{
touch('root_file0');
touch('root_file1');

mkdir('Acme');
touch('Acme/file0');
touch('Acme/file1');
touch('Acme/file2');

dump_file(
'composer.json',
<<<'JSON'
{
"autoload": {
"psr-0": {
"Acme\\": ""
}
}
}
JSON
);

$expected = [
'Acme/file0',
'Acme/file1',
'Acme/file2',
'composer.json',
'root_file0',
'root_file1',
];

$noFileConfig = $this->getNoFileConfig();

$actual = $this->normalizePaths($noFileConfig->getFiles());

$this->assertEquals($expected, $actual);
$this->assertCount(0, $noFileConfig->getBinaryFiles());

$this->reloadConfig();

$actual = $this->normalizePaths($this->config->getFiles());

$this->assertEquals($expected, $actual);
$this->assertCount(0, $this->config->getBinaryFiles());
}

public function test_throws_an_error_if_a_non_existent_file_is_found_via_the_composer_json(): void
{
touch('file0');
Expand Down

0 comments on commit 04fc36c

Please sign in to comment.