LiteralTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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\DependencyResolver;
  12. use Composer\DependencyResolver\Literal;
  13. use Composer\Test\TestCase;
  14. class LiteralTest extends TestCase
  15. {
  16. protected $package;
  17. public function setUp()
  18. {
  19. $this->package = $this->getPackage('foo', '1');
  20. $this->package->setId(12);
  21. }
  22. public function testLiteralWanted()
  23. {
  24. $literal = new Literal($this->package, true);
  25. $this->assertEquals(12, $literal->getId());
  26. $this->assertEquals('+'.(string) $this->package, (string) $literal);
  27. }
  28. public function testLiteralUnwanted()
  29. {
  30. $literal = new Literal($this->package, false);
  31. $this->assertEquals(-12, $literal->getId());
  32. $this->assertEquals('-'.(string) $this->package, (string) $literal);
  33. }
  34. public function testLiteralInverted()
  35. {
  36. $literal = new Literal($this->package, false);
  37. $inverted = $literal->inverted();
  38. $this->assertInstanceOf('\Composer\DependencyResolver\Literal', $inverted);
  39. $this->assertTrue($inverted->isWanted());
  40. $this->assertSame($this->package, $inverted->getPackage());
  41. $this->assertFalse($literal->equals($inverted));
  42. $doubleInverted = $inverted->inverted();
  43. $this->assertInstanceOf('\Composer\DependencyResolver\Literal', $doubleInverted);
  44. $this->assertFalse($doubleInverted->isWanted());
  45. $this->assertSame($this->package, $doubleInverted->getPackage());
  46. $this->assertTrue($literal->equals($doubleInverted));
  47. }
  48. }