Skip to content

Commit

Permalink
Filter out deps with name 'php'
Browse files Browse the repository at this point in the history
fix(bindata): Use stable mtime in bindata generation

test(composer): Add composer buildtool tests

test(php): Require build tool for Composer test
  • Loading branch information
anuccio1 authored and elldritch committed Oct 10, 2018
1 parent 61ce589 commit 2495072
Show file tree
Hide file tree
Showing 9 changed files with 609 additions and 2 deletions.
32 changes: 31 additions & 1 deletion buildtools/composer/composer.go
Expand Up @@ -58,7 +58,7 @@ func (c *Composer) Dependencies(dir string) ([]Package, map[Package][]Package, e
}
}

return ReadPackageTree(filteredLines, func(line string) (int, Package, error) {
imports, deps, err := ReadPackageTree(filteredLines, func(line string) (int, Package, error) {
if line[0] != '`' && line[0] != '|' && line[0] != ' ' {
// We're at a top-level package.
sections := strings.Split(line, " ")
Expand Down Expand Up @@ -94,6 +94,36 @@ func (c *Composer) Dependencies(dir string) ([]Package, map[Package][]Package, e
}
return level, p, nil
})

if err != nil {
return imports, deps, err
}

// Filter out "comp+php" imports
filteredImports := make([]Package, 0)
for _, currPackage := range imports {
if currPackage.Name != "php" {
filteredImports = append(filteredImports, currPackage)
}
}

// Filter out deps, both parent and children with locator as "php"
filteredDeps := make(map[Package][]Package)
for parent, children := range deps {
if parent.Name != "php" {
_, ok := filteredDeps[parent]
if !ok {
filteredDeps[parent] = make([]Package, 0)
}
for _, child := range children {
if child.Name != "php" {
filteredDeps[parent] = append(filteredDeps[parent], child)
}
}
}
}

return filteredImports, filteredDeps, nil
}

func (c *Composer) Show(dir string) (Show, error) {
Expand Down
48 changes: 48 additions & 0 deletions buildtools/composer/composer_test.go
@@ -0,0 +1,48 @@
package composer_test

import (
"path/filepath"
"testing"

"github.com/fossas/fossa-cli/analyzers"
"github.com/fossas/fossa-cli/analyzers/php"
"github.com/fossas/fossa-cli/module"
"github.com/fossas/fossa-cli/pkg"
"github.com/stretchr/testify/assert"
)

func TestNoDependenciesNamedPHP(t *testing.T) {
// TODO: this really shouldn't require the build tool, but we don't currently
// have a non-build-tool method or mock for Composer. We should implement this
// by adding resolution from walking `composer.json` dependency manifests.
if testing.Short() {
t.Skip("Composer requires build tool")
}

// Run analysis.
m := module.Module{
Name: "fixture",
Type: pkg.Composer,
BuildTarget: filepath.Join("testdata", "composer.json"),
Dir: "testdata",
}

a, err := analyzers.New(m)
assert.NoError(t, err)
assert.IsType(t, &php.Analyzer{}, a)

deps, err := a.Analyze()
assert.NoError(t, err)

// Ensure no PHP dependencies.
for _, dep := range deps.Direct {
assert.NotEqual(t, "php", dep.Resolved.Name)
}

for id, dep := range deps.Transitive {
assert.NotEqual(t, "php", id.Name)
for _, i := range dep.Imports {
assert.NotEqual(t, "php", i.Resolved.Name)
}
}
}
8 changes: 8 additions & 0 deletions buildtools/composer/testdata/composer.json
@@ -0,0 +1,8 @@
{
"name": "fixture",
"type": "project",
"require": {
"php": "^7.2",
"twig/twig": "^2.0"
}
}
204 changes: 204 additions & 0 deletions buildtools/composer/testdata/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2495072

Please sign in to comment.