ArrayDumperTest.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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\CompletePackageInterface|\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\CompletePackageInterface');
  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. 'abandoned' => false
  43. ),
  44. $config
  45. );
  46. }
  47. public function testRootPackage()
  48. {
  49. $this->package = $this->getMock('Composer\Package\RootPackageInterface');
  50. $this
  51. ->packageExpects('getMinimumStability', 'dev');
  52. $config = $this->dumper->dump($this->package);
  53. $this->assertSame('dev', $config['minimum-stability']);
  54. }
  55. public function testDumpAbandoned()
  56. {
  57. $this->packageExpects('getReplacementPackage', true);
  58. $config = $this->dumper->dump($this->package);
  59. $this->assertSame(true, $config['abandoned']);
  60. }
  61. public function testDumpAbandonedReplacement()
  62. {
  63. $this->packageExpects('getReplacementPackage', 'foo/bar');
  64. $config = $this->dumper->dump($this->package);
  65. $this->assertSame('foo/bar', $config['abandoned']);
  66. }
  67. /**
  68. * @dataProvider getKeys
  69. */
  70. public function testKeys($key, $value, $method = null, $expectedValue = null)
  71. {
  72. $this->packageExpects('get'.ucfirst($method ?: $key), $value);
  73. $this->packageExpects('isAbandoned', $value);
  74. $config = $this->dumper->dump($this->package);
  75. $this->assertSame($expectedValue ?: $value, $config[$key]);
  76. }
  77. public function getKeys()
  78. {
  79. return array(
  80. array(
  81. 'type',
  82. 'library'
  83. ),
  84. array(
  85. 'time',
  86. new \DateTime('2012-02-01'),
  87. 'ReleaseDate',
  88. '2012-02-01 00:00:00',
  89. ),
  90. array(
  91. 'authors',
  92. array('Nils Adermann <naderman@naderman.de>', 'Jordi Boggiano <j.boggiano@seld.be>')
  93. ),
  94. array(
  95. 'homepage',
  96. 'http://getcomposer.org'
  97. ),
  98. array(
  99. 'description',
  100. 'Dependency Manager'
  101. ),
  102. array(
  103. 'keywords',
  104. array('package', 'dependency', 'autoload'),
  105. null,
  106. array('autoload', 'dependency', 'package')
  107. ),
  108. array(
  109. 'bin',
  110. array('bin/composer'),
  111. 'binaries'
  112. ),
  113. array(
  114. 'license',
  115. array('MIT')
  116. ),
  117. array(
  118. 'autoload',
  119. array('psr-0' => array('Composer' => 'src/'))
  120. ),
  121. array(
  122. 'repositories',
  123. array('packagist' => false)
  124. ),
  125. array(
  126. 'scripts',
  127. array('post-update-cmd' => 'MyVendor\\MyClass::postUpdate')
  128. ),
  129. array(
  130. 'extra',
  131. array('class' => 'MyVendor\\Installer')
  132. ),
  133. array(
  134. 'archive',
  135. array('/foo/bar', 'baz', '!/foo/bar/baz'),
  136. 'archiveExcludes',
  137. array(
  138. 'exclude' => array('/foo/bar', 'baz', '!/foo/bar/baz'),
  139. ),
  140. ),
  141. array(
  142. 'require',
  143. array(new Link('foo', 'foo/bar', new VersionConstraint('=', '1.0.0.0'), 'requires', '1.0.0')),
  144. 'requires',
  145. array('foo/bar' => '1.0.0'),
  146. ),
  147. array(
  148. 'require-dev',
  149. array(new Link('foo', 'foo/bar', new VersionConstraint('=', '1.0.0.0'), 'requires (for development)', '1.0.0')),
  150. 'devRequires',
  151. array('foo/bar' => '1.0.0'),
  152. ),
  153. array(
  154. 'suggest',
  155. array('foo/bar' => 'very useful package'),
  156. 'suggests'
  157. ),
  158. array(
  159. 'support',
  160. array('foo' => 'bar'),
  161. ),
  162. array(
  163. 'require',
  164. array(new Link('foo', 'foo/bar', new VersionConstraint('=', '1.0.0.0'), 'requires', '1.0.0'), new Link('bar', 'bar/baz', new VersionConstraint('=', '1.0.0.0'), 'requires', '1.0.0')),
  165. 'requires',
  166. array('bar/baz' => '1.0.0', 'foo/bar' => '1.0.0')
  167. ),
  168. array(
  169. 'require-dev',
  170. array(new Link('foo', 'foo/bar', new VersionConstraint('=', '1.0.0.0'), 'requires', '1.0.0'), new Link('bar', 'bar/baz', new VersionConstraint('=', '1.0.0.0'), 'requires', '1.0.0')),
  171. 'devRequires',
  172. array('bar/baz' => '1.0.0', 'foo/bar' => '1.0.0')
  173. ),
  174. array(
  175. 'suggest',
  176. array('foo/bar' => 'very useful package', 'bar/baz' => 'another useful package'),
  177. 'suggests',
  178. array('bar/baz' => 'another useful package', 'foo/bar' => 'very useful package')
  179. ),
  180. array(
  181. 'provide',
  182. array(new Link('foo', 'foo/bar', new VersionConstraint('=', '1.0.0.0'), 'requires', '1.0.0'), new Link('bar', 'bar/baz', new VersionConstraint('=', '1.0.0.0'), 'requires', '1.0.0')),
  183. 'provides',
  184. array('bar/baz' => '1.0.0', 'foo/bar' => '1.0.0')
  185. ),
  186. array(
  187. 'replace',
  188. array(new Link('foo', 'foo/bar', new VersionConstraint('=', '1.0.0.0'), 'requires', '1.0.0'), new Link('bar', 'bar/baz', new VersionConstraint('=', '1.0.0.0'), 'requires', '1.0.0')),
  189. 'replaces',
  190. array('bar/baz' => '1.0.0', 'foo/bar' => '1.0.0')
  191. ),
  192. array(
  193. 'conflict',
  194. array(new Link('foo', 'foo/bar', new VersionConstraint('=', '1.0.0.0'), 'requires', '1.0.0'), new Link('bar', 'bar/baz', new VersionConstraint('=', '1.0.0.0'), 'requires', '1.0.0')),
  195. 'conflicts',
  196. array('bar/baz' => '1.0.0', 'foo/bar' => '1.0.0')
  197. ),
  198. array(
  199. 'transport-options',
  200. array('ssl' => array('local_cert' => '/opt/certs/test.pem')),
  201. 'transportOptions'
  202. )
  203. );
  204. }
  205. private function packageExpects($method, $value)
  206. {
  207. $this->package
  208. ->expects($this->any())
  209. ->method($method)
  210. ->will($this->returnValue($value));
  211. return $this;
  212. }
  213. }