ArrayDumperTest.php 7.0 KB

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