ArrayDumperTest.php 4.1 KB

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