ArrayDumperTest.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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\Dumper;
  12. use Composer\Package\Dumper\ArrayDumper;
  13. use Composer\Package\Link;
  14. use Composer\Package\LinkConstraint\VersionConstraint;
  15. class ArrayDumperTest extends \PHPUnit_Framework_TestCase
  16. {
  17. /**
  18. * @var ArrayDumper
  19. */
  20. private $dumper;
  21. /**
  22. * @var \Composer\Package\PackageInterface|\PHPUnit_Framework_MockObject_MockObject
  23. */
  24. private $package;
  25. public function setUp()
  26. {
  27. $this->dumper = new ArrayDumper();
  28. $this->package = $this->getMock('Composer\Package\PackageInterface');
  29. }
  30. public function testRequiredInformation()
  31. {
  32. $this
  33. ->packageExpects('getPrettyName', 'foo')
  34. ->packageExpects('getPrettyVersion', '1.0')
  35. ->packageExpects('getVersion', '1.0.0.0');
  36. $config = $this->dumper->dump($this->package);
  37. $this->assertEquals(
  38. array(
  39. 'name' => 'foo',
  40. 'version' => '1.0',
  41. 'version_normalized' => '1.0.0.0'
  42. ),
  43. $config
  44. );
  45. }
  46. /**
  47. * @dataProvider getKeys
  48. */
  49. public function testKeys($key, $value, $method = null, $expectedValue = null)
  50. {
  51. $this->packageExpects('get'.ucfirst($method ?: $key), $value);
  52. $config = $this->dumper->dump($this->package);
  53. $this->assertSame($expectedValue ?: $value, $config[$key]);
  54. }
  55. public function getKeys()
  56. {
  57. return array(
  58. array(
  59. 'type',
  60. 'library'
  61. ),
  62. array(
  63. 'time',
  64. new \DateTime('2012-02-01'),
  65. 'ReleaseDate',
  66. '2012-02-01 00:00:00',
  67. ),
  68. array(
  69. 'authors',
  70. array('Nils Adermann <naderman@naderman.de>', 'Jordi Boggiano <j.boggiano@seld.be>')
  71. ),
  72. array(
  73. 'homepage',
  74. 'http://getcomposer.org'
  75. ),
  76. array(
  77. 'description',
  78. 'Package Manager'
  79. ),
  80. array(
  81. 'keywords',
  82. array('package', 'dependency', 'autoload')
  83. ),
  84. array(
  85. 'bin',
  86. array('bin/composer'),
  87. 'binaries'
  88. ),
  89. array(
  90. 'license',
  91. array('MIT')
  92. ),
  93. array(
  94. 'autoload',
  95. array('psr-0' => array('Composer' => 'src/'))
  96. ),
  97. array(
  98. 'repositories',
  99. array('packagist' => false)
  100. ),
  101. array(
  102. 'scripts',
  103. array('post-update-cmd' => 'MyVendor\\MyClass::postUpdate')
  104. ),
  105. array(
  106. 'extra',
  107. array('class' => 'MyVendor\\Installer')
  108. ),
  109. array(
  110. 'require',
  111. array(new Link('foo', 'foo/bar', new VersionConstraint('=', '1.0.0.0'), 'requires', '1.0.0')),
  112. 'requires',
  113. array('foo/bar' => '1.0.0'),
  114. ),
  115. array(
  116. 'require-dev',
  117. array(new Link('foo', 'foo/bar', new VersionConstraint('=', '1.0.0.0'), 'requires (for development)', '1.0.0')),
  118. 'devRequires',
  119. array('foo/bar' => '1.0.0'),
  120. ),
  121. array(
  122. 'suggest',
  123. array('foo/bar' => 'very useful package'),
  124. 'suggests'
  125. ),
  126. array(
  127. 'support',
  128. array('foo' => 'bar'),
  129. )
  130. );
  131. }
  132. private function packageExpects($method, $value)
  133. {
  134. $this->package
  135. ->expects($this->any())
  136. ->method($method)
  137. ->will($this->returnValue($value));
  138. return $this;
  139. }
  140. }