1
0
Fork 0
composer/tests/Composer/Test/Package/Dumper/ArrayDumperTest.php

165 lines
4.4 KiB
PHP
Raw Normal View History

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;
use Composer\Package\LinkConstraint\VersionConstraint;
2012-02-14 11:57:15 +00:00
class ArrayDumperTest extends \PHPUnit_Framework_TestCase
{
/**
* @var ArrayDumper
*/
private $dumper;
/**
* @var \Composer\Package\CompletePackageInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $package;
2012-02-14 11:57:15 +00:00
public function setUp()
{
$this->dumper = new ArrayDumper();
$this->package = $this->getMock('Composer\Package\CompletePackageInterface');
2012-02-14 11:57:15 +00:00
}
public function testRequiredInformation()
2012-02-14 11:57:15 +00:00
{
$this
->packageExpects('getPrettyName', 'foo')
->packageExpects('getPrettyVersion', '1.0')
->packageExpects('getVersion', '1.0.0.0');
2012-02-14 11:57:15 +00:00
$config = $this->dumper->dump($this->package);
$this->assertEquals(
array(
'name' => 'foo',
'version' => '1.0',
'version_normalized' => '1.0.0.0'
),
$config
);
2012-02-14 11:57:15 +00:00
}
public function testRootPackage()
{
$this->package = $this->getMock('Composer\Package\RootPackageInterface');
$this
->packageExpects('getMinimumStability', 'dev');
$config = $this->dumper->dump($this->package);
$this->assertSame('dev', $config['minimum-stability']);
}
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
{
$this->packageExpects('get'.ucfirst($method ?: $key), $value);
2012-02-14 11:57:15 +00:00
$config = $this->dumper->dump($this->package);
2012-02-14 11:57:15 +00:00
$this->assertSame($expectedValue ?: $value, $config[$key]);
2012-02-14 11:57:15 +00:00
}
public function getKeys()
{
return array(
array(
'type',
'library'
),
2012-04-14 09:56:13 +00:00
array(
'time',
new \DateTime('2012-02-01'),
'ReleaseDate',
'2012-02-01 00:00:00',
),
array(
'authors',
array('Nils Adermann <naderman@naderman.de>', 'Jordi Boggiano <j.boggiano@seld.be>')
),
array(
'homepage',
'http://getcomposer.org'
),
array(
'description',
'Package Manager'
),
array(
'keywords',
array('package', 'dependency', 'autoload')
),
array(
'bin',
array('bin/composer'),
'binaries'
),
array(
'license',
array('MIT')
),
array(
'autoload',
array('psr-0' => array('Composer' => 'src/'))
),
array(
'repositories',
array('packagist' => false)
),
array(
'scripts',
array('post-update-cmd' => 'MyVendor\\MyClass::postUpdate')
),
array(
'extra',
array('class' => 'MyVendor\\Installer')
),
array(
'require',
array(new Link('foo', 'foo/bar', new VersionConstraint('=', '1.0.0.0'), 'requires', '1.0.0')),
'requires',
array('foo/bar' => '1.0.0'),
),
array(
'require-dev',
array(new Link('foo', 'foo/bar', new VersionConstraint('=', '1.0.0.0'), 'requires (for development)', '1.0.0')),
'devRequires',
array('foo/bar' => '1.0.0'),
),
array(
'suggest',
array('foo/bar' => 'very useful package'),
'suggests'
),
array(
'support',
array('foo' => 'bar'),
)
2012-02-14 11:57:15 +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
}