BasePackageTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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\Package;
  12. use Composer\Package\BasePackage;
  13. use Composer\Test\TestCase;
  14. class BasePackageTest extends TestCase
  15. {
  16. /**
  17. * @doesNotPerformAssertions
  18. */
  19. public function testSetSameRepository()
  20. {
  21. $package = $this->getMockForAbstractClass('Composer\Package\BasePackage', array('foo'));
  22. $repository = $this->getMockBuilder('Composer\Repository\RepositoryInterface')->getMock();
  23. $package->setRepository($repository);
  24. try {
  25. $package->setRepository($repository);
  26. } catch (\Exception $e) {
  27. $this->fail('Set against the same repository is allowed.');
  28. }
  29. }
  30. /**
  31. * @expectedException LogicException
  32. */
  33. public function testSetAnotherRepository()
  34. {
  35. $package = $this->getMockForAbstractClass('Composer\Package\BasePackage', array('foo'));
  36. $package->setRepository($this->getMockBuilder('Composer\Repository\RepositoryInterface')->getMock());
  37. $package->setRepository($this->getMockBuilder('Composer\Repository\RepositoryInterface')->getMock());
  38. }
  39. /**
  40. * @dataProvider formattedVersions
  41. */
  42. public function testFormatVersionForDevPackage(BasePackage $package, $truncate, $expected)
  43. {
  44. $this->assertSame($expected, $package->getFullPrettyVersion($truncate));
  45. }
  46. public function formattedVersions()
  47. {
  48. $data = array(
  49. array(
  50. 'sourceReference' => 'v2.1.0-RC2',
  51. 'truncate' => true,
  52. 'expected' => 'PrettyVersion v2.1.0-RC2',
  53. ),
  54. array(
  55. 'sourceReference' => 'bbf527a27356414bfa9bf520f018c5cb7af67c77',
  56. 'truncate' => true,
  57. 'expected' => 'PrettyVersion bbf527a',
  58. ),
  59. array(
  60. 'sourceReference' => 'v1.0.0',
  61. 'truncate' => false,
  62. 'expected' => 'PrettyVersion v1.0.0',
  63. ),
  64. array(
  65. 'sourceReference' => 'bbf527a27356414bfa9bf520f018c5cb7af67c77',
  66. 'truncate' => false,
  67. 'expected' => 'PrettyVersion bbf527a27356414bfa9bf520f018c5cb7af67c77',
  68. ),
  69. );
  70. $self = $this;
  71. $createPackage = function ($arr) use ($self) {
  72. $package = $self->getMockForAbstractClass('\Composer\Package\BasePackage', array(), '', false);
  73. $package->expects($self->once())->method('isDev')->will($self->returnValue(true));
  74. $package->expects($self->once())->method('getSourceType')->will($self->returnValue('git'));
  75. $package->expects($self->once())->method('getPrettyVersion')->will($self->returnValue('PrettyVersion'));
  76. $package->expects($self->any())->method('getSourceReference')->will($self->returnValue($arr['sourceReference']));
  77. return array($package, $arr['truncate'], $arr['expected']);
  78. };
  79. return array_map($createPackage, $data);
  80. }
  81. }