2011-04-05 15:37:19 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2011-04-16 12:42:35 +00:00
|
|
|
* This file is part of Composer.
|
2011-04-05 15:37:19 +00:00
|
|
|
*
|
2011-04-16 12:42:35 +00:00
|
|
|
* (c) Nils Adermann <naderman@naderman.de>
|
|
|
|
* Jordi Boggiano <j.boggiano@seld.be>
|
2011-04-05 15:37:19 +00:00
|
|
|
*
|
|
|
|
* 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;
|
2011-04-05 15:37:19 +00:00
|
|
|
|
2012-08-23 13:52:40 +00:00
|
|
|
use Composer\Package\Package;
|
2015-09-24 14:32:36 +00:00
|
|
|
use Composer\Semver\VersionParser;
|
2018-11-12 14:23:32 +00:00
|
|
|
use Composer\Test\TestCase;
|
2011-04-05 15:37:19 +00:00
|
|
|
|
2012-08-23 13:52:40 +00:00
|
|
|
class CompletePackageTest extends TestCase
|
2011-04-05 15:37:19 +00:00
|
|
|
{
|
2011-09-27 04:05:57 +00:00
|
|
|
/**
|
|
|
|
* Memory package naming, versioning, and marshalling semantics provider
|
|
|
|
*
|
|
|
|
* demonstrates several versioning schemes
|
|
|
|
*/
|
2022-02-21 12:42:28 +00:00
|
|
|
public function providerVersioningSchemes(): array
|
2011-09-27 04:05:57 +00:00
|
|
|
{
|
2011-11-20 14:06:12 +00:00
|
|
|
$provider[] = array('foo', '1-beta');
|
|
|
|
$provider[] = array('node', '0.5.6');
|
|
|
|
$provider[] = array('li3', '0.10');
|
|
|
|
$provider[] = array('mongodb_odm', '1.0.0BETA3');
|
|
|
|
$provider[] = array('DoctrineCommon', '2.2.0-DEV');
|
2011-09-27 04:05:57 +00:00
|
|
|
|
|
|
|
return $provider;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-09-28 09:33:20 +00:00
|
|
|
* @dataProvider providerVersioningSchemes
|
2021-11-01 20:44:12 +00:00
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @param string $version
|
2011-09-27 04:05:57 +00:00
|
|
|
*/
|
2022-02-22 15:47:09 +00:00
|
|
|
public function testPackageHasExpectedNamingSemantics(string $name, string $version): void
|
2011-04-05 15:37:19 +00:00
|
|
|
{
|
2011-11-20 14:06:12 +00:00
|
|
|
$versionParser = new VersionParser();
|
|
|
|
$normVersion = $versionParser->normalize($version);
|
2012-08-23 13:52:40 +00:00
|
|
|
$package = new Package($name, $normVersion, $version);
|
2011-09-27 04:05:57 +00:00
|
|
|
$this->assertEquals(strtolower($name), $package->getName());
|
|
|
|
}
|
2011-04-05 15:37:19 +00:00
|
|
|
|
2011-09-27 04:05:57 +00:00
|
|
|
/**
|
2011-09-28 09:33:20 +00:00
|
|
|
* @dataProvider providerVersioningSchemes
|
2021-11-01 20:44:12 +00:00
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @param string $version
|
2011-09-27 04:05:57 +00:00
|
|
|
*/
|
2022-02-22 15:47:09 +00:00
|
|
|
public function testPackageHasExpectedVersioningSemantics(string $name, string $version): void
|
2011-09-27 04:05:57 +00:00
|
|
|
{
|
2011-11-20 14:06:12 +00:00
|
|
|
$versionParser = new VersionParser();
|
|
|
|
$normVersion = $versionParser->normalize($version);
|
2012-08-23 13:52:40 +00:00
|
|
|
$package = new Package($name, $normVersion, $version);
|
2011-11-20 14:06:12 +00:00
|
|
|
$this->assertEquals($version, $package->getPrettyVersion());
|
|
|
|
$this->assertEquals($normVersion, $package->getVersion());
|
2011-09-27 04:05:57 +00:00
|
|
|
}
|
2011-04-05 15:37:19 +00:00
|
|
|
|
2011-09-27 04:05:57 +00:00
|
|
|
/**
|
2011-09-28 09:33:20 +00:00
|
|
|
* @dataProvider providerVersioningSchemes
|
2021-11-01 20:44:12 +00:00
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @param string $version
|
2011-09-27 04:05:57 +00:00
|
|
|
*/
|
2022-02-22 15:47:09 +00:00
|
|
|
public function testPackageHasExpectedMarshallingSemantics(string $name, string $version): void
|
2011-09-27 04:05:57 +00:00
|
|
|
{
|
2011-11-20 14:06:12 +00:00
|
|
|
$versionParser = new VersionParser();
|
|
|
|
$normVersion = $versionParser->normalize($version);
|
2012-08-23 13:52:40 +00:00
|
|
|
$package = new Package($name, $normVersion, $version);
|
2011-11-20 14:06:12 +00:00
|
|
|
$this->assertEquals(strtolower($name).'-'.$normVersion, (string) $package);
|
2011-04-05 15:37:19 +00:00
|
|
|
}
|
2011-09-27 04:05:57 +00:00
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testGetTargetDir(): void
|
2012-09-18 16:30:11 +00:00
|
|
|
{
|
|
|
|
$package = new Package('a', '1.0.0.0', '1.0');
|
|
|
|
|
|
|
|
$this->assertNull($package->getTargetDir());
|
|
|
|
|
|
|
|
$package->setTargetDir('./../foo/');
|
|
|
|
$this->assertEquals('foo/', $package->getTargetDir());
|
|
|
|
|
|
|
|
$package->setTargetDir('foo/../../../bar/');
|
|
|
|
$this->assertEquals('foo/bar/', $package->getTargetDir());
|
|
|
|
|
|
|
|
$package->setTargetDir('../..');
|
|
|
|
$this->assertEquals('', $package->getTargetDir());
|
2012-09-18 16:32:24 +00:00
|
|
|
|
|
|
|
$package->setTargetDir('..');
|
|
|
|
$this->assertEquals('', $package->getTargetDir());
|
|
|
|
|
|
|
|
$package->setTargetDir('/..');
|
|
|
|
$this->assertEquals('', $package->getTargetDir());
|
|
|
|
|
|
|
|
$package->setTargetDir('/foo/..');
|
|
|
|
$this->assertEquals('foo/', $package->getTargetDir());
|
2012-09-19 09:25:49 +00:00
|
|
|
|
|
|
|
$package->setTargetDir('/foo/..//bar');
|
|
|
|
$this->assertEquals('foo/bar', $package->getTargetDir());
|
2012-09-18 16:30:11 +00:00
|
|
|
}
|
2011-04-05 15:37:19 +00:00
|
|
|
}
|