2012-02-14 11:57:15 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
/**
|
2012-08-23 13:52:40 +00:00
|
|
|
* @var \Composer\Package\CompletePackageInterface|\PHPUnit_Framework_MockObject_MockObject
|
2012-07-14 10:29:53 +00:00
|
|
|
*/
|
|
|
|
private $package;
|
|
|
|
|
2012-02-14 11:57:15 +00:00
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
$this->dumper = new ArrayDumper();
|
2018-04-12 08:24:56 +00:00
|
|
|
$this->package = $this->getMockBuilder('Composer\Package\CompletePackageInterface')->getMock();
|
2016-11-25 07:28:49 +00:00
|
|
|
$this->packageExpects('getTransportOptions', array());
|
2012-02-14 11:57:15 +00:00
|
|
|
}
|
|
|
|
|
2012-07-14 10:29:53 +00:00
|
|
|
public function testRequiredInformation()
|
2012-02-14 11:57:15 +00:00
|
|
|
{
|
2012-07-14 10:29:53 +00:00
|
|
|
$this
|
|
|
|
->packageExpects('getPrettyName', 'foo')
|
|
|
|
->packageExpects('getPrettyVersion', '1.0')
|
2016-11-25 07:28:49 +00:00
|
|
|
->packageExpects('getVersion', '1.0.0.0')
|
|
|
|
;
|
2012-02-14 11:57:15 +00:00
|
|
|
|
2012-07-14 10:29:53 +00:00
|
|
|
$config = $this->dumper->dump($this->package);
|
|
|
|
$this->assertEquals(
|
|
|
|
array(
|
|
|
|
'name' => 'foo',
|
|
|
|
'version' => '1.0',
|
2015-09-28 09:51:14 +00:00
|
|
|
'version_normalized' => '1.0.0.0',
|
2012-07-14 10:29:53 +00:00
|
|
|
),
|
|
|
|
$config
|
|
|
|
);
|
2012-02-14 11:57:15 +00:00
|
|
|
}
|
|
|
|
|
2012-09-19 21:08:37 +00:00
|
|
|
public function testRootPackage()
|
|
|
|
{
|
2018-04-12 08:24:56 +00:00
|
|
|
$this->package = $this->getMockBuilder('Composer\Package\RootPackageInterface')->getMock();
|
2012-09-19 21:08:37 +00:00
|
|
|
|
|
|
|
$this
|
2016-11-25 07:28:49 +00:00
|
|
|
->packageExpects('getMinimumStability', 'dev')
|
|
|
|
->packageExpects('getTransportOptions', array())
|
|
|
|
;
|
2012-09-19 21:08:37 +00:00
|
|
|
|
|
|
|
$config = $this->dumper->dump($this->package);
|
|
|
|
$this->assertSame('dev', $config['minimum-stability']);
|
|
|
|
}
|
|
|
|
|
2014-10-02 21:04:35 +00:00
|
|
|
public function testDumpAbandoned()
|
|
|
|
{
|
2014-10-03 13:12:16 +00:00
|
|
|
$this->packageExpects('isAbandoned', true);
|
2014-10-02 21:04:35 +00:00
|
|
|
$this->packageExpects('getReplacementPackage', true);
|
|
|
|
|
|
|
|
$config = $this->dumper->dump($this->package);
|
|
|
|
|
2017-11-30 14:58:10 +00:00
|
|
|
$this->assertTrue($config['abandoned']);
|
2014-10-02 21:04:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testDumpAbandonedReplacement()
|
|
|
|
{
|
2014-10-03 13:12:16 +00:00
|
|
|
$this->packageExpects('isAbandoned', true);
|
2014-10-02 21:04:35 +00:00
|
|
|
$this->packageExpects('getReplacementPackage', 'foo/bar');
|
|
|
|
|
|
|
|
$config = $this->dumper->dump($this->package);
|
|
|
|
|
|
|
|
$this->assertSame('foo/bar', $config['abandoned']);
|
|
|
|
}
|
|
|
|
|
2012-02-14 11:57:15 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider getKeys
|
|
|
|
*/
|
2012-04-14 09:56:13 +00:00
|
|
|
public function testKeys($key, $value, $method = null, $expectedValue = null)
|
2012-02-14 11:57:15 +00:00
|
|
|
{
|
2018-04-12 08:24:56 +00:00
|
|
|
$this->package = $this->getMockBuilder('Composer\Package\RootPackageInterface')->getMock();
|
2016-11-25 07:28:49 +00:00
|
|
|
|
2012-07-14 10:29:53 +00:00
|
|
|
$this->packageExpects('get'.ucfirst($method ?: $key), $value);
|
2014-10-02 21:04:35 +00:00
|
|
|
$this->packageExpects('isAbandoned', $value);
|
2012-02-14 11:57:15 +00:00
|
|
|
|
2016-11-25 07:28:49 +00:00
|
|
|
if ($method !== 'transportOptions') {
|
|
|
|
$this->packageExpects('getTransportOptions', array());
|
|
|
|
}
|
|
|
|
|
2012-07-14 10:29:53 +00:00
|
|
|
$config = $this->dumper->dump($this->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
|
|
|
}
|
|
|
|
|
|
|
|
public function getKeys()
|
|
|
|
{
|
|
|
|
return array(
|
2012-07-14 10:29:53 +00:00
|
|
|
array(
|
|
|
|
'type',
|
2015-09-28 09:51:14 +00:00
|
|
|
'library',
|
2012-07-14 10:29:53 +00:00
|
|
|
),
|
2012-04-14 09:56:13 +00:00
|
|
|
array(
|
|
|
|
'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),
|
2012-04-14 09:56:13 +00:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'authors',
|
2015-09-28 09:51:14 +00:00
|
|
|
array('Nils Adermann <naderman@naderman.de>', 'Jordi Boggiano <j.boggiano@seld.be>'),
|
2012-04-14 09:56:13 +00:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'homepage',
|
2015-09-28 09:51:14 +00:00
|
|
|
'https://getcomposer.org',
|
2012-04-14 09:56:13 +00:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'description',
|
2015-09-28 09:51:14 +00:00
|
|
|
'Dependency Manager',
|
2012-04-14 09:56:13 +00:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'keywords',
|
2013-01-31 08:55:19 +00:00
|
|
|
array('package', 'dependency', 'autoload'),
|
|
|
|
null,
|
2015-09-28 09:51:14 +00:00
|
|
|
array('autoload', 'dependency', 'package'),
|
2012-04-14 09:56:13 +00:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'bin',
|
|
|
|
array('bin/composer'),
|
2015-09-28 09:51:14 +00:00
|
|
|
'binaries',
|
2012-04-14 09:56:13 +00:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'license',
|
2015-09-28 09:51:14 +00:00
|
|
|
array('MIT'),
|
2012-04-14 09:56:13 +00:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'autoload',
|
2015-09-28 09:51:14 +00:00
|
|
|
array('psr-0' => array('Composer' => 'src/')),
|
2012-04-14 09:56:13 +00:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'repositories',
|
2015-09-28 09:51:14 +00:00
|
|
|
array('packagist' => false),
|
2012-04-14 09:56:13 +00:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'scripts',
|
2015-09-28 09:51:14 +00:00
|
|
|
array('post-update-cmd' => 'MyVendor\\MyClass::postUpdate'),
|
2012-04-14 09:56:13 +00:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'extra',
|
2015-09-28 09:51:14 +00:00
|
|
|
array('class' => 'MyVendor\\Installer'),
|
2012-04-14 09:56:13 +00:00
|
|
|
),
|
2013-02-07 14:45:58 +00:00
|
|
|
array(
|
|
|
|
'archive',
|
|
|
|
array('/foo/bar', 'baz', '!/foo/bar/baz'),
|
|
|
|
'archiveExcludes',
|
|
|
|
array(
|
|
|
|
'exclude' => array('/foo/bar', 'baz', '!/foo/bar/baz'),
|
|
|
|
),
|
|
|
|
),
|
2012-04-14 09:56:13 +00:00
|
|
|
array(
|
|
|
|
'require',
|
2015-09-24 14:32:36 +00:00
|
|
|
array(new Link('foo', 'foo/bar', new Constraint('=', '1.0.0.0'), 'requires', '1.0.0')),
|
2012-04-14 09:56:13 +00:00
|
|
|
'requires',
|
|
|
|
array('foo/bar' => '1.0.0'),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'require-dev',
|
2015-09-24 14:32:36 +00:00
|
|
|
array(new Link('foo', 'foo/bar', new Constraint('=', '1.0.0.0'), 'requires (for development)', '1.0.0')),
|
2012-04-14 09:56:13 +00:00
|
|
|
'devRequires',
|
|
|
|
array('foo/bar' => '1.0.0'),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'suggest',
|
|
|
|
array('foo/bar' => 'very useful package'),
|
2015-09-28 09:51:14 +00:00
|
|
|
'suggests',
|
2012-04-14 09:56:13 +00:00
|
|
|
),
|
2012-07-14 10:29:53 +00:00
|
|
|
array(
|
|
|
|
'support',
|
|
|
|
array('foo' => 'bar'),
|
2013-01-31 08:55:19 +00:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'require',
|
2015-09-24 14:32:36 +00:00
|
|
|
array(new Link('foo', 'foo/bar', new Constraint('=', '1.0.0.0'), 'requires', '1.0.0'), new Link('bar', 'bar/baz', new Constraint('=', '1.0.0.0'), 'requires', '1.0.0')),
|
2013-01-31 08:55:19 +00:00
|
|
|
'requires',
|
2015-09-28 09:51:14 +00:00
|
|
|
array('bar/baz' => '1.0.0', 'foo/bar' => '1.0.0'),
|
2013-01-31 08:55:19 +00:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'require-dev',
|
2015-09-24 14:32:36 +00:00
|
|
|
array(new Link('foo', 'foo/bar', new Constraint('=', '1.0.0.0'), 'requires', '1.0.0'), new Link('bar', 'bar/baz', new Constraint('=', '1.0.0.0'), 'requires', '1.0.0')),
|
2013-01-31 08:55:19 +00:00
|
|
|
'devRequires',
|
2015-09-28 09:51:14 +00:00
|
|
|
array('bar/baz' => '1.0.0', 'foo/bar' => '1.0.0'),
|
2013-01-31 08:55:19 +00:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'suggest',
|
|
|
|
array('foo/bar' => 'very useful package', 'bar/baz' => 'another useful package'),
|
|
|
|
'suggests',
|
2015-09-28 09:51:14 +00:00
|
|
|
array('bar/baz' => 'another useful package', 'foo/bar' => 'very useful package'),
|
2013-01-31 08:55:19 +00:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'provide',
|
2015-09-24 14:32:36 +00:00
|
|
|
array(new Link('foo', 'foo/bar', new Constraint('=', '1.0.0.0'), 'requires', '1.0.0'), new Link('bar', 'bar/baz', new Constraint('=', '1.0.0.0'), 'requires', '1.0.0')),
|
2013-01-31 08:55:19 +00:00
|
|
|
'provides',
|
2015-09-28 09:51:14 +00:00
|
|
|
array('bar/baz' => '1.0.0', 'foo/bar' => '1.0.0'),
|
2013-01-31 08:55:19 +00:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'replace',
|
2015-09-24 14:32:36 +00:00
|
|
|
array(new Link('foo', 'foo/bar', new Constraint('=', '1.0.0.0'), 'requires', '1.0.0'), new Link('bar', 'bar/baz', new Constraint('=', '1.0.0.0'), 'requires', '1.0.0')),
|
2013-01-31 08:55:19 +00:00
|
|
|
'replaces',
|
2015-09-28 09:51:14 +00:00
|
|
|
array('bar/baz' => '1.0.0', 'foo/bar' => '1.0.0'),
|
2013-01-31 08:55:19 +00:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'conflict',
|
2015-09-24 14:32:36 +00:00
|
|
|
array(new Link('foo', 'foo/bar', new Constraint('=', '1.0.0.0'), 'requires', '1.0.0'), new Link('bar', 'bar/baz', new Constraint('=', '1.0.0.0'), 'requires', '1.0.0')),
|
2013-01-31 08:55:19 +00:00
|
|
|
'conflicts',
|
2015-09-28 09:51:14 +00:00
|
|
|
array('bar/baz' => '1.0.0', 'foo/bar' => '1.0.0'),
|
2013-08-19 07:39:13 +00:00
|
|
|
),
|
|
|
|
array(
|
2014-05-07 16:25:28 +00:00
|
|
|
'transport-options',
|
|
|
|
array('ssl' => array('local_cert' => '/opt/certs/test.pem')),
|
2015-09-28 09:51:14 +00:00
|
|
|
'transportOptions',
|
|
|
|
),
|
2012-02-14 11:57:15 +00:00
|
|
|
);
|
|
|
|
}
|
2012-07-14 10:29:53 +00:00
|
|
|
|
|
|
|
private function packageExpects($method, $value)
|
|
|
|
{
|
|
|
|
$this->package
|
|
|
|
->expects($this->any())
|
|
|
|
->method($method)
|
|
|
|
->will($this->returnValue($value));
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2012-02-14 11:57:15 +00:00
|
|
|
}
|