/** * 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()); }
/** * Add a file from the passed string. * * @param string $localName The local name of the file. * * @param string $contents The file contents to use. * * @return FileEntry */ public function addFromString($localName, $contents) { $add = new FileEntry(); $add->setContent($contents)->setFilename($localName); $this->pharchive->addFile($add); return $add; }
/** * Test that the version parsing works. * * @param string $expects The expected value. * * @param mixed $value The value to set. * * @return void * * @dataProvider permissionNumberProvider */ public function testPermissionParsing($expects, $value) { $phar = new FileEntry(); $phar->setPermissions($value); $this->assertEquals($expects, $phar->getPermissionString()); }