public function onBeforeScenarioTested()
 {
     $processBuilder = ProcessBuilder::create()->setPrefix($this->binary)->add('site-install')->add($this->drupal->getProfile())->add('--sites-subdir=' . $this->drupal->getSiteDir())->add('--account-name=admin')->add('--account-pass=password')->add('--yes')->setWorkingDirectory($this->drupal->getPath())->setTimeout(null)->setEnv('PHP_OPTIONS', '-d sendmail_path=' . `which true`);
     $this->eventDispatcher->dispatch(InstallingSite::NAME, $event = new InstallingSite($this->drupal, $processBuilder));
     if (!$event->isPropagationStopped()) {
         $this->processRunner->run($processBuilder->getProcess());
         $this->eventDispatcher->dispatch(SiteInstalled::NAME, new SiteInstalled($this->drupal));
     }
 }
 public function onInstallingSite(InstallingSite $event)
 {
     if (!is_dir($this->masterPath)) {
         // Master copy doesn't yet exist, so let it be created.
         return;
     }
     // Import the site's folder.
     if (is_dir($this->drupal->getSitePath())) {
         $this->filesystem->chmod($this->drupal->getSitePath(), 0777, 00, true);
     }
     $this->filesystem->mirror($this->masterPath, $this->drupal->getSitePath(), null, ['override' => true, 'delete' => true]);
     // Clean the database. (Mainly for SQLite.)
     $this->processRunner->run(ProcessBuilder::create()->setPrefix($this->binary)->add('sql-drop')->add('--uri=' . $this->drupal->getUri())->add('--yes')->setWorkingDirectory($this->drupal->getPath())->setTimeout(null)->getProcess());
     // Import the database.
     $this->processRunner->run(ProcessBuilder::create()->setPrefix($this->binary)->add('sql-query')->add('--file=' . $this->drupal->getSitePath() . '/db.sql')->add('--uri=' . $this->drupal->getUri())->add('--yes')->setWorkingDirectory($this->drupal->getPath())->setTimeout(null)->getProcess());
     $this->filesystem->remove($this->drupal->getSitePath() . '/db.sql');
     $this->eventDispatcher->dispatch(SiteCloned::NAME, new SiteCloned($this->drupal));
     // Signify that a site isn't actually being installed.
     $event->stopPropagation();
 }
 /**
  * @test
  */
 public function itUsesACopyOfAnInstalledSite()
 {
     $dispatcher = $this->prophesize('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $root = vfsStream::setup('foo');
     $root->addChild($sites = vfsStream::newDirectory('sites'));
     $sites->addChild($site = vfsStream::newDirectory('localhost'));
     $site->addChild($file = vfsStream::newFile('bar.tmp'));
     $sites->addChild($site = vfsStream::newDirectory('localhost.master'));
     $site->addChild($file = vfsStream::newFile('foo.tmp'));
     $site->addChild($file = vfsStream::newFile('db.sql'));
     $drupal = new Drupal('vfs://foo/', 'http://localhost/', 'standard');
     $processRunner = $this->prophesize('eLife\\IsolatedDrupalBehatExtension\\Process\\ProcessRunner');
     $cleaner = $this->prophesize('eLife\\IsolatedDrupalBehatExtension\\Filesystem\\FilesystemCleaner');
     $lazyCleaner = $this->prophesize('eLife\\IsolatedDrupalBehatExtension\\Filesystem\\LazyFilesystemCleaner');
     $listener = new BypassInstallSiteListener($dispatcher->reveal(), $drupal, new Filesystem(), '/path/to/drush', $processRunner->reveal(), $cleaner->reveal(), $lazyCleaner->reveal());
     $realDispatcher = $this->getDispatcher($listener);
     $realDispatcher->dispatch(InstallingSite::NAME, $event = new InstallingSite($drupal, new ProcessBuilder()));
     $this->assertFileExists($drupal->getSitePath() . '/foo.tmp');
     $this->assertFileNotExists($drupal->getSitePath() . '/db.sql');
     $this->assertFileNotExists($drupal->getSitePath() . '/bar.tmp');
     $processRunner->run(Argument::type('Symfony\\Component\\Process\\Process'))->shouldBeCalledTimes(2)->should(new CallbackPrediction(function (array $calls) use($drupal) {
         /** @var Call[] $calls */
         /** @var Process $process0 */
         $process0 = $calls[0]->getArguments()[0];
         /** @var Process $process1 */
         $process1 = $calls[1]->getArguments()[0];
         Assert::assertSame("'/path/to/drush' 'sql-drop' '--uri=http://localhost/' '--yes'", $process0->getCommandLine());
         Assert::assertSame($drupal->getPath(), $process0->getWorkingDirectory());
         Assert::assertSame("'/path/to/drush' 'sql-query' '--file=vfs://foo/sites/localhost/db.sql' '--uri=http://localhost/' '--yes'", $process1->getCommandLine());
         Assert::assertSame($drupal->getPath(), $process1->getWorkingDirectory());
     }));
     $dispatcher->dispatch(SiteCloned::NAME, Argument::type('eLife\\IsolatedDrupalBehatExtension\\Event\\SiteCloned'))->shouldHaveBeenCalled();
     $this->assertTrue($event->isPropagationStopped());
 }
 /**
  * @test
  */
 public function itHasACommand()
 {
     $processBuilder = new ProcessBuilder();
     $event = new InstallingSite($this->generateDrupal(), $processBuilder);
     $this->assertSame($processBuilder, $event->getCommand());
 }