Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix main script failure when bin is a string #162

Merged
merged 1 commit into from
Apr 25, 2018
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
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