diff --git a/src/Composer/Package/Loader/ArrayLoader.php b/src/Composer/Package/Loader/ArrayLoader.php index abebb4163..3d315045d 100644 --- a/src/Composer/Package/Loader/ArrayLoader.php +++ b/src/Composer/Package/Loader/ArrayLoader.php @@ -185,7 +185,7 @@ class ArrayLoader implements LoaderInterface } $package->setSourceType($config['source']['type']); $package->setSourceUrl($config['source']['url']); - $package->setSourceReference($config['source']['reference'] ?? null); + $package->setSourceReference(isset($config['source']['reference']) ? (string) $config['source']['reference'] : null); if (isset($config['source']['mirrors'])) { $package->setSourceMirrors($config['source']['mirrors']); } @@ -202,7 +202,7 @@ class ArrayLoader implements LoaderInterface } $package->setDistType($config['dist']['type']); $package->setDistUrl($config['dist']['url']); - $package->setDistReference($config['dist']['reference'] ?? null); + $package->setDistReference(isset($config['dist']['reference']) ? (string) $config['dist']['reference'] : null); $package->setDistSha1Checksum($config['dist']['shasum'] ?? null); if (isset($config['dist']['mirrors'])) { $package->setDistMirrors($config['dist']['mirrors']); diff --git a/tests/Composer/Test/Package/Loader/ArrayLoaderTest.php b/tests/Composer/Test/Package/Loader/ArrayLoaderTest.php index fa2a180a9..2fb83698b 100644 --- a/tests/Composer/Test/Package/Loader/ArrayLoaderTest.php +++ b/tests/Composer/Test/Package/Loader/ArrayLoaderTest.php @@ -325,4 +325,26 @@ class ArrayLoaderTest extends TestCase $package = $this->loader->load($config); $this->assertSame('1', $package->getPrettyVersion()); } + + public function testNoneStringSourceDistReference(): void + { + $config = array( + 'name' => 'acme/package', + 'version' => 'dev-main', + 'source' => [ + 'type' => 'svn', + 'url' => 'https://example.org/', + 'reference' => 2019, + ], + 'dist' => [ + 'type' => 'zip', + 'url' => 'https://example.org/', + 'reference' => 2019, + ], + ); + + $package = $this->loader->load($config); + $this->assertSame('2019', $package->getSourceReference()); + $this->assertSame('2019', $package->getDistReference()); + } }