Exemplo n.º 1
0
    /**
     * Test that the reading is successful.
     *
     * @return void
     *
     * @dataProvider testReadingFlagsProvider
     */
    public function testReadingEntirePharCompressed($compression, $signatureName, $signatureFlag)
    {
        $pharfile = $this->getTempFile('temp.phar');
        $phar = new \Phar($pharfile, 0, 'temp.phar');
        $phar->startBuffering();
        $phar->addFromString('/bin/script', $fileData = <<<EOF
#!/usr/bin/php
<?php
echo 'hello world';
EOF
);
        $phar->setStub(<<<EOF
#!/usr/bin/php
<?php

/*STUB!*/
__HALT_COMPILER();
?>
EOF
);
        $phar->stopBuffering();
        if (0 !== $signatureFlag) {
            $phar->setSignatureAlgorithm($signatureFlag);
        }
        if ($compression !== \Phar::NONE) {
            $phar->compress($compression);
        }
        unset($phar);
        $reader = new PharReader();
        $phar = $reader->load($pharfile);
        $this->assertEquals('temp.phar', $phar->getAlias());
        $this->assertTrue($phar->isSigned());
        $this->assertEquals($signatureName, $phar->getSignatureAlgorithm());
        $files = $phar->getFiles();
        $this->assertEquals('bin/script', $files[0]->getFilename());
        $this->assertEquals($fileData, $files[0]->getContent());
    }
Exemplo n.º 2
0
    /**
     * Test that the writing of a loaded phar results in an equal file.
     *
     * @return void
     *
     * @dataProvider testWritingFlagsProvider
     */
    public function testWriteLoaded($compression, $signatureFlag)
    {
        $pharfile = $this->getTempFile('temp.phar');
        $phar = new \Phar($pharfile, 0, 'temp.phar');
        $phar->startBuffering();
        $phar->addFromString('/bin/script', $fileData = <<<EOF
#!/usr/bin/php
<?php
echo 'hello world';
EOF
);
        $phar->setDefaultStub('/bin/script', '/web/index');
        $phar->stopBuffering();
        if (0 !== $signatureFlag) {
            $phar->setSignatureAlgorithm($signatureFlag);
        }
        if ($compression !== \Phar::NONE) {
            $phar->compress($compression);
        }
        unset($phar);
        $reader = new PharReader();
        $phar = $reader->load($pharfile);
        $pharfile2 = $this->getTempFile('temp.phar');
        $writer = new PharWriter();
        $writer->save($phar, $pharfile2);
        unset($writer);
        $this->assertFileEquals($pharfile, $pharfile2);
    }