2022-02-23 15:58:18 +00:00
|
|
|
<?php declare(strict_types=1);
|
2013-03-21 11:33:02 +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;
|
|
|
|
|
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
|
|
|
|
*/
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testSetSameRepository(): void
|
2013-03-21 11:33:02 +00:00
|
|
|
{
|
2022-08-17 12:20:07 +00:00
|
|
|
$package = $this->getMockForAbstractClass('Composer\Package\BasePackage', ['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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testSetAnotherRepository(): void
|
2013-03-21 11:33:02 +00:00
|
|
|
{
|
2021-12-09 19:55:26 +00:00
|
|
|
self::expectException('LogicException');
|
2020-09-10 15:21:11 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$package = $this->getMockForAbstractClass('Composer\Package\BasePackage', ['foo']);
|
2013-03-21 11:33:02 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
/**
|
2021-11-01 20:44:12 +00:00
|
|
|
* @dataProvider provideFormattedVersions
|
2015-05-31 06:30:52 +00:00
|
|
|
*/
|
2022-02-22 15:47:09 +00:00
|
|
|
public function testFormatVersionForDevPackage(BasePackage $package, bool $truncate, string $expected): void
|
2015-05-31 06:30:52 +00:00
|
|
|
{
|
|
|
|
$this->assertSame($expected, $package->getFullPrettyVersion($truncate));
|
|
|
|
}
|
|
|
|
|
2022-02-21 12:42:28 +00:00
|
|
|
public function provideFormattedVersions(): array
|
2015-05-31 06:30:52 +00:00
|
|
|
{
|
2022-08-17 12:20:07 +00:00
|
|
|
$data = [
|
|
|
|
[
|
2015-05-31 06:30:52 +00:00
|
|
|
'sourceReference' => 'v2.1.0-RC2',
|
|
|
|
'truncate' => true,
|
2015-09-28 09:51:14 +00:00
|
|
|
'expected' => 'PrettyVersion v2.1.0-RC2',
|
2022-08-17 12:20:07 +00:00
|
|
|
],
|
|
|
|
[
|
2015-05-31 06:30:52 +00:00
|
|
|
'sourceReference' => 'bbf527a27356414bfa9bf520f018c5cb7af67c77',
|
|
|
|
'truncate' => true,
|
2015-09-28 09:51:14 +00:00
|
|
|
'expected' => 'PrettyVersion bbf527a',
|
2022-08-17 12:20:07 +00:00
|
|
|
],
|
|
|
|
[
|
2015-05-31 06:30:52 +00:00
|
|
|
'sourceReference' => 'v1.0.0',
|
|
|
|
'truncate' => false,
|
2015-09-28 09:51:14 +00:00
|
|
|
'expected' => 'PrettyVersion v1.0.0',
|
2022-08-17 12:20:07 +00:00
|
|
|
],
|
|
|
|
[
|
2015-05-31 06:30:52 +00:00
|
|
|
'sourceReference' => 'bbf527a27356414bfa9bf520f018c5cb7af67c77',
|
|
|
|
'truncate' => false,
|
2015-09-28 09:51:14 +00:00
|
|
|
'expected' => 'PrettyVersion bbf527a27356414bfa9bf520f018c5cb7af67c77',
|
2022-08-17 12:20:07 +00:00
|
|
|
],
|
|
|
|
];
|
2015-05-31 06:30:52 +00:00
|
|
|
|
2022-02-21 12:42:28 +00:00
|
|
|
$createPackage = function ($arr): array {
|
2022-08-17 12:20:07 +00:00
|
|
|
$package = $this->getMockForAbstractClass('\Composer\Package\BasePackage', [], '', false);
|
2022-01-03 14:40:32 +00:00
|
|
|
$package->expects($this->once())->method('isDev')->will($this->returnValue(true));
|
|
|
|
$package->expects($this->any())->method('getSourceType')->will($this->returnValue('git'));
|
|
|
|
$package->expects($this->once())->method('getPrettyVersion')->will($this->returnValue('PrettyVersion'));
|
|
|
|
$package->expects($this->any())->method('getSourceReference')->will($this->returnValue($arr['sourceReference']));
|
2015-05-31 06:30:52 +00:00
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
return [$package, $arr['truncate'], $arr['expected']];
|
2015-05-31 06:30:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return array_map($createPackage, $data);
|
|
|
|
}
|
2021-11-11 14:56:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string[] $packageNames
|
2022-02-02 20:35:37 +00:00
|
|
|
* @param non-empty-string $wrap
|
2021-11-11 14:56:38 +00:00
|
|
|
*
|
|
|
|
* @dataProvider dataPackageNamesToRegexp
|
|
|
|
*/
|
2022-02-22 15:47:09 +00:00
|
|
|
public function testPackageNamesToRegexp(array $packageNames, $wrap, string $expectedRegexp): void
|
2021-11-11 14:56:38 +00:00
|
|
|
{
|
|
|
|
$regexp = BasePackage::packageNamesToRegexp($packageNames, $wrap);
|
|
|
|
|
|
|
|
$this->assertSame($expectedRegexp, $regexp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return mixed[][]
|
|
|
|
*/
|
2022-02-18 10:22:01 +00:00
|
|
|
public function dataPackageNamesToRegexp(): array
|
2021-11-11 14:56:38 +00:00
|
|
|
{
|
2022-08-17 12:20:07 +00:00
|
|
|
return [
|
|
|
|
[
|
|
|
|
['ext-*', 'monolog/monolog'], '{^%s$}i', '{^ext\-.*|monolog/monolog$}i',
|
|
|
|
['php'], '{^%s$}i', '{^php$}i',
|
|
|
|
['*'], '{^%s$}i', '{^.*$}i',
|
|
|
|
['foo', 'bar'], '§%s§', '§foo|bar§',
|
|
|
|
],
|
|
|
|
];
|
2021-11-11 14:56:38 +00:00
|
|
|
}
|
2013-03-21 11:33:02 +00:00
|
|
|
}
|