1
0
Fork 0
composer/tests/Composer/Test/Package/CompletePackageTest.php

99 lines
3.1 KiB
PHP
Raw Normal View History

2022-02-23 15:58:18 +00:00
<?php declare(strict_types=1);
/*
2011-04-16 12:42:35 +00:00
* This file is part of Composer.
*
2011-04-16 12:42:35 +00:00
* (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.
*/
2011-04-17 21:45:37 +00:00
namespace Composer\Test\Package;
use Composer\Package\Package;
use Composer\Semver\VersionParser;
use Composer\Test\TestCase;
class CompletePackageTest extends TestCase
{
/**
* Memory package naming, versioning, and marshalling semantics provider
*
* demonstrates several versioning schemes
*/
public static function providerVersioningSchemes(): array
{
2022-08-17 12:20:07 +00:00
$provider[] = ['foo', '1-beta'];
$provider[] = ['node', '0.5.6'];
$provider[] = ['li3', '0.10'];
$provider[] = ['mongodb_odm', '1.0.0BETA3'];
$provider[] = ['DoctrineCommon', '2.2.0-DEV'];
return $provider;
}
/**
* @dataProvider providerVersioningSchemes
*/
2022-02-22 15:47:09 +00:00
public function testPackageHasExpectedNamingSemantics(string $name, string $version): void
{
$versionParser = new VersionParser();
$normVersion = $versionParser->normalize($version);
$package = new Package($name, $normVersion, $version);
self::assertEquals(strtolower($name), $package->getName());
}
/**
* @dataProvider providerVersioningSchemes
*/
2022-02-22 15:47:09 +00:00
public function testPackageHasExpectedVersioningSemantics(string $name, string $version): void
{
$versionParser = new VersionParser();
$normVersion = $versionParser->normalize($version);
$package = new Package($name, $normVersion, $version);
self::assertEquals($version, $package->getPrettyVersion());
self::assertEquals($normVersion, $package->getVersion());
}
/**
* @dataProvider providerVersioningSchemes
*/
2022-02-22 15:47:09 +00:00
public function testPackageHasExpectedMarshallingSemantics(string $name, string $version): void
{
$versionParser = new VersionParser();
$normVersion = $versionParser->normalize($version);
$package = new Package($name, $normVersion, $version);
self::assertEquals(strtolower($name).'-'.$normVersion, (string) $package);
}
public function testGetTargetDir(): void
{
$package = new Package('a', '1.0.0.0', '1.0');
self::assertNull($package->getTargetDir());
$package->setTargetDir('./../foo/');
self::assertEquals('foo/', $package->getTargetDir());
$package->setTargetDir('foo/../../../bar/');
self::assertEquals('foo/bar/', $package->getTargetDir());
$package->setTargetDir('../..');
self::assertEquals('', $package->getTargetDir());
2012-09-18 16:32:24 +00:00
$package->setTargetDir('..');
self::assertEquals('', $package->getTargetDir());
2012-09-18 16:32:24 +00:00
$package->setTargetDir('/..');
self::assertEquals('', $package->getTargetDir());
2012-09-18 16:32:24 +00:00
$package->setTargetDir('/foo/..');
self::assertEquals('foo/', $package->getTargetDir());
$package->setTargetDir('/foo/..//bar');
self::assertEquals('foo/bar', $package->getTargetDir());
}
}