/** * Test that the Writing is successful. * * @return void * * @dataProvider testWritingFlagsProvider */ public function testWriting($compression, $signatureName, $signatureFlag) { $pharfile = $this->getTempFile('temp.phar'); $phar = new Pharchive(); $phar->setStub($stubData = <<<EOF #!/usr/bin/php <?php /*STUB!*/ __HALT_COMPILER(); EOF )->setSignatureFlags($signatureFlag); $file = new FileEntry(); $file->setFilename('/bin/script')->setContent($fileData = <<<EOF #!/usr/bin/php <?php echo 'hello world'; EOF ); if ($compression) { $file->setCompression($compression); } $phar->addFile($file); $writer = new PharWriter(); $writer->save($phar, $pharfile); unset($writer); $phar = new \Phar($pharfile); // As we did not set an alias, php defaults to the file name. $this->assertEquals($pharfile, $phar->getAlias()); $signature = $phar->getSignature(); $this->assertEquals($signatureName, strtolower(str_replace('-', '', $signature['hash_type']))); /** @var \PharFileInfo[] $files */ $files = array_values(iterator_to_array($phar->getChildren())); $this->assertEquals('phar://' . $pharfile . '/bin/script', $files[0]->getPathname()); $this->assertEquals($fileData, $files[0]->getContent()); }
/** * Test that the version parsing works. * * @param string $expectedException The expected exception. * * @param mixed $value The value to set. * * @return void * * @dataProvider invalidVersionNumberProvider */ public function testVersionParsingWithInvalidRaisesException($expectedException, $value) { $this->setExpectedException($expectedException); $phar = new Pharchive(); $phar->setApiVersion($value); }
/** * Compress all files using the passed algorithm. * * @param int $algorithm The algoithm to use (either \Phar::GZ or \Phar::BZ2). * * @return void */ public function compressFiles($algorithm) { foreach ($this->pharchive->getFiles() as $file) { $file->setCompression($algorithm); } }