Skip to content

Commit 77d502f

Browse files
committed
fix: in composer.lock, avoid homepage item missing error.
1 parent e1711a2 commit 77d502f

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/Lib/Composer/LockFile.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function getPackages(): array
2424
$packages = [];
2525
foreach ($this->object->{'packages'} as $p) {
2626
$name = $p->name;
27-
$url = $p->homepage;
27+
$url = property_exists($p, 'homepage') ? $p->homepage : '';
2828
$packages[] = new Package($name, $url);
2929
}
3030
return $packages;

test/unit/Lib/Composer/LockFileTest.php

+23-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,29 @@ public function testNormal(): void
4747
$this->assertSame(1, count($packages));
4848
$this->assertSame('doctrine/instantiator', $packages[0]->getName());
4949
$this->assertSame('https://www.doctrine-project.org/projects/instantiator.html', $packages[0]->getUrl());
50-
// $this->assertSame('x', $packages[0]->getfilePath());
51-
// $this->assertSame('', $packages[0]->getContent());
50+
}
51+
52+
public function testNoHomepage(): void
53+
{
54+
55+
$json = <<<EOJ
56+
{
57+
"packages": [
58+
{
59+
"name": "doctrine/instantiator",
60+
"version": "1.5.0",
61+
"license": [
62+
"MIT"
63+
]
64+
}
65+
]
66+
}
67+
EOJ;
68+
$sut = new LockFile($json);
69+
$packages = $sut->getPackages();
5270

71+
$this->assertSame(1, count($packages));
72+
$this->assertSame('doctrine/instantiator', $packages[0]->getName());
73+
$this->assertSame('', $packages[0]->getUrl());
5374
}
5475
}

0 commit comments

Comments
 (0)