2022-02-23 15:58:18 +00:00
|
|
|
<?php declare(strict_types=1);
|
2013-05-25 15:56:02 +00:00
|
|
|
|
2013-05-27 08:41:50 +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.
|
|
|
|
*/
|
|
|
|
|
2013-05-26 11:44:26 +00:00
|
|
|
namespace Composer\Test\Command;
|
2013-05-25 15:56:02 +00:00
|
|
|
|
|
|
|
use Composer\Command\InitCommand;
|
2022-10-13 08:39:51 +00:00
|
|
|
use Composer\Json\JsonFile;
|
2018-11-12 14:23:32 +00:00
|
|
|
use Composer\Test\TestCase;
|
2022-10-13 08:39:51 +00:00
|
|
|
use Symfony\Component\Console\Tester\ApplicationTester;
|
2013-05-25 15:56:02 +00:00
|
|
|
|
|
|
|
class InitCommandTest extends TestCase
|
|
|
|
{
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testParseValidAuthorString(): void
|
2013-05-25 15:56:02 +00:00
|
|
|
{
|
|
|
|
$command = new InitCommand;
|
2022-02-22 21:10:52 +00:00
|
|
|
$author = $this->callParseAuthorString($command, 'John Smith <john@example.com>');
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals('John Smith', $author['name']);
|
|
|
|
self::assertEquals('john@example.com', $author['email']);
|
2013-05-25 15:56:02 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testParseValidAuthorStringWithoutEmail(): void
|
2022-02-16 12:24:15 +00:00
|
|
|
{
|
|
|
|
$command = new InitCommand;
|
2022-02-22 21:10:52 +00:00
|
|
|
$author = $this->callParseAuthorString($command, 'John Smith');
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals('John Smith', $author['name']);
|
|
|
|
self::assertNull($author['email']);
|
2022-02-16 12:24:15 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testParseValidUtf8AuthorString(): void
|
2013-07-25 20:40:41 +00:00
|
|
|
{
|
|
|
|
$command = new InitCommand;
|
2022-02-22 21:10:52 +00:00
|
|
|
$author = $this->callParseAuthorString($command, 'Matti Meikäläinen <matti@example.com>');
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals('Matti Meikäläinen', $author['name']);
|
|
|
|
self::assertEquals('matti@example.com', $author['email']);
|
2013-07-25 20:40:41 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testParseValidUtf8AuthorStringWithNonSpacingMarks(): void
|
2017-03-16 00:43:54 +00:00
|
|
|
{
|
|
|
|
// \xCC\x88 is UTF-8 for U+0308 diaeresis (umlaut) combining mark
|
|
|
|
$utf8_expected = "Matti Meika\xCC\x88la\xCC\x88inen";
|
|
|
|
$command = new InitCommand;
|
2022-02-22 21:10:52 +00:00
|
|
|
$author = $this->callParseAuthorString($command, $utf8_expected." <matti@example.com>");
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals($utf8_expected, $author['name']);
|
|
|
|
self::assertEquals('matti@example.com', $author['email']);
|
2017-03-16 00:43:54 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testParseNumericAuthorString(): void
|
2015-04-20 11:09:18 +00:00
|
|
|
{
|
|
|
|
$command = new InitCommand;
|
2022-02-22 21:10:52 +00:00
|
|
|
$author = $this->callParseAuthorString($command, 'h4x0r <h4x@example.com>');
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals('h4x0r', $author['name']);
|
|
|
|
self::assertEquals('h4x@example.com', $author['email']);
|
2015-04-20 11:09:18 +00:00
|
|
|
}
|
2017-03-08 14:07:29 +00:00
|
|
|
|
2016-08-31 06:29:22 +00:00
|
|
|
/**
|
|
|
|
* Test scenario for issue #5631
|
|
|
|
* @link https://github.com/composer/composer/issues/5631 Issue #5631
|
|
|
|
*/
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testParseValidAlias1AuthorString(): void
|
2016-08-31 06:29:22 +00:00
|
|
|
{
|
2017-03-08 14:07:29 +00:00
|
|
|
$command = new InitCommand;
|
2022-02-23 13:09:49 +00:00
|
|
|
$author = $this->callParseAuthorString(
|
|
|
|
$command,
|
2020-11-22 13:48:56 +00:00
|
|
|
'Johnathon "Johnny" Smith <john@example.com>'
|
2018-07-24 12:32:52 +00:00
|
|
|
);
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals('Johnathon "Johnny" Smith', $author['name']);
|
|
|
|
self::assertEquals('john@example.com', $author['email']);
|
2016-08-31 06:29:22 +00:00
|
|
|
}
|
2017-03-08 14:07:29 +00:00
|
|
|
|
2016-08-31 06:29:22 +00:00
|
|
|
/**
|
|
|
|
* Test scenario for issue #5631
|
|
|
|
* @link https://github.com/composer/composer/issues/5631 Issue #5631
|
|
|
|
*/
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testParseValidAlias2AuthorString(): void
|
2016-08-31 06:29:22 +00:00
|
|
|
{
|
2017-03-08 14:07:29 +00:00
|
|
|
$command = new InitCommand;
|
2022-02-23 13:09:49 +00:00
|
|
|
$author = $this->callParseAuthorString(
|
|
|
|
$command,
|
2020-11-22 13:48:56 +00:00
|
|
|
'Johnathon (Johnny) Smith <john@example.com>'
|
2018-07-24 12:32:52 +00:00
|
|
|
);
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals('Johnathon (Johnny) Smith', $author['name']);
|
|
|
|
self::assertEquals('john@example.com', $author['email']);
|
2016-08-31 06:29:22 +00:00
|
|
|
}
|
2015-04-20 11:09:18 +00:00
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testParseEmptyAuthorString(): void
|
2013-05-25 15:56:02 +00:00
|
|
|
{
|
|
|
|
$command = new InitCommand;
|
2021-12-09 19:55:26 +00:00
|
|
|
self::expectException('InvalidArgumentException');
|
2022-02-22 21:10:52 +00:00
|
|
|
$this->callParseAuthorString($command, '');
|
2013-05-25 15:56:02 +00:00
|
|
|
}
|
2013-05-25 16:01:14 +00:00
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testParseAuthorStringWithInvalidEmail(): void
|
2013-05-25 16:01:14 +00:00
|
|
|
{
|
|
|
|
$command = new InitCommand;
|
2021-12-09 19:55:26 +00:00
|
|
|
self::expectException('InvalidArgumentException');
|
2022-02-22 21:10:52 +00:00
|
|
|
$this->callParseAuthorString($command, 'John Smith <john>');
|
2013-05-25 16:01:14 +00:00
|
|
|
}
|
2021-04-20 19:58:38 +00:00
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testNamespaceFromValidPackageName(): void
|
2021-04-20 19:58:38 +00:00
|
|
|
{
|
|
|
|
$command = new InitCommand;
|
|
|
|
$namespace = $command->namespaceFromPackageName('new_projects.acme-extra/package-name');
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals('NewProjectsAcmeExtra\PackageName', $namespace);
|
2021-04-20 19:58:38 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testNamespaceFromInvalidPackageName(): void
|
2021-04-20 19:58:38 +00:00
|
|
|
{
|
|
|
|
$command = new InitCommand;
|
|
|
|
$namespace = $command->namespaceFromPackageName('invalid-package-name');
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertNull($namespace);
|
2021-04-20 19:58:38 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testNamespaceFromMissingPackageName(): void
|
2021-04-20 19:58:38 +00:00
|
|
|
{
|
|
|
|
$command = new InitCommand;
|
2021-08-21 15:41:52 +00:00
|
|
|
$namespace = $command->namespaceFromPackageName('');
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertNull($namespace);
|
2021-04-20 19:58:38 +00:00
|
|
|
}
|
2022-02-22 21:10:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array{name: string, email: string|null}
|
|
|
|
*/
|
|
|
|
private function callParseAuthorString(InitCommand $command, string $string): array
|
|
|
|
{
|
|
|
|
$reflMethod = new \ReflectionMethod($command, 'parseAuthorString');
|
|
|
|
$reflMethod->setAccessible(true);
|
|
|
|
|
|
|
|
return $reflMethod->invoke($command, $string);
|
|
|
|
}
|
2022-10-13 08:39:51 +00:00
|
|
|
|
|
|
|
public function testRunNoInteraction(): void
|
|
|
|
{
|
|
|
|
$this->expectException(\RuntimeException::class);
|
|
|
|
$dir = $this->initTempComposer();
|
|
|
|
unlink($dir . '/composer.json');
|
|
|
|
unlink($dir . '/auth.json');
|
|
|
|
|
|
|
|
$appTester = $this->getApplicationTester();
|
|
|
|
$appTester->run(['command' => 'init', '--no-interaction' => true]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRunInvalidNameArgument(): void
|
|
|
|
{
|
|
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
|
|
$dir = $this->initTempComposer();
|
|
|
|
unlink($dir . '/composer.json');
|
|
|
|
unlink($dir . '/auth.json');
|
|
|
|
|
|
|
|
$appTester = $this->getApplicationTester();
|
|
|
|
$appTester->run(['command' => 'init', '--no-interaction' => true, '--name' => 'test']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRunNameArgument(): void
|
|
|
|
{
|
|
|
|
$dir = $this->initTempComposer();
|
|
|
|
unlink($dir . '/composer.json');
|
|
|
|
unlink($dir . '/auth.json');
|
|
|
|
|
|
|
|
$appTester = $this->getApplicationTester();
|
|
|
|
$appTester->run(['command' => 'init', '--no-interaction' => true, '--name' => 'test/pkg']);
|
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame(0, $appTester->getStatusCode());
|
2022-10-13 08:39:51 +00:00
|
|
|
|
|
|
|
$expected = [
|
|
|
|
'name' => 'test/pkg',
|
|
|
|
'require' => [],
|
|
|
|
];
|
|
|
|
|
|
|
|
$file = new JsonFile($dir . '/composer.json');
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals($expected, $file->read());
|
2022-10-13 08:39:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRunInvalidAuthorArgumentInvalidEmail(): void
|
|
|
|
{
|
|
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
|
|
|
|
|
|
$dir = $this->initTempComposer();
|
|
|
|
unlink($dir . '/composer.json');
|
|
|
|
unlink($dir . '/auth.json');
|
|
|
|
|
|
|
|
$appTester = $this->getApplicationTester();
|
|
|
|
$appTester->run([
|
|
|
|
'command' => 'init',
|
|
|
|
'--no-interaction' => true,
|
|
|
|
'--name' => 'test/pkg',
|
|
|
|
'--author' => 'Mr. Test <test>',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRunAuthorArgument(): void
|
|
|
|
{
|
|
|
|
$dir = $this->initTempComposer();
|
|
|
|
unlink($dir . '/composer.json');
|
|
|
|
unlink($dir . '/auth.json');
|
|
|
|
|
|
|
|
$appTester = $this->getApplicationTester();
|
|
|
|
$appTester->run([
|
|
|
|
'command' => 'init',
|
|
|
|
'--no-interaction' => true,
|
|
|
|
'--name' => 'test/pkg',
|
|
|
|
'--author' => 'Mr. Test <test@example.org>',
|
|
|
|
]);
|
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame(0, $appTester->getStatusCode());
|
2022-10-13 08:39:51 +00:00
|
|
|
|
|
|
|
$expected = [
|
|
|
|
'name' => 'test/pkg',
|
|
|
|
'require' => [],
|
|
|
|
'authors' => [
|
|
|
|
[
|
|
|
|
'name' => 'Mr. Test',
|
|
|
|
'email' => 'test@example.org',
|
|
|
|
]
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
$file = new JsonFile($dir . '/composer.json');
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals($expected, $file->read());
|
2022-10-13 08:39:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRunAuthorArgumentMissingEmail(): void
|
|
|
|
{
|
|
|
|
$dir = $this->initTempComposer();
|
|
|
|
unlink($dir . '/composer.json');
|
|
|
|
unlink($dir . '/auth.json');
|
|
|
|
|
|
|
|
$appTester = $this->getApplicationTester();
|
|
|
|
$appTester->run([
|
|
|
|
'command' => 'init',
|
|
|
|
'--no-interaction' => true,
|
|
|
|
'--name' => 'test/pkg',
|
|
|
|
'--author' => 'Mr. Test',
|
|
|
|
]);
|
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame(0, $appTester->getStatusCode());
|
2022-10-13 08:39:51 +00:00
|
|
|
|
|
|
|
$expected = [
|
|
|
|
'name' => 'test/pkg',
|
|
|
|
'require' => [],
|
|
|
|
'authors' => [
|
|
|
|
[
|
|
|
|
'name' => 'Mr. Test',
|
|
|
|
]
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
$file = new JsonFile($dir . '/composer.json');
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals($expected, $file->read());
|
2022-10-13 08:39:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRunSingleRepositoryArgument(): void
|
|
|
|
{
|
|
|
|
$dir = $this->initTempComposer();
|
|
|
|
unlink($dir . '/composer.json');
|
|
|
|
unlink($dir . '/auth.json');
|
|
|
|
|
|
|
|
$appTester = $this->getApplicationTester();
|
|
|
|
$appTester->run([
|
|
|
|
'command' => 'init',
|
|
|
|
'--no-interaction' => true,
|
|
|
|
'--name' => 'test/pkg',
|
|
|
|
'--repository' => [
|
|
|
|
'{"type":"vcs","url":"http://packages.example.com"}'
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame(0, $appTester->getStatusCode());
|
2022-10-13 08:39:51 +00:00
|
|
|
|
|
|
|
$expected = [
|
|
|
|
'name' => 'test/pkg',
|
|
|
|
'require' => [],
|
|
|
|
'repositories' => [
|
|
|
|
[
|
|
|
|
'type' => 'vcs',
|
|
|
|
'url' => 'http://packages.example.com'
|
|
|
|
]
|
|
|
|
]
|
|
|
|
];
|
|
|
|
|
|
|
|
$file = new JsonFile($dir . '/composer.json');
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals($expected, $file->read());
|
2022-10-13 08:39:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRunMultipleRepositoryArguments(): void
|
|
|
|
{
|
|
|
|
$dir = $this->initTempComposer();
|
|
|
|
unlink($dir . '/composer.json');
|
|
|
|
unlink($dir . '/auth.json');
|
|
|
|
|
|
|
|
$appTester = $this->getApplicationTester();
|
|
|
|
$appTester->run([
|
|
|
|
'command' => 'init',
|
|
|
|
'--no-interaction' => true,
|
|
|
|
'--name' => 'test/pkg',
|
|
|
|
'--repository' => [
|
|
|
|
'{"type":"vcs","url":"http://vcs.example.com"}',
|
|
|
|
'{"type":"composer","url":"http://composer.example.com"}',
|
|
|
|
'{"type":"composer","url":"http://composer2.example.com","options":{"ssl":{"verify_peer":"true"}}}',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame(0, $appTester->getStatusCode());
|
2022-10-13 08:39:51 +00:00
|
|
|
|
|
|
|
$expected = [
|
|
|
|
'name' => 'test/pkg',
|
|
|
|
'require' => [],
|
|
|
|
'repositories' => [
|
|
|
|
[
|
|
|
|
'type' => 'vcs',
|
|
|
|
'url' => 'http://vcs.example.com'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'type' => 'composer',
|
|
|
|
'url' => 'http://composer.example.com'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'type' => 'composer',
|
|
|
|
'url' => 'http://composer2.example.com',
|
|
|
|
'options' => [
|
|
|
|
'ssl' => [
|
|
|
|
'verify_peer' => 'true'
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
];
|
|
|
|
|
|
|
|
$file = new JsonFile($dir . '/composer.json');
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals($expected, $file->read());
|
2022-10-13 08:39:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRunStability(): void
|
|
|
|
{
|
|
|
|
$dir = $this->initTempComposer();
|
|
|
|
unlink($dir . '/composer.json');
|
|
|
|
unlink($dir . '/auth.json');
|
|
|
|
|
|
|
|
$appTester = $this->getApplicationTester();
|
|
|
|
$appTester->run([
|
|
|
|
'command' => 'init',
|
|
|
|
'--no-interaction' => true,
|
|
|
|
'--name' => 'test/pkg',
|
|
|
|
'--stability' => 'dev',
|
|
|
|
]);
|
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame(0, $appTester->getStatusCode());
|
2022-10-13 08:39:51 +00:00
|
|
|
|
|
|
|
$expected = [
|
|
|
|
'name' => 'test/pkg',
|
|
|
|
'require' => [],
|
|
|
|
'minimum-stability' => 'dev',
|
|
|
|
];
|
|
|
|
|
|
|
|
$file = new JsonFile($dir . '/composer.json');
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals($expected, $file->read());
|
2022-10-13 08:39:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRunInvalidStability(): void
|
|
|
|
{
|
|
|
|
$dir = $this->initTempComposer();
|
|
|
|
unlink($dir . '/composer.json');
|
|
|
|
unlink($dir . '/auth.json');
|
|
|
|
|
|
|
|
$appTester = $this->getApplicationTester();
|
|
|
|
$appTester->run([
|
|
|
|
'command' => 'init',
|
|
|
|
'--no-interaction' => true,
|
|
|
|
'--name' => 'test/pkg',
|
|
|
|
'--stability' => 'bogus',
|
|
|
|
], ['capture_stderr_separately' => true]);
|
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame(1, $appTester->getStatusCode());
|
2022-10-13 08:39:51 +00:00
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertMatchesRegularExpression("/minimum-stability\s+:\s+Does not have a value in the enumeration/", $appTester->getErrorOutput());
|
2022-10-13 08:39:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRunRequireOne(): void
|
|
|
|
{
|
|
|
|
$dir = $this->initTempComposer();
|
|
|
|
unlink($dir . '/composer.json');
|
|
|
|
unlink($dir . '/auth.json');
|
|
|
|
|
|
|
|
$appTester = $this->getApplicationTester();
|
|
|
|
$appTester->run([
|
|
|
|
'command' => 'init',
|
|
|
|
'--no-interaction' => true,
|
|
|
|
'--name' => 'test/pkg',
|
|
|
|
'--require' => [
|
|
|
|
'first/pkg:1.0.0'
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame(0, $appTester->getStatusCode());
|
2022-10-13 08:39:51 +00:00
|
|
|
|
|
|
|
$expected = [
|
|
|
|
'name' => 'test/pkg',
|
|
|
|
'require' => [
|
|
|
|
'first/pkg' => '1.0.0'
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
$file = new JsonFile($dir . '/composer.json');
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals($expected, $file->read());
|
2022-10-13 08:39:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRunRequireMultiple(): void
|
|
|
|
{
|
|
|
|
$dir = $this->initTempComposer();
|
|
|
|
unlink($dir . '/composer.json');
|
|
|
|
unlink($dir . '/auth.json');
|
|
|
|
|
|
|
|
$appTester = $this->getApplicationTester();
|
|
|
|
$appTester->run([
|
|
|
|
'command' => 'init',
|
|
|
|
'--no-interaction' => true,
|
|
|
|
'--name' => 'test/pkg',
|
|
|
|
'--require' => [
|
|
|
|
'first/pkg:1.0.0',
|
|
|
|
'second/pkg:^3.4'
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame(0, $appTester->getStatusCode());
|
2022-10-13 08:39:51 +00:00
|
|
|
|
|
|
|
$expected = [
|
|
|
|
'name' => 'test/pkg',
|
|
|
|
'require' => [
|
|
|
|
'first/pkg' => '1.0.0',
|
|
|
|
'second/pkg' => '^3.4',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
$file = new JsonFile($dir . '/composer.json');
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals($expected, $file->read());
|
2022-10-13 08:39:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRunInvalidRequire(): void
|
|
|
|
{
|
|
|
|
$this->expectException(\UnexpectedValueException::class);
|
|
|
|
$this->expectExceptionMessage("Option first is missing a version constraint, use e.g. first:^1.0");
|
|
|
|
|
|
|
|
$dir = $this->initTempComposer();
|
|
|
|
unlink($dir . '/composer.json');
|
|
|
|
unlink($dir . '/auth.json');
|
|
|
|
|
|
|
|
$appTester = $this->getApplicationTester();
|
|
|
|
$appTester->run([
|
|
|
|
'command' => 'init',
|
|
|
|
'--no-interaction' => true,
|
|
|
|
'--name' => 'test/pkg',
|
|
|
|
'--require' => [
|
|
|
|
'first',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRunRequireDevOne(): void
|
|
|
|
{
|
|
|
|
$dir = $this->initTempComposer();
|
|
|
|
unlink($dir . '/composer.json');
|
|
|
|
unlink($dir . '/auth.json');
|
|
|
|
|
|
|
|
$appTester = $this->getApplicationTester();
|
|
|
|
$appTester->run([
|
|
|
|
'command' => 'init',
|
|
|
|
'--no-interaction' => true,
|
|
|
|
'--name' => 'test/pkg',
|
|
|
|
'--require-dev' => [
|
|
|
|
'first/pkg:1.0.0'
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame(0, $appTester->getStatusCode());
|
2022-10-13 08:39:51 +00:00
|
|
|
|
|
|
|
$expected = [
|
|
|
|
'name' => 'test/pkg',
|
|
|
|
'require' => [],
|
|
|
|
'require-dev' => [
|
|
|
|
'first/pkg' => '1.0.0'
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
$file = new JsonFile($dir . '/composer.json');
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals($expected, $file->read());
|
2022-10-13 08:39:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRunRequireDevMultiple(): void
|
|
|
|
{
|
|
|
|
$dir = $this->initTempComposer();
|
|
|
|
unlink($dir . '/composer.json');
|
|
|
|
unlink($dir . '/auth.json');
|
|
|
|
|
|
|
|
$appTester = $this->getApplicationTester();
|
|
|
|
$appTester->run([
|
|
|
|
'command' => 'init',
|
|
|
|
'--no-interaction' => true,
|
|
|
|
'--name' => 'test/pkg',
|
|
|
|
'--require-dev' => [
|
|
|
|
'first/pkg:1.0.0',
|
|
|
|
'second/pkg:^3.4'
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame(0, $appTester->getStatusCode());
|
2022-10-13 08:39:51 +00:00
|
|
|
|
|
|
|
$expected = [
|
|
|
|
'name' => 'test/pkg',
|
|
|
|
'require' => [],
|
|
|
|
'require-dev' => [
|
|
|
|
'first/pkg' => '1.0.0',
|
|
|
|
'second/pkg' => '^3.4',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
$file = new JsonFile($dir . '/composer.json');
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals($expected, $file->read());
|
2022-10-13 08:39:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRunInvalidRequireDev(): void
|
|
|
|
{
|
|
|
|
$this->expectException(\UnexpectedValueException::class);
|
|
|
|
$this->expectExceptionMessage("Option first is missing a version constraint, use e.g. first:^1.0");
|
|
|
|
|
|
|
|
$dir = $this->initTempComposer();
|
|
|
|
unlink($dir . '/composer.json');
|
|
|
|
unlink($dir . '/auth.json');
|
|
|
|
|
|
|
|
$appTester = $this->getApplicationTester();
|
|
|
|
$appTester->run([
|
|
|
|
'command' => 'init',
|
|
|
|
'--no-interaction' => true,
|
|
|
|
'--name' => 'test/pkg',
|
|
|
|
'--require-dev' => [
|
|
|
|
'first',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRunAutoload(): void
|
|
|
|
{
|
|
|
|
$dir = $this->initTempComposer();
|
|
|
|
unlink($dir . '/composer.json');
|
|
|
|
unlink($dir . '/auth.json');
|
|
|
|
|
|
|
|
$appTester = $this->getApplicationTester();
|
|
|
|
$appTester->run([
|
|
|
|
'command' => 'init',
|
|
|
|
'--no-interaction' => true,
|
|
|
|
'--name' => 'test/pkg',
|
|
|
|
'--autoload' => 'testMapping/'
|
|
|
|
]);
|
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame(0, $appTester->getStatusCode());
|
2022-10-13 08:39:51 +00:00
|
|
|
|
|
|
|
$expected = [
|
|
|
|
'name' => 'test/pkg',
|
|
|
|
'require' => [],
|
|
|
|
'autoload' => [
|
|
|
|
'psr-4' => [
|
|
|
|
'Test\\Pkg\\' => 'testMapping/',
|
|
|
|
]
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
$file = new JsonFile($dir . '/composer.json');
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals($expected, $file->read());
|
2022-10-13 08:39:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRunHomepage(): void
|
|
|
|
{
|
|
|
|
$dir = $this->initTempComposer();
|
|
|
|
unlink($dir . '/composer.json');
|
|
|
|
unlink($dir . '/auth.json');
|
|
|
|
|
|
|
|
$appTester = $this->getApplicationTester();
|
|
|
|
$appTester->run([
|
|
|
|
'command' => 'init',
|
|
|
|
'--no-interaction' => true,
|
|
|
|
'--name' => 'test/pkg',
|
|
|
|
'--homepage' => 'https://example.org/'
|
|
|
|
]);
|
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame(0, $appTester->getStatusCode());
|
2022-10-13 08:39:51 +00:00
|
|
|
|
|
|
|
$expected = [
|
|
|
|
'name' => 'test/pkg',
|
|
|
|
'require' => [],
|
|
|
|
'homepage' => 'https://example.org/'
|
|
|
|
];
|
|
|
|
|
|
|
|
$file = new JsonFile($dir . '/composer.json');
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals($expected, $file->read());
|
2022-10-13 08:39:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRunInvalidHomepage(): void
|
|
|
|
{
|
|
|
|
$dir = $this->initTempComposer();
|
|
|
|
unlink($dir . '/composer.json');
|
|
|
|
unlink($dir . '/auth.json');
|
|
|
|
|
|
|
|
$appTester = $this->getApplicationTester();
|
|
|
|
$appTester->run([
|
|
|
|
'command' => 'init',
|
|
|
|
'--no-interaction' => true,
|
|
|
|
'--name' => 'test/pkg',
|
|
|
|
'--homepage' => 'not-a-url',
|
|
|
|
], ['capture_stderr_separately' => true]);
|
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame(1, $appTester->getStatusCode());
|
|
|
|
self::assertMatchesRegularExpression("/homepage\s*:\s*Invalid URL format/", $appTester->getErrorOutput());
|
2022-10-13 08:39:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRunDescription(): void
|
|
|
|
{
|
|
|
|
$dir = $this->initTempComposer();
|
|
|
|
unlink($dir . '/composer.json');
|
|
|
|
unlink($dir . '/auth.json');
|
|
|
|
|
|
|
|
$appTester = $this->getApplicationTester();
|
|
|
|
$appTester->run([
|
|
|
|
'command' => 'init',
|
|
|
|
'--no-interaction' => true,
|
|
|
|
'--name' => 'test/pkg',
|
|
|
|
'--description' => 'My first example package'
|
|
|
|
]);
|
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame(0, $appTester->getStatusCode());
|
2022-10-13 08:39:51 +00:00
|
|
|
|
|
|
|
$expected = [
|
|
|
|
'name' => 'test/pkg',
|
|
|
|
'require' => [],
|
|
|
|
'description' => 'My first example package'
|
|
|
|
];
|
|
|
|
|
|
|
|
$file = new JsonFile($dir . '/composer.json');
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals($expected, $file->read());
|
2022-10-13 08:39:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRunType(): void
|
|
|
|
{
|
|
|
|
$dir = $this->initTempComposer();
|
|
|
|
unlink($dir . '/composer.json');
|
|
|
|
unlink($dir . '/auth.json');
|
|
|
|
|
|
|
|
$appTester = $this->getApplicationTester();
|
|
|
|
$appTester->run([
|
|
|
|
'command' => 'init',
|
|
|
|
'--no-interaction' => true,
|
|
|
|
'--name' => 'test/pkg',
|
|
|
|
'--type' => 'library'
|
|
|
|
]);
|
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame(0, $appTester->getStatusCode());
|
2022-10-13 08:39:51 +00:00
|
|
|
|
|
|
|
$expected = [
|
|
|
|
'name' => 'test/pkg',
|
|
|
|
'require' => [],
|
|
|
|
'type' => 'library'
|
|
|
|
];
|
|
|
|
|
|
|
|
$file = new JsonFile($dir . '/composer.json');
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals($expected, $file->read());
|
2022-10-13 08:39:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRunLicense(): void
|
|
|
|
{
|
|
|
|
$dir = $this->initTempComposer();
|
|
|
|
unlink($dir . '/composer.json');
|
|
|
|
unlink($dir . '/auth.json');
|
|
|
|
|
|
|
|
$appTester = $this->getApplicationTester();
|
|
|
|
$appTester->run([
|
|
|
|
'command' => 'init',
|
|
|
|
'--no-interaction' => true,
|
|
|
|
'--name' => 'test/pkg',
|
|
|
|
'--license' => 'MIT'
|
|
|
|
]);
|
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame(0, $appTester->getStatusCode());
|
2022-10-13 08:39:51 +00:00
|
|
|
|
|
|
|
$expected = [
|
|
|
|
'name' => 'test/pkg',
|
|
|
|
'require' => [],
|
|
|
|
'license' => 'MIT'
|
|
|
|
];
|
|
|
|
|
|
|
|
$file = new JsonFile($dir . '/composer.json');
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals($expected, $file->read());
|
2022-10-13 08:39:51 +00:00
|
|
|
}
|
2013-05-25 15:56:02 +00:00
|
|
|
}
|