Skip to content

Commit

Permalink
Fix main script failure when bin is a string (#162)
Browse files Browse the repository at this point in the history
The `bin` entry in the `composer.json` can be a `string` besides a `string[]`.
  • Loading branch information
theofidry authored Apr 25, 2018
1 parent 6b7dc4a commit c350a04
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,7 @@ private static function retrieveMainScriptPath(stdClass $raw, string $basePath,
} else {
if (null === $decodedJsonContents
|| false === array_key_exists('bin', $decodedJsonContents)
|| false === $main = current($decodedJsonContents['bin'])
|| false === $main = current((array) $decodedJsonContents['bin'])
) {
$main = self::DEFAULT_MAIN_SCRIPT;
}
Expand Down
22 changes: 19 additions & 3 deletions tests/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,16 +449,32 @@ public function test_configure_file_mode(): void

public function test_a_main_script_path_is_configured_by_default(): void
{
$this->assertSame($this->tmp.DIRECTORY_SEPARATOR.'index.php', $this->config->getMainScriptPath());
$this->assertSame($this->tmp.DIRECTORY_SEPARATOR.'index.php', $this->getNoFileConfig()->getMainScriptPath());

dump_file('composer.json', '{"bin": []}');

$this->assertSame($this->tmp.DIRECTORY_SEPARATOR.'index.php', $this->config->getMainScriptPath());
$this->assertSame($this->tmp.DIRECTORY_SEPARATOR.'index.php', $this->getNoFileConfig()->getMainScriptPath());
}

public function test_a_main_script_path_is_inferred_by_the_composer_json_by_default(): void
{
dump_file('bin/foo');

dump_file(
'composer.json',
<<<'JSON'
{
"bin": "bin/foo"
}
JSON
);

$this->reloadConfig();

$this->assertSame($this->tmp.DIRECTORY_SEPARATOR.'bin/foo', $this->config->getMainScriptPath());
$this->assertSame($this->tmp.DIRECTORY_SEPARATOR.'bin/foo', $this->getNoFileConfig()->getMainScriptPath());
}

public function test_the_first_composer_bin_is_used_as_the_main_script_by_default(): void
{
dump_file('bin/foo');
dump_file('bin/bar');
Expand Down

0 comments on commit c350a04

Please sign in to comment.