InitCommandTest.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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\Test\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 testParseValidUtf8AuthorStringWithNonSpacingMarks()
  31. {
  32. // \xCC\x88 is UTF-8 for U+0308 diaeresis (umlaut) combining mark
  33. $utf8_expected = "Matti Meika\xCC\x88la\xCC\x88inen";
  34. $command = new InitCommand;
  35. $author = $command->parseAuthorString($utf8_expected." <matti@example.com>");
  36. $this->assertEquals($utf8_expected, $author['name']);
  37. $this->assertEquals('matti@example.com', $author['email']);
  38. }
  39. public function testParseNumericAuthorString()
  40. {
  41. $command = new InitCommand;
  42. $author = $command->parseAuthorString('h4x0r <h4x@example.com>');
  43. $this->assertEquals('h4x0r', $author['name']);
  44. $this->assertEquals('h4x@example.com', $author['email']);
  45. }
  46. /**
  47. * Test scenario for issue #5631
  48. * @link https://github.com/composer/composer/issues/5631 Issue #5631
  49. */
  50. public function testParseValidAlias1AuthorString()
  51. {
  52. $command = new InitCommand;
  53. $author = $command->parseAuthorString(
  54. 'Johnathon "Johnny" Smith <john@example.com>'
  55. );
  56. $this->assertEquals('Johnathon "Johnny" Smith', $author['name']);
  57. $this->assertEquals('john@example.com', $author['email']);
  58. }
  59. /**
  60. * Test scenario for issue #5631
  61. * @link https://github.com/composer/composer/issues/5631 Issue #5631
  62. */
  63. public function testParseValidAlias2AuthorString()
  64. {
  65. $command = new InitCommand;
  66. $author = $command->parseAuthorString(
  67. 'Johnathon (Johnny) Smith <john@example.com>'
  68. );
  69. $this->assertEquals('Johnathon (Johnny) Smith', $author['name']);
  70. $this->assertEquals('john@example.com', $author['email']);
  71. }
  72. public function testParseEmptyAuthorString()
  73. {
  74. $command = new InitCommand;
  75. $this->setExpectedException('InvalidArgumentException');
  76. $command->parseAuthorString('');
  77. }
  78. public function testParseAuthorStringWithInvalidEmail()
  79. {
  80. $command = new InitCommand;
  81. $this->setExpectedException('InvalidArgumentException');
  82. $command->parseAuthorString('John Smith <john>');
  83. }
  84. }