コード例 #1
0
 /**
  * Verifies that archive information is shown.
  *
  * @covers \Box\Command\Info\ArchiveCommand
  */
 public function testExecute()
 {
     $file = $this->createArchive();
     self::assertEquals(0, $this->runCommand(new ArrayInput(array('command' => 'info:archive', 'path' => $file)), $output));
     $builder = new Builder($file);
     $contents = $this->readOutput($output);
     self::assertContains($file, $contents);
     self::assertContains($builder->getVersion(), $contents);
     self::assertContains('PHAR', $contents);
     self::assertContains('No', $contents);
     self::assertContains('SHA-1', $contents);
     self::assertContains('5', $contents);
     self::assertContains('NONE', $contents);
     self::assertContains('Yes', $contents);
 }
コード例 #2
0
 /**
  * Creates a new test archive.
  *
  * If a `$build` callback is not given, the default build will be used.
  *
  * @param callable $build The archive build callback.
  *
  * @return string The path to the test archive.
  */
 protected function createArchive(callable $build = null)
 {
     $path = tempnam($this->dir, '');
     unlink($path);
     $path .= '.phar';
     $builder = new Builder($path);
     if (null === $build) {
         $builder->addEmptyDir('a');
         $builder->addFromString('b/b', 'b');
         $builder->addFromString('c/c/c', 'c');
         $builder->addFromString('d/d/d/d', 'd');
         $builder->addFromString('e', 'e');
         $builder->resolvePath('c/c/c')->compress(Builder::BZ2);
         $builder->resolvePath('d/d/d/d')->compress(Builder::GZ);
     } else {
         $build($builder);
     }
     return $path;
 }
コード例 #3
0
ファイル: ExtractTest.php プロジェクト: box-project/builder
 /**
  * Creates a new archive file for testing.
  *
  * @param callable $tweak Make tweaks to the archive.
  *
  * @return string The path the new archive file.
  */
 protected function buildArchive(callable $tweak = null)
 {
     $file = tempnam(sys_get_temp_dir(), 'box-');
     unlink($file);
     $this->paths[] = $file .= '.phar';
     $builder = new Builder($file, 0, basename($file));
     $builder->addFromString('a', 'a');
     $builder->addFromString('b/b', '');
     $builder->addFromString('c/c/c', 'c');
     $builder->addEmptyDir('d/d/d/d');
     if (null !== $tweak) {
         $tweak($builder);
     }
     $builder = null;
     return $file;
 }
コード例 #4
0
ファイル: BuildCommand.php プロジェクト: box-project/box3
 /**
  * Signs the archive.
  *
  * @param Builder $builder The archive builder.
  *
  * @return BuildCommand For method chaining.
  */
 private function sign(Builder $builder)
 {
     $event = new PreSignEvent($builder, constant('Phar::' . $this->config['build']['signature']['algorithm']), $this->config['build']['signature']['file']);
     $this->dispatcher->dispatch(Events::PRE_BUILD_SIGN, $event);
     $builder->setSignatureAlgorithm($event->getAlgorithm(), $event->getPath());
     $this->dispatcher->dispatch(Events::POST_BUILD_SIGN, new PostSignEvent($builder, $event->getAlgorithm(), $event->getPath()));
     return $this;
 }
コード例 #5
0
ファイル: BuildCommandTest.php プロジェクト: box-project/box3
 /**
  * Verifies that we can create an archive using the default stub.
  */
 public function testExecuteDefaultStub()
 {
     // create project configuration
     file_put_contents($this->dir . '/box.yml', '');
     // reload the application
     $this->app = $this->createApp($this->dir);
     // build the archive
     $status = $this->runCommand(new ArrayInput(array('command' => 'build')), $output);
     if (0 !== $status) {
         self::markTestIncomplete($this->readOutput($output));
     }
     // make sure the default stub is used
     $builder = new Builder($this->dir . '/out.phar');
     $this->setExpectedException('RuntimeException', 'Unable to read stub');
     self::assertContains('class Extract_Archive', $builder->getStub());
 }
コード例 #6
0
ファイル: BuilderTest.php プロジェクト: box-project/builder
 /**
  * Verifies that the pre and post events for `setStub` are dispatched.
  */
 public function testSetStub()
 {
     // make sure the events are fired and changes are applied
     $hello = '<?php echo "Hello, world!\\n"; __HALT_COMPILER(); ?>';
     $goodbye = '<?php echo "Goodbye, world!\\n"; __HALT_COMPILER(); ?>';
     $post = null;
     $this->dispatcher->addListener(Events::PRE_SET_STUB, function (PreSetStubEvent $event) use($goodbye) {
         $event->setStub($goodbye);
     });
     $this->dispatcher->addListener(Events::POST_SET_STUB, function (PostSetStubEvent $event) use(&$post) {
         $post = $event;
     });
     $this->builder->setStub($hello);
     self::assertEquals($goodbye, trim($this->builder->getStub()));
     self::assertInstanceOf('Box\\Component\\Builder\\Event\\PostSetStubEvent', $post);
     // make sure the process can be skipped
     $this->removeListeners();
     $this->builder->setStub(Builder::createDefaultStub());
     $this->dispatcher->addListener(Events::PRE_SET_STUB, function (PreSetStubEvent $event) {
         $event->skip();
     });
     $this->builder->setStub($hello);
     self::assertEquals(trim(Builder::createDefaultStub()), trim($this->builder->getStub()));
     // make sure we can skip everything and go straight to `Phar`
     $this->builder->setEventDispatcher(null);
     $post = null;
     $this->builder->setStub($hello);
     self::assertEquals($hello, trim($this->builder->getStub()));
     self::assertNull($post);
 }