Skip to content

Commit

Permalink
fix: in composer.lock, avoid homepage item missing error.
Browse files Browse the repository at this point in the history
  • Loading branch information
smeghead committed Jan 29, 2024
1 parent e1711a2 commit 77d502f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Lib/Composer/LockFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function getPackages(): array
$packages = [];
foreach ($this->object->{'packages'} as $p) {
$name = $p->name;
$url = $p->homepage;
$url = property_exists($p, 'homepage') ? $p->homepage : '';
$packages[] = new Package($name, $url);
}
return $packages;
Expand Down
25 changes: 23 additions & 2 deletions test/unit/Lib/Composer/LockFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,29 @@ public function testNormal(): void
$this->assertSame(1, count($packages));
$this->assertSame('doctrine/instantiator', $packages[0]->getName());
$this->assertSame('https://www.doctrine-project.org/projects/instantiator.html', $packages[0]->getUrl());
// $this->assertSame('x', $packages[0]->getfilePath());
// $this->assertSame('', $packages[0]->getContent());
}

public function testNoHomepage(): void
{

$json = <<<EOJ
{
"packages": [
{
"name": "doctrine/instantiator",
"version": "1.5.0",
"license": [
"MIT"
]
}
]
}
EOJ;
$sut = new LockFile($json);
$packages = $sut->getPackages();

$this->assertSame(1, count($packages));
$this->assertSame('doctrine/instantiator', $packages[0]->getName());
$this->assertSame('', $packages[0]->getUrl());
}
}

0 comments on commit 77d502f

Please sign in to comment.