ExtensionTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 PharIo\Version\AnyVersionConstraint;
  12. use PharIo\Version\Version;
  13. use PharIo\Version\VersionConstraint;
  14. use PharIo\Version\VersionConstraintParser;
  15. use PHPUnit\Framework\TestCase;
  16. /**
  17. * @covers \PharIo\Manifest\Extension
  18. * @covers \PharIo\Manifest\Type
  19. *
  20. * @uses \PharIo\Version\VersionConstraint
  21. * @uses \PharIo\Manifest\ApplicationName
  22. */
  23. class ExtensionTest extends TestCase {
  24. /**
  25. * @var Extension
  26. */
  27. private $type;
  28. /**
  29. * @var ApplicationName|\PHPUnit_Framework_MockObject_MockObject
  30. */
  31. private $name;
  32. protected function setUp() {
  33. $this->name = $this->createMock(ApplicationName::class);
  34. $this->type = Type::extension($this->name, new AnyVersionConstraint);
  35. }
  36. public function testCanBeCreated() {
  37. $this->assertInstanceOf(Extension::class, $this->type);
  38. }
  39. public function testIsNotApplication() {
  40. $this->assertFalse($this->type->isApplication());
  41. }
  42. public function testIsNotLibrary() {
  43. $this->assertFalse($this->type->isLibrary());
  44. }
  45. public function testIsExtension() {
  46. $this->assertTrue($this->type->isExtension());
  47. }
  48. public function testApplicationCanBeRetrieved()
  49. {
  50. $this->assertInstanceOf(ApplicationName::class, $this->type->getApplicationName());
  51. }
  52. public function testVersionConstraintCanBeRetrieved() {
  53. $this->assertInstanceOf(
  54. VersionConstraint::class,
  55. $this->type->getVersionConstraint()
  56. );
  57. }
  58. public function testApplicationCanBeQueried()
  59. {
  60. $this->name->method('isEqual')->willReturn(true);
  61. $this->assertTrue(
  62. $this->type->isExtensionFor($this->createMock(ApplicationName::class))
  63. );
  64. }
  65. public function testCompatibleWithReturnsTrueForMatchingVersionConstraintAndApplicaiton() {
  66. $app = new ApplicationName('foo/bar');
  67. $extension = Type::extension($app, (new VersionConstraintParser)->parse('^1.0'));
  68. $version = new Version('1.0.0');
  69. $this->assertTrue(
  70. $extension->isCompatibleWith($app, $version)
  71. );
  72. }
  73. public function testCompatibleWithReturnsFalseForNotMatchingVersionConstraint() {
  74. $app = new ApplicationName('foo/bar');
  75. $extension = Type::extension($app, (new VersionConstraintParser)->parse('^1.0'));
  76. $version = new Version('2.0.0');
  77. $this->assertFalse(
  78. $extension->isCompatibleWith($app, $version)
  79. );
  80. }
  81. public function testCompatibleWithReturnsFalseForNotMatchingApplication() {
  82. $app1 = new ApplicationName('foo/bar');
  83. $app2 = new ApplicationName('foo/foo');
  84. $extension = Type::extension($app1, (new VersionConstraintParser)->parse('^1.0'));
  85. $version = new Version('1.0.0');
  86. $this->assertFalse(
  87. $extension->isCompatibleWith($app2, $version)
  88. );
  89. }
  90. }