github.com/anchore/syft@v1.4.2-0.20240516191711-1bec1fc5d397/syft/pkg/cataloger/php/parse_composer_lock_test.go (about)

     1  package php
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/anchore/syft/syft/artifact"
     7  	"github.com/anchore/syft/syft/file"
     8  	"github.com/anchore/syft/syft/pkg"
     9  	"github.com/anchore/syft/syft/pkg/cataloger/internal/pkgtest"
    10  )
    11  
    12  func TestParseComposerFileLock(t *testing.T) {
    13  	var expectedRelationships []artifact.Relationship
    14  	fixture := "test-fixtures/composer.lock"
    15  	locations := file.NewLocationSet(file.NewLocation(fixture))
    16  	expectedPkgs := []pkg.Package{
    17  		{
    18  			Name:      "adoy/fastcgi-client",
    19  			Version:   "1.0.2",
    20  			PURL:      "pkg:composer/adoy/fastcgi-client@1.0.2",
    21  			Locations: locations,
    22  			Licenses: pkg.NewLicenseSet(
    23  				pkg.NewLicenseFromLocations("MIT", file.NewLocation(fixture)),
    24  			),
    25  			Language: pkg.PHP,
    26  			Type:     pkg.PhpComposerPkg,
    27  			Metadata: pkg.PhpComposerLockEntry{
    28  				Name:    "adoy/fastcgi-client",
    29  				Version: "1.0.2",
    30  				Source: pkg.PhpComposerExternalReference{
    31  					Type:      "git",
    32  					URL:       "https://github.com/adoy/PHP-FastCGI-Client.git",
    33  					Reference: "6d9a552f0206a1db7feb442824540aa6c55e5b27",
    34  				},
    35  				Dist: pkg.PhpComposerExternalReference{
    36  					Type:      "zip",
    37  					URL:       "https://api.github.com/repos/adoy/PHP-FastCGI-Client/zipball/6d9a552f0206a1db7feb442824540aa6c55e5b27",
    38  					Reference: "6d9a552f0206a1db7feb442824540aa6c55e5b27",
    39  				},
    40  				Type:            "library",
    41  				NotificationURL: "https://packagist.org/downloads/",
    42  				Authors: []pkg.PhpComposerAuthors{
    43  					{
    44  						Name:  "Pierrick Charron",
    45  						Email: "pierrick@adoy.net",
    46  					},
    47  				},
    48  				Description: "Lightweight, single file FastCGI client for PHP.",
    49  				Keywords: []string{
    50  					"fastcgi",
    51  					"fcgi",
    52  				},
    53  				Time: "2019-12-11T13:49:21+00:00",
    54  			},
    55  		},
    56  		{
    57  			Name:      "alcaeus/mongo-php-adapter",
    58  			Version:   "1.1.11",
    59  			Locations: locations,
    60  			PURL:      "pkg:composer/alcaeus/mongo-php-adapter@1.1.11",
    61  			Language:  pkg.PHP,
    62  			Licenses: pkg.NewLicenseSet(
    63  				pkg.NewLicenseFromLocations("MIT", file.NewLocation(fixture)),
    64  			),
    65  			Type: pkg.PhpComposerPkg,
    66  			Metadata: pkg.PhpComposerLockEntry{
    67  				Name:    "alcaeus/mongo-php-adapter",
    68  				Version: "1.1.11",
    69  				Source: pkg.PhpComposerExternalReference{
    70  					Type:      "git",
    71  					URL:       "https://github.com/alcaeus/mongo-php-adapter.git",
    72  					Reference: "43b6add94c8b4cb9890d662cba4c0defde733dcf",
    73  				},
    74  				Dist: pkg.PhpComposerExternalReference{
    75  					Type:      "zip",
    76  					URL:       "https://api.github.com/repos/alcaeus/mongo-php-adapter/zipball/43b6add94c8b4cb9890d662cba4c0defde733dcf",
    77  					Reference: "43b6add94c8b4cb9890d662cba4c0defde733dcf",
    78  				},
    79  				Require: map[string]string{
    80  					"ext-ctype":       "*",
    81  					"ext-hash":        "*",
    82  					"ext-mongodb":     "^1.2.0",
    83  					"mongodb/mongodb": "^1.0.1",
    84  					"php":             "^5.6 || ^7.0",
    85  				},
    86  				Provide: map[string]string{
    87  					"ext-mongo": "1.6.14",
    88  				},
    89  				RequireDev: map[string]string{
    90  					"phpunit/phpunit":           "^5.7.27 || ^6.0 || ^7.0",
    91  					"squizlabs/php_codesniffer": "^3.2",
    92  				},
    93  				Type:            "library",
    94  				NotificationURL: "https://packagist.org/downloads/",
    95  				Authors: []pkg.PhpComposerAuthors{
    96  					{
    97  						Name:  "alcaeus",
    98  						Email: "alcaeus@alcaeus.org",
    99  					},
   100  					{
   101  						Name:  "Olivier Lechevalier",
   102  						Email: "olivier.lechevalier@gmail.com",
   103  					},
   104  				},
   105  				Description: "Adapter to provide ext-mongo interface on top of mongo-php-libary",
   106  				Keywords: []string{
   107  					"database",
   108  					"mongodb",
   109  				},
   110  				Time: "2019-11-11T20:47:32+00:00",
   111  			},
   112  		},
   113  	}
   114  	pkgtest.TestFileParser(t, fixture, parseComposerLock, expectedPkgs, expectedRelationships)
   115  }