File: MetadataMinifierTest.php

package info (click to toggle)
php-composer-metadata-minifier 1.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 124 kB
  • sloc: php: 80; makefile: 20
file content (47 lines) | stat: -rw-r--r-- 1,817 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php

/*
 * This file is part of composer/metadata-minifier.
 *
 * (c) Composer <https://github.com/composer>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Composer\Test\MetadataMinifier;

use Composer\MetadataMinifier\MetadataMinifier;
use Composer\Package\CompletePackage;
use Composer\Package\Dumper\ArrayDumper;
use PHPUnit\Framework\TestCase;

class MetadataMinifierTest extends TestCase
{
    /**
     * @return void
     */
    public function testMinifyExpand()
    {
        $package1 = new CompletePackage('foo/bar', '2.0.0.0', '2.0.0');
        $package1->setScripts(array('foo' => 'bar'));
        $package1->setLicense(array('MIT'));
        $package2 = new CompletePackage('foo/bar', '1.2.0.0', '1.2.0');
        $package2->setLicense(array('GPL'));
        $package2->setHomepage('https://example.org');
        $package3 = new CompletePackage('foo/bar', '1.0.0.0', '1.0.0');
        $package3->setLicense(array('GPL'));
        $dumper = new ArrayDumper();

        $minified = array(
            array('name' => 'foo/bar', 'version' => '2.0.0', 'version_normalized' => '2.0.0.0', 'type' => 'library', 'scripts' => array('foo' => 'bar'), 'license' => array('MIT')),
            array('version' => '1.2.0', 'version_normalized' => '1.2.0.0', 'license' => array('GPL'), 'homepage' => 'https://example.org', 'scripts' => '__unset'),
            array('version' => '1.0.0', 'version_normalized' => '1.0.0.0', 'homepage' => '__unset'),
        );

        $source = array($dumper->dump($package1), $dumper->dump($package2), $dumper->dump($package3));

        $this->assertSame($minified, MetadataMinifier::minify($source));
        $this->assertSame($source, MetadataMinifier::expand($minified));
    }
}