ArrayDumperTest.php 7.6 KB

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