InitCommandTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Test\Command;
  12. use Composer\Command\InitCommand;
  13. use Composer\TestCase;
  14. class InitCommandTest extends TestCase
  15. {
  16. public function testParseValidAuthorString()
  17. {
  18. $command = new InitCommand;
  19. $author = $command->parseAuthorString('John Smith <john@example.com>');
  20. $this->assertEquals('John Smith', $author['name']);
  21. $this->assertEquals('john@example.com', $author['email']);
  22. }
  23. public function testParseValidUtf8AuthorString()
  24. {
  25. $command = new InitCommand;
  26. $author = $command->parseAuthorString('Matti Meikäläinen <matti@example.com>');
  27. $this->assertEquals('Matti Meikäläinen', $author['name']);
  28. $this->assertEquals('matti@example.com', $author['email']);
  29. }
  30. public function testParseNumericAuthorString()
  31. {
  32. $command = new InitCommand;
  33. $author = $command->parseAuthorString('h4x0r <h4x@example.com>');
  34. $this->assertEquals('h4x0r', $author['name']);
  35. $this->assertEquals('h4x@example.com', $author['email']);
  36. }
  37. /**
  38. * Test scenario for issue #5631
  39. * @link https://github.com/composer/composer/issues/5631 Issue #5631
  40. */
  41. public function testParseValidAlias1AuthorString()
  42. {
  43. $command = new InitCommand;
  44. $author = $command->parseAuthorString(
  45. 'Johnathon "Johnny" Smith <john@example.com>');
  46. $this->assertEquals('Johnathon "Johnny" Smith', $author['name'] );
  47. $this->assertEquals('john@example.com', $author['email']);
  48. }
  49. /**
  50. * Test scenario for issue #5631
  51. * @link https://github.com/composer/composer/issues/5631 Issue #5631
  52. */
  53. public function testParseValidAlias2AuthorString()
  54. {
  55. $command = new InitCommand;
  56. $author = $command->parseAuthorString(
  57. 'Johnathon (Johnny) Smith <john@example.com>');
  58. $this->assertEquals('Johnathon (Johnny) Smith', $author['name'] );
  59. $this->assertEquals('john@example.com', $author['email']);
  60. }
  61. public function testParseEmptyAuthorString()
  62. {
  63. $command = new InitCommand;
  64. $this->setExpectedException('InvalidArgumentException');
  65. $command->parseAuthorString('');
  66. }
  67. public function testParseAuthorStringWithInvalidEmail()
  68. {
  69. $command = new InitCommand;
  70. $this->setExpectedException('InvalidArgumentException');
  71. $command->parseAuthorString('John Smith <john>');
  72. }
  73. }