-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes and specs fix spec added composer features updated readme, features test fixing indentation fixed rubocop errors fixed specs, added logic for specs to run properly fix rubocop errors fix broken tests, rubocop errors, incorrect fixtures, extra code
- Loading branch information
Showing
15 changed files
with
193 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
5.8.0 | ||
5.8.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../../support/feature_helper' | ||
|
||
describe 'Composer Dependencies' do | ||
let(:php_developer) { LicenseFinder::TestingDSL::User.new } | ||
|
||
specify 'are shown in reports' do | ||
LicenseFinder::TestingDSL::ComposerProject.create | ||
php_developer.run_license_finder | ||
expect(php_developer).to be_seeing_line 'vlucas/phpdotenv, v3.3.3, "New BSD"' | ||
expect(php_developer).to be_seeing_line 'symfony/debug, v4.2.8, MIT' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "license_finder/fixture", | ||
"description": "A sample composer.json file.", | ||
"version": "1.0.0", | ||
"license": "MIT", | ||
"require": { | ||
"vlucas/phpdotenv": "3.3.3" | ||
}, | ||
"require-dev": { | ||
"symfony/debug": "4.2.8" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'json' | ||
|
||
module LicenseFinder | ||
class Composer < PackageManager | ||
SHELL_COMMAND = 'composer licenses --format=json' | ||
|
||
def possible_package_paths | ||
[project_path.join('composer.lock'), project_path.join('composer.json')] | ||
end | ||
|
||
def current_packages | ||
dependency_list.map do |name, dependency| | ||
ComposerPackage.new(name, dependency['version'], spec_licenses: dependency['license']) | ||
end | ||
end | ||
|
||
def prepare | ||
_stdout, stderr, status = Dir.chdir(project_path) { Cmd.run(Composer.prepare_command) } | ||
return if status.success? | ||
|
||
log_errors stderr | ||
raise "Prepare command '#{prep_cmd}' failed" unless @prepare_no_fail | ||
end | ||
|
||
def self.package_management_command | ||
'composer' | ||
end | ||
|
||
def self.prepare_command | ||
'composer install' | ||
end | ||
|
||
def package_path | ||
project_path.join('composer.json') | ||
end | ||
|
||
def lockfile_path | ||
project_path.join('composer.lock') | ||
end | ||
|
||
def dependency_list | ||
json ||= composer_json | ||
json.fetch('dependencies', {}).reject { |_, d| d.is_a?(String) } | ||
end | ||
|
||
def composer_json | ||
stdout, _stderr, status = Cmd.run(Composer::SHELL_COMMAND) | ||
return [] unless status.success? | ||
|
||
json = JSON(stdout) | ||
|
||
json | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
module LicenseFinder | ||
class ComposerPackage < Package | ||
def package_manager | ||
'Composer' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"require": { | ||
"vlucas/phpdotenv": "^3.3" | ||
}, | ||
"require-dev": { | ||
"symfony/debug": "^4.2" | ||
} | ||
} |
Empty file.
25 changes: 25 additions & 0 deletions
25
spec/lib/license_finder/package_managers/composer_package_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
module LicenseFinder | ||
describe ComposerPackage do | ||
subject do | ||
described_class.new('symfony/debug', 'v3.0.7', 'license' => [{ 'name' => 'MIT' }]) | ||
end | ||
|
||
its(:name) { should == 'symfony/debug' } | ||
its(:version) { should == 'v3.0.7' } | ||
its(:summary) { should eq '' } | ||
its(:description) { should == '' } | ||
its(:homepage) { should == '' } | ||
its(:package_manager) { should eq 'Composer' } | ||
|
||
describe '#license_names_from_spec' do | ||
it 'finds the license for both license structures' do | ||
package = ComposerPackage.new('test', 'v1.2.3', spec_licenses: ['MIT']) | ||
expect(package.license_names_from_spec).to eq ['MIT'] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
require 'fakefs/spec_helpers' | ||
require 'json' | ||
|
||
module LicenseFinder | ||
describe Composer do | ||
let(:root) { '/fake-composer-project' } | ||
let(:composer) { Composer.new project_path: Pathname.new(root) } | ||
|
||
it_behaves_like 'a PackageManager' | ||
|
||
let(:composer_shell_command_output) do | ||
{ | ||
'require' => { | ||
'vlucas/phpdotenv' => '3.3.*' | ||
}, | ||
'require-dev' => { | ||
'symfony/debug' => '4.2.*' | ||
} | ||
}.to_json | ||
end | ||
|
||
describe '.prepare' do | ||
subject { Composer.new(project_path: Pathname(root), logger: double(:logger, active: nil)) } | ||
|
||
include FakeFS::SpecHelpers | ||
before do | ||
FileUtils.mkdir_p(Dir.tmpdir) | ||
FileUtils.mkdir_p(root) | ||
end | ||
|
||
it 'should call composer install' do | ||
expect(SharedHelpers::Cmd).to receive(:run).with('composer install') | ||
.and_return([composer_shell_command_output, '', cmd_success]) | ||
subject.prepare | ||
end | ||
end | ||
end | ||
end |