1
0
Fork 0
composer/tests/Composer/Test/Util/MetadataMinifierTest.php

46 lines
1.7 KiB
PHP
Raw Normal View History

2022-02-23 15:58:18 +00:00
<?php declare(strict_types=1);
2020-01-15 11:58:30 +00:00
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Test\Util;
2021-08-18 13:17:06 +00:00
use Composer\MetadataMinifier\MetadataMinifier;
2020-01-15 11:58:30 +00:00
use Composer\Package\CompletePackage;
use Composer\Package\Dumper\ArrayDumper;
use PHPUnit\Framework\TestCase;
class MetadataMinifierTest extends TestCase
{
public function testMinifyExpand(): void
2020-01-15 11:58:30 +00:00
{
$package1 = new CompletePackage('foo/bar', '2.0.0.0', '2.0.0');
2022-08-17 12:20:07 +00:00
$package1->setScripts(['foo' => ['bar']]);
$package1->setLicense(['MIT']);
2020-01-15 11:58:30 +00:00
$package2 = new CompletePackage('foo/bar', '1.2.0.0', '1.2.0');
2022-08-17 12:20:07 +00:00
$package2->setLicense(['GPL']);
2020-01-15 11:58:30 +00:00
$package2->setHomepage('https://example.org');
$package3 = new CompletePackage('foo/bar', '1.0.0.0', '1.0.0');
2022-08-17 12:20:07 +00:00
$package3->setLicense(['GPL']);
2020-01-15 11:58:30 +00:00
$dumper = new ArrayDumper();
2022-08-17 12:20:07 +00:00
$minified = [
['name' => 'foo/bar', 'version' => '2.0.0', 'version_normalized' => '2.0.0.0', 'type' => 'library', 'scripts' => ['foo' => ['bar']], 'license' => ['MIT']],
['version' => '1.2.0', 'version_normalized' => '1.2.0.0', 'license' => ['GPL'], 'homepage' => 'https://example.org', 'scripts' => '__unset'],
['version' => '1.0.0', 'version_normalized' => '1.0.0.0', 'homepage' => '__unset'],
];
2020-01-15 11:58:30 +00:00
2022-08-17 12:20:07 +00:00
$source = [$dumper->dump($package1), $dumper->dump($package2), $dumper->dump($package3)];
2020-01-15 11:58:30 +00:00
self::assertSame($minified, MetadataMinifier::minify($source));
self::assertSame($source, MetadataMinifier::expand($minified));
2020-01-15 11:58:30 +00:00
}
}