diff --git a/composer/lib/dependabot/composer/file_parser.rb b/composer/lib/dependabot/composer/file_parser.rb index 8bd8b1972a8..0d647ed888e 100644 --- a/composer/lib/dependabot/composer/file_parser.rb +++ b/composer/lib/dependabot/composer/file_parser.rb @@ -166,7 +166,7 @@ def git_dependency_details(package_details, requirement) def lockfile_details(name:, type:) key = lockfile_key(type) - parsed_lockfile.fetch(key, []).find { |d| d["name"] == name } + parsed_lockfile.fetch(key, [])&.find { |d| d["name"] == name } end def lockfile_key(type) diff --git a/composer/spec/dependabot/composer/file_parser_spec.rb b/composer/spec/dependabot/composer/file_parser_spec.rb index b266ccabb19..0802cba4971 100644 --- a/composer/spec/dependabot/composer/file_parser_spec.rb +++ b/composer/spec/dependabot/composer/file_parser_spec.rb @@ -49,6 +49,16 @@ end end + context "null dependencies with lockfile" do + let(:project_name) { "null_dependencies_with_lockfile" } + let(:name) { "phpunit/phpunit" } + let(:type) { "development" } + describe "no dependencies" do + subject { dependencies } + its(:length) { is_expected.to be >= 0 } + end + end + context "with a version specified (composer v1)" do let(:project_name) { "v1/minor_version" } diff --git a/composer/spec/fixtures/projects/null_dependencies_with_lockfile/composer.json b/composer/spec/fixtures/projects/null_dependencies_with_lockfile/composer.json new file mode 100644 index 00000000000..acb4fabb0d3 --- /dev/null +++ b/composer/spec/fixtures/projects/null_dependencies_with_lockfile/composer.json @@ -0,0 +1,41 @@ +{ + "name": "joshuaestes/server-tools", + "description": "Collection of command line tools to help with server management and maintenance", + "keywords": [], + "homepage": "https://github.com/JoshuaEstes/ServerTools", + "license": "MIT", + "authors": [ + { + "name": "Joshua Estes", + "homepage": "http://joshuaestes.me" + }, + { + "name": "Contributors", + "homepage": "https://github.com/JoshuaEstes/ServerTools/graphs/contributors" + } + ], + "minimum-stability": "dev", + "require": { + "php": ">=5.3.2", + "symfony/console": ">=2.1,<=2.3@dev", + "symfony/process": ">=2.1,<=2.3@dev", + "symfony/yaml": ">=2.1,<=2.3@dev", + "symfony/finder": ">=2.1,<=2.3@dev", + "symfony/filesystem": ">=2.1,<=2.3@dev" + }, + "replace": { + "JoshuaEstes/ServerTools": "self.version" + }, + "require-dev": { + "phpunit/phpunit": "*", + "mikey179/vfsStream": "*" + }, + "autoload": { + "psr-0": { "": "src/" } + }, + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + } +} diff --git a/composer/spec/fixtures/projects/null_dependencies_with_lockfile/composer.lock b/composer/spec/fixtures/projects/null_dependencies_with_lockfile/composer.lock new file mode 100644 index 00000000000..7074d4d2b21 --- /dev/null +++ b/composer/spec/fixtures/projects/null_dependencies_with_lockfile/composer.lock @@ -0,0 +1,249 @@ +{ + "hash": "e031c26dc793ba069af645833f61dd89", + "packages": [ + { + "name": "symfony/console", + "version": "dev-master", + "target-dir": "Symfony/Component/Console", + "source": { + "type": "git", + "url": "https://github.com/symfony/Console", + "reference": "fdb2d9320106926266a0f7a5a97aab7213e11ad6" + }, + "dist": { + "type": "zip", + "url": "https://github.com/symfony/Console/archive/fdb2d9320106926266a0f7a5a97aab7213e11ad6.zip", + "reference": "fdb2d9320106926266a0f7a5a97aab7213e11ad6", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "time": "2013-01-24 15:55:08", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.2-dev" + } + }, + "autoload": { + "psr-0": { + "Symfony\\Component\\Console\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony Console Component", + "homepage": "http://symfony.com" + }, + { + "name": "symfony/filesystem", + "version": "dev-master", + "target-dir": "Symfony/Component/Filesystem", + "source": { + "type": "git", + "url": "https://github.com/symfony/Filesystem", + "reference": "v2.2.0-BETA2" + }, + "dist": { + "type": "zip", + "url": "https://github.com/symfony/Filesystem/archive/v2.2.0-BETA2.zip", + "reference": "v2.2.0-BETA2", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "time": "2013-01-17 15:25:59", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.2-dev" + } + }, + "autoload": { + "psr-0": { + "Symfony\\Component\\Filesystem\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony Filesystem Component", + "homepage": "http://symfony.com" + }, + { + "name": "symfony/finder", + "version": "dev-master", + "target-dir": "Symfony/Component/Finder", + "source": { + "type": "git", + "url": "https://github.com/symfony/Finder", + "reference": "d33658c34672f48474a669227ca3639fa0b443e7" + }, + "dist": { + "type": "zip", + "url": "https://github.com/symfony/Finder/archive/d33658c34672f48474a669227ca3639fa0b443e7.zip", + "reference": "d33658c34672f48474a669227ca3639fa0b443e7", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "time": "2013-01-29 18:42:39", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.2-dev" + } + }, + "autoload": { + "psr-0": { + "Symfony\\Component\\Finder\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony Finder Component", + "homepage": "http://symfony.com" + }, + { + "name": "symfony/process", + "version": "dev-master", + "target-dir": "Symfony/Component/Process", + "source": { + "type": "git", + "url": "https://github.com/symfony/Process", + "reference": "v2.2.0-BETA2" + }, + "dist": { + "type": "zip", + "url": "https://github.com/symfony/Process/archive/v2.2.0-BETA2.zip", + "reference": "v2.2.0-BETA2", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "time": "2013-01-17 15:25:59", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.2-dev" + } + }, + "autoload": { + "psr-0": { + "Symfony\\Component\\Process\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony Process Component", + "homepage": "http://symfony.com" + }, + { + "name": "symfony/yaml", + "version": "dev-master", + "target-dir": "Symfony/Component/Yaml", + "source": { + "type": "git", + "url": "https://github.com/symfony/Yaml", + "reference": "b293027f4030998a752a1ac06e80ae9e6bf6a763" + }, + "dist": { + "type": "zip", + "url": "https://github.com/symfony/Yaml/archive/b293027f4030998a752a1ac06e80ae9e6bf6a763.zip", + "reference": "b293027f4030998a752a1ac06e80ae9e6bf6a763", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "time": "2013-01-27 16:49:19", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.2-dev" + } + }, + "autoload": { + "psr-0": { + "Symfony\\Component\\Yaml\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony Yaml Component", + "homepage": "http://symfony.com" + } + ], + "packages-dev": null, + "aliases": [ + + ], + "minimum-stability": "dev", + "stability-flags": [ + + ] +} +