2013-03-21 11:33:02 +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;
|
|
|
|
|
2015-05-31 06:30:52 +00:00
|
|
|
use Composer\Package\BasePackage;
|
2020-02-07 03:18:45 +00:00
|
|
|
use Composer\Test\TestCase;
|
2015-05-31 06:30:52 +00:00
|
|
|
|
2017-11-04 14:52:13 +00:00
|
|
|
class BasePackageTest extends TestCase
|
2013-03-21 11:33:02 +00:00
|
|
|
{
|
2020-02-07 06:35:07 +00:00
|
|
|
/**
|
|
|
|
* @doesNotPerformAssertions
|
|
|
|
*/
|
2013-03-21 11:33:02 +00:00
|
|
|
public function testSetSameRepository()
|
|
|
|
{
|
|
|
|
$package = $this->getMockForAbstractClass('Composer\Package\BasePackage', array('foo'));
|
2018-04-12 08:24:56 +00:00
|
|
|
$repository = $this->getMockBuilder('Composer\Repository\RepositoryInterface')->getMock();
|
2013-03-21 11:33:02 +00:00
|
|
|
|
|
|
|
$package->setRepository($repository);
|
|
|
|
try {
|
|
|
|
$package->setRepository($repository);
|
|
|
|
} catch (\Exception $e) {
|
2013-12-27 11:36:18 +00:00
|
|
|
$this->fail('Set against the same repository is allowed.');
|
2013-03-21 11:33:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException LogicException
|
|
|
|
*/
|
|
|
|
public function testSetAnotherRepository()
|
|
|
|
{
|
|
|
|
$package = $this->getMockForAbstractClass('Composer\Package\BasePackage', array('foo'));
|
|
|
|
|
2018-04-12 08:24:56 +00:00
|
|
|
$package->setRepository($this->getMockBuilder('Composer\Repository\RepositoryInterface')->getMock());
|
|
|
|
$package->setRepository($this->getMockBuilder('Composer\Repository\RepositoryInterface')->getMock());
|
2013-03-21 11:33:02 +00:00
|
|
|
}
|
2015-05-31 06:30:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider formattedVersions
|
|
|
|
*/
|
|
|
|
public function testFormatVersionForDevPackage(BasePackage $package, $truncate, $expected)
|
|
|
|
{
|
|
|
|
$this->assertSame($expected, $package->getFullPrettyVersion($truncate));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function formattedVersions()
|
|
|
|
{
|
|
|
|
$data = array(
|
|
|
|
array(
|
|
|
|
'sourceReference' => 'v2.1.0-RC2',
|
|
|
|
'truncate' => true,
|
2015-09-28 09:51:14 +00:00
|
|
|
'expected' => 'PrettyVersion v2.1.0-RC2',
|
2015-05-31 06:30:52 +00:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'sourceReference' => 'bbf527a27356414bfa9bf520f018c5cb7af67c77',
|
|
|
|
'truncate' => true,
|
2015-09-28 09:51:14 +00:00
|
|
|
'expected' => 'PrettyVersion bbf527a',
|
2015-05-31 06:30:52 +00:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'sourceReference' => 'v1.0.0',
|
|
|
|
'truncate' => false,
|
2015-09-28 09:51:14 +00:00
|
|
|
'expected' => 'PrettyVersion v1.0.0',
|
2015-05-31 06:30:52 +00:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'sourceReference' => 'bbf527a27356414bfa9bf520f018c5cb7af67c77',
|
|
|
|
'truncate' => false,
|
2015-09-28 09:51:14 +00:00
|
|
|
'expected' => 'PrettyVersion bbf527a27356414bfa9bf520f018c5cb7af67c77',
|
2015-05-31 06:30:52 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
$self = $this;
|
|
|
|
$createPackage = function ($arr) use ($self) {
|
|
|
|
$package = $self->getMockForAbstractClass('\Composer\Package\BasePackage', array(), '', false);
|
|
|
|
$package->expects($self->once())->method('isDev')->will($self->returnValue(true));
|
|
|
|
$package->expects($self->once())->method('getSourceType')->will($self->returnValue('git'));
|
|
|
|
$package->expects($self->once())->method('getPrettyVersion')->will($self->returnValue('PrettyVersion'));
|
|
|
|
$package->expects($self->any())->method('getSourceReference')->will($self->returnValue($arr['sourceReference']));
|
|
|
|
|
|
|
|
return array($package, $arr['truncate'], $arr['expected']);
|
|
|
|
};
|
|
|
|
|
|
|
|
return array_map($createPackage, $data);
|
|
|
|
}
|
2013-03-21 11:33:02 +00:00
|
|
|
}
|