2022-02-23 15:58:18 +00:00
|
|
|
<?php declare(strict_types=1);
|
2012-02-14 11:57:15 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Composer.
|
|
|
|
*
|
|
|
|
* (c) Nils Adermann <naderman@naderman.de>
|
|
|
|
* Jordi Boggiano <j.boggiano@seld.be>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Composer\Test\Package\Dumper;
|
|
|
|
|
|
|
|
use Composer\Package\Dumper\ArrayDumper;
|
2012-04-14 09:56:13 +00:00
|
|
|
use Composer\Package\Link;
|
2015-09-24 14:32:36 +00:00
|
|
|
use Composer\Semver\Constraint\Constraint;
|
2020-02-07 03:18:45 +00:00
|
|
|
use Composer\Test\TestCase;
|
2012-02-14 11:57:15 +00:00
|
|
|
|
2017-11-04 14:52:13 +00:00
|
|
|
class ArrayDumperTest extends TestCase
|
2012-02-14 11:57:15 +00:00
|
|
|
{
|
2012-07-14 10:29:53 +00:00
|
|
|
/**
|
|
|
|
* @var ArrayDumper
|
|
|
|
*/
|
|
|
|
private $dumper;
|
|
|
|
|
2021-12-08 16:03:05 +00:00
|
|
|
public function setUp(): void
|
2012-02-14 11:57:15 +00:00
|
|
|
{
|
|
|
|
$this->dumper = new ArrayDumper();
|
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testRequiredInformation(): void
|
2012-02-14 11:57:15 +00:00
|
|
|
{
|
2022-02-22 21:10:52 +00:00
|
|
|
$config = $this->dumper->dump($this->getPackage());
|
2012-07-14 10:29:53 +00:00
|
|
|
$this->assertEquals(
|
2022-08-17 12:20:07 +00:00
|
|
|
[
|
2022-02-22 21:10:52 +00:00
|
|
|
'name' => 'dummy/pkg',
|
|
|
|
'version' => '1.0.0',
|
2015-09-28 09:51:14 +00:00
|
|
|
'version_normalized' => '1.0.0.0',
|
2022-02-22 21:10:52 +00:00
|
|
|
'type' => 'library',
|
2022-08-17 12:20:07 +00:00
|
|
|
],
|
2012-07-14 10:29:53 +00:00
|
|
|
$config
|
|
|
|
);
|
2012-02-14 11:57:15 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testRootPackage(): void
|
2012-09-19 21:08:37 +00:00
|
|
|
{
|
2022-02-22 21:10:52 +00:00
|
|
|
$package = $this->getRootPackage();
|
|
|
|
$package->setMinimumStability('dev');
|
2012-09-19 21:08:37 +00:00
|
|
|
|
2022-02-22 21:10:52 +00:00
|
|
|
$config = $this->dumper->dump($package);
|
2012-09-19 21:08:37 +00:00
|
|
|
$this->assertSame('dev', $config['minimum-stability']);
|
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testDumpAbandoned(): void
|
2014-10-02 21:04:35 +00:00
|
|
|
{
|
2022-02-22 21:10:52 +00:00
|
|
|
$package = $this->getPackage();
|
|
|
|
$package->setAbandoned(true);
|
|
|
|
$config = $this->dumper->dump($package);
|
2014-10-02 21:04:35 +00:00
|
|
|
|
2017-11-30 14:58:10 +00:00
|
|
|
$this->assertTrue($config['abandoned']);
|
2014-10-02 21:04:35 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testDumpAbandonedReplacement(): void
|
2014-10-02 21:04:35 +00:00
|
|
|
{
|
2022-02-22 21:10:52 +00:00
|
|
|
$package = $this->getPackage();
|
|
|
|
$package->setAbandoned('foo/bar');
|
|
|
|
$config = $this->dumper->dump($package);
|
2014-10-02 21:04:35 +00:00
|
|
|
|
|
|
|
$this->assertSame('foo/bar', $config['abandoned']);
|
|
|
|
}
|
|
|
|
|
2012-02-14 11:57:15 +00:00
|
|
|
/**
|
2021-11-01 20:44:12 +00:00
|
|
|
* @dataProvider provideKeys
|
|
|
|
*
|
|
|
|
* @param mixed $value
|
|
|
|
* @param string $method
|
|
|
|
* @param mixed $expectedValue
|
2012-02-14 11:57:15 +00:00
|
|
|
*/
|
2022-08-17 12:20:07 +00:00
|
|
|
public function testKeys(string $key, $value, ?string $method = null, $expectedValue = null): void
|
2012-02-14 11:57:15 +00:00
|
|
|
{
|
2022-02-22 21:10:52 +00:00
|
|
|
$package = $this->getRootPackage();
|
2012-02-14 11:57:15 +00:00
|
|
|
|
2022-02-22 21:10:52 +00:00
|
|
|
// @phpstan-ignore-next-line
|
|
|
|
$package->{'set'.ucfirst($method ?: $key)}($value);
|
2016-11-25 07:28:49 +00:00
|
|
|
|
2022-02-22 21:10:52 +00:00
|
|
|
$config = $this->dumper->dump($package);
|
2012-02-14 11:57:15 +00:00
|
|
|
|
2012-07-14 10:29:53 +00:00
|
|
|
$this->assertSame($expectedValue ?: $value, $config[$key]);
|
2012-02-14 11:57:15 +00:00
|
|
|
}
|
|
|
|
|
2022-02-21 12:42:28 +00:00
|
|
|
public function provideKeys(): array
|
2012-02-14 11:57:15 +00:00
|
|
|
{
|
2022-08-17 12:20:07 +00:00
|
|
|
return [
|
|
|
|
[
|
2012-07-14 10:29:53 +00:00
|
|
|
'type',
|
2015-09-28 09:51:14 +00:00
|
|
|
'library',
|
2022-08-17 12:20:07 +00:00
|
|
|
],
|
|
|
|
[
|
2012-04-14 09:56:13 +00:00
|
|
|
'time',
|
2016-10-04 11:17:10 +00:00
|
|
|
$datetime = new \DateTime('2012-02-01'),
|
2012-04-14 09:56:13 +00:00
|
|
|
'ReleaseDate',
|
2016-10-04 11:17:10 +00:00
|
|
|
$datetime->format(DATE_RFC3339),
|
2022-08-17 12:20:07 +00:00
|
|
|
],
|
|
|
|
[
|
2012-04-14 09:56:13 +00:00
|
|
|
'authors',
|
2022-08-17 12:20:07 +00:00
|
|
|
['Nils Adermann <naderman@naderman.de>', 'Jordi Boggiano <j.boggiano@seld.be>'],
|
|
|
|
],
|
|
|
|
[
|
2012-04-14 09:56:13 +00:00
|
|
|
'homepage',
|
2015-09-28 09:51:14 +00:00
|
|
|
'https://getcomposer.org',
|
2022-08-17 12:20:07 +00:00
|
|
|
],
|
|
|
|
[
|
2012-04-14 09:56:13 +00:00
|
|
|
'description',
|
2015-09-28 09:51:14 +00:00
|
|
|
'Dependency Manager',
|
2022-08-17 12:20:07 +00:00
|
|
|
],
|
|
|
|
[
|
2012-04-14 09:56:13 +00:00
|
|
|
'keywords',
|
2022-08-17 12:20:07 +00:00
|
|
|
['package', 'dependency', 'autoload'],
|
2013-01-31 08:55:19 +00:00
|
|
|
null,
|
2022-08-17 12:20:07 +00:00
|
|
|
['autoload', 'dependency', 'package'],
|
|
|
|
],
|
|
|
|
[
|
2012-04-14 09:56:13 +00:00
|
|
|
'bin',
|
2022-08-17 12:20:07 +00:00
|
|
|
['bin/composer'],
|
2015-09-28 09:51:14 +00:00
|
|
|
'binaries',
|
2022-08-17 12:20:07 +00:00
|
|
|
],
|
|
|
|
[
|
2012-04-14 09:56:13 +00:00
|
|
|
'license',
|
2022-08-17 12:20:07 +00:00
|
|
|
['MIT'],
|
|
|
|
],
|
|
|
|
[
|
2012-04-14 09:56:13 +00:00
|
|
|
'autoload',
|
2022-08-17 12:20:07 +00:00
|
|
|
['psr-0' => ['Composer' => 'src/']],
|
|
|
|
],
|
|
|
|
[
|
2012-04-14 09:56:13 +00:00
|
|
|
'repositories',
|
2022-08-17 12:20:07 +00:00
|
|
|
['packagist' => false],
|
|
|
|
],
|
|
|
|
[
|
2012-04-14 09:56:13 +00:00
|
|
|
'scripts',
|
2022-08-17 12:20:07 +00:00
|
|
|
['post-update-cmd' => 'MyVendor\\MyClass::postUpdate'],
|
|
|
|
],
|
|
|
|
[
|
2012-04-14 09:56:13 +00:00
|
|
|
'extra',
|
2022-08-17 12:20:07 +00:00
|
|
|
['class' => 'MyVendor\\Installer'],
|
|
|
|
],
|
|
|
|
[
|
2013-02-07 14:45:58 +00:00
|
|
|
'archive',
|
2022-08-17 12:20:07 +00:00
|
|
|
['/foo/bar', 'baz', '!/foo/bar/baz'],
|
2013-02-07 14:45:58 +00:00
|
|
|
'archiveExcludes',
|
2022-08-17 12:20:07 +00:00
|
|
|
[
|
|
|
|
'exclude' => ['/foo/bar', 'baz', '!/foo/bar/baz'],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
[
|
2012-04-14 09:56:13 +00:00
|
|
|
'require',
|
2022-08-17 12:20:07 +00:00
|
|
|
['foo/bar' => new Link('dummy/pkg', 'foo/bar', new Constraint('=', '1.0.0.0'), Link::TYPE_REQUIRE, '1.0.0')],
|
2012-04-14 09:56:13 +00:00
|
|
|
'requires',
|
2022-08-17 12:20:07 +00:00
|
|
|
['foo/bar' => '1.0.0'],
|
|
|
|
],
|
|
|
|
[
|
2012-04-14 09:56:13 +00:00
|
|
|
'require-dev',
|
2022-08-17 12:20:07 +00:00
|
|
|
['foo/bar' => new Link('dummy/pkg', 'foo/bar', new Constraint('=', '1.0.0.0'), Link::TYPE_DEV_REQUIRE, '1.0.0')],
|
2012-04-14 09:56:13 +00:00
|
|
|
'devRequires',
|
2022-08-17 12:20:07 +00:00
|
|
|
['foo/bar' => '1.0.0'],
|
|
|
|
],
|
|
|
|
[
|
2012-04-14 09:56:13 +00:00
|
|
|
'suggest',
|
2022-08-17 12:20:07 +00:00
|
|
|
['foo/bar' => 'very useful package'],
|
2015-09-28 09:51:14 +00:00
|
|
|
'suggests',
|
2022-08-17 12:20:07 +00:00
|
|
|
],
|
|
|
|
[
|
2012-07-14 10:29:53 +00:00
|
|
|
'support',
|
2022-08-17 12:20:07 +00:00
|
|
|
['foo' => 'bar'],
|
|
|
|
],
|
|
|
|
[
|
2019-11-28 21:34:29 +00:00
|
|
|
'funding',
|
2022-08-17 12:20:07 +00:00
|
|
|
['type' => 'foo', 'url' => 'https://example.com'],
|
|
|
|
],
|
|
|
|
[
|
2013-01-31 08:55:19 +00:00
|
|
|
'require',
|
2022-08-17 12:20:07 +00:00
|
|
|
[
|
2022-02-22 21:10:52 +00:00
|
|
|
'foo/bar' => new Link('dummy/pkg', 'foo/bar', new Constraint('=', '1.0.0.0'), Link::TYPE_REQUIRE, '1.0.0'),
|
|
|
|
'bar/baz' => new Link('dummy/pkg', 'bar/baz', new Constraint('=', '1.0.0.0'), Link::TYPE_REQUIRE, '1.0.0'),
|
2022-08-17 12:20:07 +00:00
|
|
|
],
|
2013-01-31 08:55:19 +00:00
|
|
|
'requires',
|
2022-08-17 12:20:07 +00:00
|
|
|
['bar/baz' => '1.0.0', 'foo/bar' => '1.0.0'],
|
|
|
|
],
|
|
|
|
[
|
2013-01-31 08:55:19 +00:00
|
|
|
'require-dev',
|
2022-08-17 12:20:07 +00:00
|
|
|
[
|
2022-02-22 21:10:52 +00:00
|
|
|
'foo/bar' => new Link('dummy/pkg', 'foo/bar', new Constraint('=', '1.0.0.0'), Link::TYPE_REQUIRE, '1.0.0'),
|
|
|
|
'bar/baz' => new Link('dummy/pkg', 'bar/baz', new Constraint('=', '1.0.0.0'), Link::TYPE_REQUIRE, '1.0.0'),
|
2022-08-17 12:20:07 +00:00
|
|
|
],
|
2013-01-31 08:55:19 +00:00
|
|
|
'devRequires',
|
2022-08-17 12:20:07 +00:00
|
|
|
['bar/baz' => '1.0.0', 'foo/bar' => '1.0.0'],
|
|
|
|
],
|
|
|
|
[
|
2013-01-31 08:55:19 +00:00
|
|
|
'suggest',
|
2022-08-17 12:20:07 +00:00
|
|
|
['foo/bar' => 'very useful package', 'bar/baz' => 'another useful package'],
|
2013-01-31 08:55:19 +00:00
|
|
|
'suggests',
|
2022-08-17 12:20:07 +00:00
|
|
|
['bar/baz' => 'another useful package', 'foo/bar' => 'very useful package'],
|
|
|
|
],
|
|
|
|
[
|
2013-01-31 08:55:19 +00:00
|
|
|
'provide',
|
2022-08-17 12:20:07 +00:00
|
|
|
[
|
2022-02-22 21:10:52 +00:00
|
|
|
'foo/bar' => new Link('dummy/pkg', 'foo/bar', new Constraint('=', '1.0.0.0'), Link::TYPE_REQUIRE, '1.0.0'),
|
|
|
|
'bar/baz' => new Link('dummy/pkg', 'bar/baz', new Constraint('=', '1.0.0.0'), Link::TYPE_REQUIRE, '1.0.0'),
|
2022-08-17 12:20:07 +00:00
|
|
|
],
|
2013-01-31 08:55:19 +00:00
|
|
|
'provides',
|
2022-08-17 12:20:07 +00:00
|
|
|
['bar/baz' => '1.0.0', 'foo/bar' => '1.0.0'],
|
|
|
|
],
|
|
|
|
[
|
2013-01-31 08:55:19 +00:00
|
|
|
'replace',
|
2022-08-17 12:20:07 +00:00
|
|
|
[
|
2022-02-22 21:10:52 +00:00
|
|
|
'foo/bar' => new Link('dummy/pkg', 'foo/bar', new Constraint('=', '1.0.0.0'), Link::TYPE_REQUIRE, '1.0.0'),
|
|
|
|
'bar/baz' => new Link('dummy/pkg', 'bar/baz', new Constraint('=', '1.0.0.0'), Link::TYPE_REQUIRE, '1.0.0'),
|
2022-08-17 12:20:07 +00:00
|
|
|
],
|
2013-01-31 08:55:19 +00:00
|
|
|
'replaces',
|
2022-08-17 12:20:07 +00:00
|
|
|
['bar/baz' => '1.0.0', 'foo/bar' => '1.0.0'],
|
|
|
|
],
|
|
|
|
[
|
2013-01-31 08:55:19 +00:00
|
|
|
'conflict',
|
2022-08-17 12:20:07 +00:00
|
|
|
[
|
2022-02-22 21:10:52 +00:00
|
|
|
'foo/bar' => new Link('dummy/pkg', 'foo/bar', new Constraint('=', '1.0.0.0'), Link::TYPE_REQUIRE, '1.0.0'),
|
|
|
|
'bar/baz' => new Link('dummy/pkg', 'bar/baz', new Constraint('=', '1.0.0.0'), Link::TYPE_REQUIRE, '1.0.0'),
|
2022-08-17 12:20:07 +00:00
|
|
|
],
|
2013-01-31 08:55:19 +00:00
|
|
|
'conflicts',
|
2022-08-17 12:20:07 +00:00
|
|
|
['bar/baz' => '1.0.0', 'foo/bar' => '1.0.0'],
|
|
|
|
],
|
|
|
|
[
|
2014-05-07 16:25:28 +00:00
|
|
|
'transport-options',
|
2022-08-17 12:20:07 +00:00
|
|
|
['ssl' => ['local_cert' => '/opt/certs/test.pem']],
|
2015-09-28 09:51:14 +00:00
|
|
|
'transportOptions',
|
2022-08-17 12:20:07 +00:00
|
|
|
],
|
|
|
|
];
|
2012-02-14 11:57:15 +00:00
|
|
|
}
|
|
|
|
}
|