1
0
Fork 0
composer/tests/Composer/Test/Command/InitCommandTest.php

94 lines
3.1 KiB
PHP
Raw Normal View History

2013-05-25 15:56:02 +00:00
<?php
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;
2013-09-25 08:14:42 +00:00
use Composer\TestCase;
2013-05-25 15:56:02 +00:00
class InitCommandTest extends TestCase
{
2013-06-13 11:28:24 +00:00
public function testParseValidAuthorString()
2013-05-25 15:56:02 +00:00
{
$command = new InitCommand;
2013-05-26 14:10:17 +00:00
$author = $command->parseAuthorString('John Smith <john@example.com>');
$this->assertEquals('John Smith', $author['name']);
$this->assertEquals('john@example.com', $author['email']);
2013-05-25 15:56:02 +00:00
}
public function testParseValidUtf8AuthorString()
{
$command = new InitCommand;
$author = $command->parseAuthorString('Matti Meikäläinen <matti@example.com>');
$this->assertEquals('Matti Meikäläinen', $author['name']);
$this->assertEquals('matti@example.com', $author['email']);
}
public function testParseValidUtf8AuthorStringWithNonSpacingMarks()
{
// \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>");
$this->assertEquals($utf8_expected, $author['name']);
$this->assertEquals('matti@example.com', $author['email']);
}
2015-04-20 11:09:18 +00:00
public function testParseNumericAuthorString()
{
$command = new InitCommand;
$author = $command->parseAuthorString('h4x0r <h4x@example.com>');
$this->assertEquals('h4x0r', $author['name']);
$this->assertEquals('h4x@example.com', $author['email']);
}
2017-03-08 14:07:29 +00:00
/**
* Test scenario for issue #5631
* @link https://github.com/composer/composer/issues/5631 Issue #5631
*/
public function testParseValidAlias1AuthorString()
{
2017-03-08 14:07:29 +00:00
$command = new InitCommand;
$author = $command->parseAuthorString(
'Johnathon "Johnny" Smith <john@example.com>');
2017-03-08 14:07:29 +00:00
$this->assertEquals('Johnathon "Johnny" Smith', $author['name']);
$this->assertEquals('john@example.com', $author['email']);
}
2017-03-08 14:07:29 +00:00
/**
* Test scenario for issue #5631
* @link https://github.com/composer/composer/issues/5631 Issue #5631
*/
public function testParseValidAlias2AuthorString()
{
2017-03-08 14:07:29 +00:00
$command = new InitCommand;
$author = $command->parseAuthorString(
'Johnathon (Johnny) Smith <john@example.com>');
2017-03-08 14:07:29 +00:00
$this->assertEquals('Johnathon (Johnny) Smith', $author['name']);
$this->assertEquals('john@example.com', $author['email']);
}
2015-04-20 11:09:18 +00:00
2013-06-13 11:28:24 +00:00
public function testParseEmptyAuthorString()
2013-05-25 15:56:02 +00:00
{
$command = new InitCommand;
$this->setExpectedException('InvalidArgumentException');
$command->parseAuthorString('');
}
2013-05-25 16:01:14 +00:00
2013-06-13 11:28:24 +00:00
public function testParseAuthorStringWithInvalidEmail()
2013-05-25 16:01:14 +00:00
{
$command = new InitCommand;
$this->setExpectedException('InvalidArgumentException');
$command->parseAuthorString('John Smith <john>');
}
2013-05-25 15:56:02 +00:00
}