1
0
Fork 0

Update/add tests

pull/575/head
Jordi Boggiano 2012-04-14 11:56:13 +02:00
parent 53191eb0fe
commit e922404f19
3 changed files with 154 additions and 14 deletions

View File

@ -14,6 +14,8 @@ namespace Composer\Test\Package\Dumper;
use Composer\Package\Dumper\ArrayDumper;
use Composer\Package\MemoryPackage;
use Composer\Package\Link;
use Composer\Package\LinkConstraint\VersionConstraint;
class ArrayDumperTest extends \PHPUnit_Framework_TestCase
{
@ -27,13 +29,13 @@ class ArrayDumperTest extends \PHPUnit_Framework_TestCase
$package = new MemoryPackage('foo', '1.0.0.0', '1.0');
$config = $this->dumper->dump($package);
$this->assertEquals(array('name', 'version', 'version_normalized', 'type', 'names'), array_keys($config));
$this->assertEquals(array('name', 'version', 'version_normalized', 'type'), array_keys($config));
}
/**
* @dataProvider getKeys
*/
public function testKeys($key, $value, $expectedValue = null, $method = null)
public function testKeys($key, $value, $method = null, $expectedValue = null)
{
$package = new MemoryPackage('foo', '1.0.0.0', '1.0');
@ -50,17 +52,70 @@ class ArrayDumperTest extends \PHPUnit_Framework_TestCase
public function getKeys()
{
return array(
array('time', new \DateTime('2012-02-01'), '2012-02-01 00:00:00', 'ReleaseDate'),
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'), null, '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(
'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'
),
);
}
}

View File

@ -13,6 +13,7 @@
namespace Composer\Test\Package\Loader;
use Composer\Package\Loader\ArrayLoader;
use Composer\Package\Dumper\ArrayDumper;
class ArrayLoaderTest extends \PHPUnit_Framework_TestCase
{
@ -35,4 +36,88 @@ class ArrayLoaderTest extends \PHPUnit_Framework_TestCase
$replaces = $package->getReplaces();
$this->assertEquals('== 1.2.3.4', (string) $replaces[0]->getConstraint());
}
public function testTypeDefault()
{
$config = array(
'name' => 'A',
'version' => '1.0',
);
$package = $this->loader->load($config);
$this->assertEquals('library', $package->getType());
$config = array(
'name' => 'A',
'version' => '1.0',
'type' => 'foo',
);
$package = $this->loader->load($config);
$this->assertEquals('foo', $package->getType());
}
public function testNormalizedVersionOptimization()
{
$config = array(
'name' => 'A',
'version' => '1.2.3',
);
$package = $this->loader->load($config);
$this->assertEquals('1.2.3.0', $package->getVersion());
$config = array(
'name' => 'A',
'version' => '1.2.3',
'version_normalized' => '1.2.3.4',
);
$package = $this->loader->load($config);
$this->assertEquals('1.2.3.4', $package->getVersion());
}
public function testParseDump()
{
$config = array(
'name' => 'A/B',
'version' => '1.2.3',
'version_normalized' => '1.2.3.0',
'description' => 'Foo bar',
'type' => 'library',
'keywords' => array('a', 'b', 'c'),
'homepage' => 'http://example.com',
'license' => array('MIT', 'GPLv3'),
'authors' => array(
array('name' => 'Bob', 'email' => 'bob@example.org', 'homepage' => 'example.org'),
),
'require' => array(
'foo/bar' => '1.0',
),
'require-dev' => array(
'foo/baz' => '1.0',
),
'replace' => array(
'foo/qux' => '1.0',
),
'conflict' => array(
'foo/quux' => '1.0',
),
'provide' => array(
'foo/quuux' => '1.0',
),
'autoload' => array(
'psr-0' => array('Ns\Prefix' => 'path'),
'classmap' => array('path', 'path2'),
),
'include-path' => array('path3', 'path4'),
'target-dir' => 'some/prefix',
'extra' => array('random' => array('things' => 'of', 'any' => 'shape')),
'bin' => array('bin1', 'bin/foo'),
);
$package = $this->loader->load($config);
$dumper = new ArrayDumper;
$this->assertEquals($config, $dumper->dump($package));
}
}

View File

@ -95,7 +95,7 @@ class FilesystemRepositoryTest extends TestCase
->expects($this->once())
->method('write')
->with(array(
array('name' => 'mypkg', 'type' => 'library', 'names' => array('mypkg'), 'version' => '0.1.10', 'version_normalized' => '0.1.10.0')
array('name' => 'mypkg', 'type' => 'library', 'version' => '0.1.10', 'version_normalized' => '0.1.10.0')
));
$repository->addPackage($this->getPackage('mypkg', '0.1.10'));