ApplicationNameTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /*
  3. * This file is part of PharIo\Manifest.
  4. *
  5. * (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace PharIo\Manifest;
  11. use PHPUnit\Framework\TestCase;
  12. class ApplicationNameTest extends TestCase {
  13. public function testCanBeCreatedWithValidName() {
  14. $this->assertInstanceOf(
  15. ApplicationName::class,
  16. new ApplicationName('foo/bar')
  17. );
  18. }
  19. public function testUsingInvalidFormatForNameThrowsException() {
  20. $this->expectException(InvalidApplicationNameException::class);
  21. $this->expectExceptionCode(InvalidApplicationNameException::InvalidFormat);
  22. new ApplicationName('foo');
  23. }
  24. public function testUsingWrongTypeForNameThrowsException() {
  25. $this->expectException(InvalidApplicationNameException::class);
  26. $this->expectExceptionCode(InvalidApplicationNameException::NotAString);
  27. new ApplicationName(123);
  28. }
  29. public function testReturnsTrueForEqualNamesWhenCompared() {
  30. $app = new ApplicationName('foo/bar');
  31. $this->assertTrue(
  32. $app->isEqual($app)
  33. );
  34. }
  35. public function testReturnsFalseForNonEqualNamesWhenCompared() {
  36. $app1 = new ApplicationName('foo/bar');
  37. $app2 = new ApplicationName('foo/foo');
  38. $this->assertFalse(
  39. $app1->isEqual($app2)
  40. );
  41. }
  42. public function testCanBeConvertedToString() {
  43. $this->assertEquals(
  44. 'foo/bar',
  45. new ApplicationName('foo/bar')
  46. );
  47. }
  48. }