Gush\Subscriber\GitDirectorySubscriber::initialize PHP Метод

initialize() публичный Метод

public initialize ( Symfony\Component\Console\Event\ConsoleCommandEvent $event )
$event Symfony\Component\Console\Event\ConsoleCommandEvent
    public function initialize(ConsoleCommandEvent $event)
    {
        /** @var GitDirectoryFeature|BaseCommand $command */
        $command = $event->getCommand();
        if (!$command instanceof GitDirectoryFeature) {
            return;
        }
        if (!$this->gitHelper->isGitDir()) {
            throw new UserException(sprintf('The "%s" command can only be executed from the root of a Git repository.', $command->getName()));
        }
    }

Usage Example

Пример #1
0
 /**
  * @test
  */
 public function throws_user_exception_when_not_in_git_directory()
 {
     $command = new GitDirectoryCommand();
     $commandEvent = new ConsoleCommandEvent($command, $this->createMock('Symfony\\Component\\Console\\Input\\InputInterface'), $this->createMock('Symfony\\Component\\Console\\Output\\OutputInterface'));
     $helper = $this->getGitHelper(false);
     $subscriber = new GitDirectorySubscriber($helper);
     $this->setExpectedException(UserException::class);
     $subscriber->initialize($commandEvent);
 }