InitCommandTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. public function testParseEmptyAuthorString()
  38. {
  39. $command = new InitCommand;
  40. $this->setExpectedException('InvalidArgumentException');
  41. $command->parseAuthorString('');
  42. }
  43. public function testParseAuthorStringWithInvalidEmail()
  44. {
  45. $command = new InitCommand;
  46. $this->setExpectedException('InvalidArgumentException');
  47. $command->parseAuthorString('John Smith <john>');
  48. }
  49. }