MetadataMinifierTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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\Util;
  12. use Composer\Util\MetadataMinifier;
  13. use Composer\Package\CompletePackage;
  14. use Composer\Package\Dumper\ArrayDumper;
  15. use PHPUnit\Framework\TestCase;
  16. class MetadataMinifierTest extends TestCase
  17. {
  18. public function testMinifyExpand()
  19. {
  20. $package1 = new CompletePackage('foo/bar', '2.0.0.0', '2.0.0');
  21. $package1->setScripts(array('foo' => 'bar'));
  22. $package1->setLicense(array('MIT'));
  23. $package2 = new CompletePackage('foo/bar', '1.2.0.0', '1.2.0');
  24. $package2->setLicense(array('GPL'));
  25. $package2->setHomepage('https://example.org');
  26. $package3 = new CompletePackage('foo/bar', '1.0.0.0', '1.0.0');
  27. $package3->setLicense(array('GPL'));
  28. $dumper = new ArrayDumper();
  29. $minified = array(
  30. array('name' => 'foo/bar', 'version' => '2.0.0', 'version_normalized' => '2.0.0.0', 'type' => 'library', 'scripts' => array('foo' => 'bar'), 'license' => array('MIT')),
  31. array('version' => '1.2.0', 'version_normalized' => '1.2.0.0', 'license' => array('GPL'), 'homepage' => 'https://example.org', 'scripts' => '__unset'),
  32. array('version' => '1.0.0', 'version_normalized' => '1.0.0.0', 'homepage' => '__unset'),
  33. );
  34. $source = array($dumper->dump($package1), $dumper->dump($package2), $dumper->dump($package3));
  35. $this->assertSame($minified, MetadataMinifier::minify($source));
  36. $this->assertSame($source, MetadataMinifier::expand($minified));
  37. }
  38. }