ArrayDumperTest.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. 'Package Manager'
  87. ),
  88. array(
  89. 'keywords',
  90. array('package', 'dependency', 'autoload')
  91. ),
  92. array(
  93. 'bin',
  94. array('bin/composer'),
  95. 'binaries'
  96. ),
  97. array(
  98. 'license',
  99. array('MIT')
  100. ),
  101. array(
  102. 'autoload',
  103. array('psr-0' => array('Composer' => 'src/'))
  104. ),
  105. array(
  106. 'repositories',
  107. array('packagist' => false)
  108. ),
  109. array(
  110. 'scripts',
  111. array('post-update-cmd' => 'MyVendor\\MyClass::postUpdate')
  112. ),
  113. array(
  114. 'extra',
  115. array('class' => 'MyVendor\\Installer')
  116. ),
  117. array(
  118. 'require',
  119. array(new Link('foo', 'foo/bar', new VersionConstraint('=', '1.0.0.0'), 'requires', '1.0.0')),
  120. 'requires',
  121. array('foo/bar' => '1.0.0'),
  122. ),
  123. array(
  124. 'require-dev',
  125. array(new Link('foo', 'foo/bar', new VersionConstraint('=', '1.0.0.0'), 'requires (for development)', '1.0.0')),
  126. 'devRequires',
  127. array('foo/bar' => '1.0.0'),
  128. ),
  129. array(
  130. 'suggest',
  131. array('foo/bar' => 'very useful package'),
  132. 'suggests'
  133. ),
  134. array(
  135. 'support',
  136. array('foo' => 'bar'),
  137. )
  138. );
  139. }
  140. private function packageExpects($method, $value)
  141. {
  142. $this->package
  143. ->expects($this->any())
  144. ->method($method)
  145. ->will($this->returnValue($value));
  146. return $this;
  147. }
  148. }