mirror of
https://github.com/composer/composer
synced 2025-05-09 00:22:53 +00:00
Add more types
This commit is contained in:
parent
e52071a92c
commit
7abc8da7d3
71 changed files with 807 additions and 850 deletions
|
@ -20,7 +20,7 @@ class InitCommandTest extends TestCase
|
|||
public function testParseValidAuthorString(): void
|
||||
{
|
||||
$command = new InitCommand;
|
||||
$author = $command->parseAuthorString('John Smith <john@example.com>');
|
||||
$author = $this->callParseAuthorString($command, 'John Smith <john@example.com>');
|
||||
$this->assertEquals('John Smith', $author['name']);
|
||||
$this->assertEquals('john@example.com', $author['email']);
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ class InitCommandTest extends TestCase
|
|||
public function testParseValidAuthorStringWithoutEmail(): void
|
||||
{
|
||||
$command = new InitCommand;
|
||||
$author = $command->parseAuthorString('John Smith');
|
||||
$author = $this->callParseAuthorString($command, 'John Smith');
|
||||
$this->assertEquals('John Smith', $author['name']);
|
||||
$this->assertNull($author['email']);
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ class InitCommandTest extends TestCase
|
|||
public function testParseValidUtf8AuthorString(): void
|
||||
{
|
||||
$command = new InitCommand;
|
||||
$author = $command->parseAuthorString('Matti Meikäläinen <matti@example.com>');
|
||||
$author = $this->callParseAuthorString($command, 'Matti Meikäläinen <matti@example.com>');
|
||||
$this->assertEquals('Matti Meikäläinen', $author['name']);
|
||||
$this->assertEquals('matti@example.com', $author['email']);
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ class InitCommandTest extends TestCase
|
|||
// \xCC\x88 is UTF-8 for U+0308 diaeresis (umlaut) combining mark
|
||||
$utf8_expected = "Matti Meika\xCC\x88la\xCC\x88inen";
|
||||
$command = new InitCommand;
|
||||
$author = $command->parseAuthorString($utf8_expected." <matti@example.com>");
|
||||
$author = $this->callParseAuthorString($command, $utf8_expected." <matti@example.com>");
|
||||
$this->assertEquals($utf8_expected, $author['name']);
|
||||
$this->assertEquals('matti@example.com', $author['email']);
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ class InitCommandTest extends TestCase
|
|||
public function testParseNumericAuthorString(): void
|
||||
{
|
||||
$command = new InitCommand;
|
||||
$author = $command->parseAuthorString('h4x0r <h4x@example.com>');
|
||||
$author = $this->callParseAuthorString($command, 'h4x0r <h4x@example.com>');
|
||||
$this->assertEquals('h4x0r', $author['name']);
|
||||
$this->assertEquals('h4x@example.com', $author['email']);
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ class InitCommandTest extends TestCase
|
|||
public function testParseValidAlias1AuthorString(): void
|
||||
{
|
||||
$command = new InitCommand;
|
||||
$author = $command->parseAuthorString(
|
||||
$author = $this->callParseAuthorString($command,
|
||||
'Johnathon "Johnny" Smith <john@example.com>'
|
||||
);
|
||||
$this->assertEquals('Johnathon "Johnny" Smith', $author['name']);
|
||||
|
@ -80,7 +80,7 @@ class InitCommandTest extends TestCase
|
|||
public function testParseValidAlias2AuthorString(): void
|
||||
{
|
||||
$command = new InitCommand;
|
||||
$author = $command->parseAuthorString(
|
||||
$author = $this->callParseAuthorString($command,
|
||||
'Johnathon (Johnny) Smith <john@example.com>'
|
||||
);
|
||||
$this->assertEquals('Johnathon (Johnny) Smith', $author['name']);
|
||||
|
@ -91,14 +91,14 @@ class InitCommandTest extends TestCase
|
|||
{
|
||||
$command = new InitCommand;
|
||||
self::expectException('InvalidArgumentException');
|
||||
$command->parseAuthorString('');
|
||||
$this->callParseAuthorString($command, '');
|
||||
}
|
||||
|
||||
public function testParseAuthorStringWithInvalidEmail(): void
|
||||
{
|
||||
$command = new InitCommand;
|
||||
self::expectException('InvalidArgumentException');
|
||||
$command->parseAuthorString('John Smith <john>');
|
||||
$this->callParseAuthorString($command, 'John Smith <john>');
|
||||
}
|
||||
|
||||
public function testNamespaceFromValidPackageName(): void
|
||||
|
@ -121,4 +121,15 @@ class InitCommandTest extends TestCase
|
|||
$namespace = $command->namespaceFromPackageName('');
|
||||
$this->assertNull($namespace);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue