Pantheon\Terminus\Commands\Solr\EnableCommand::enable PHP Method

enable() public method

Enable Solr indexing on a site
public enable ( string $site_id )
$site_id string Name of the site to enable Solr on
    public function enable($site_id)
    {
        $site = $this->getSite($site_id);
        $site->getSolr()->enable();
        $this->log()->notice('Solr enabled. Converging bindings.');
        $workflow = $site->converge();
        // Wait for the workflow to complete.
        while (!$workflow->checkProgress()) {
            // @TODO: Add Symfony progress bar to indicate that something is happening.
        }
        $this->log()->notice($workflow->getMessage());
    }

Usage Example

 /**
  * Tests the solr:enable command
  */
 public function testEnableSolr()
 {
     $workflow = $this->getMockBuilder(Workflow::class)->disableOriginalConstructor()->getMock();
     // workflow succeeded
     $workflow->expects($this->once())->method('checkProgress')->willReturn(true);
     $workflow->expects($this->once())->method('getMessage')->willReturn('successful workflow');
     $this->solr = $this->getMockBuilder(Solr::class)->disableOriginalConstructor()->getMock();
     $this->solr->expects($this->once())->method('enable');
     $this->site->expects($this->once())->method('converge')->willReturn($workflow);
     $this->site->method('getSolr')->willReturn($this->solr);
     $this->logger->expects($this->at(0))->method('log')->with($this->equalTo('notice'), $this->equalTo('Solr enabled. Converging bindings.'));
     $this->logger->expects($this->at(1))->method('log')->with($this->equalTo('notice'), $this->equalTo('successful workflow'));
     $command = new EnableCommand();
     $command->setSites($this->sites);
     $command->setLogger($this->logger);
     $command->enable('mysite');
 }
EnableCommand