Beispiel #1
0
 /**
  * Get the Composer instance.
  *
  * @param  bool               $required
  * @param  array|string|null  $config
  * @return Composer\Composer
  */
 public function getComposer($required = true, $config = null)
 {
     if (is_null($this->composer)) {
         try {
             $this->composer = Factory::create($this->consoleIo, $config);
         } catch (\InvalidArgumentException $e) {
             $this->consoleIo->write($e->getMessage());
             exit(1);
         }
     }
     return $this->composer;
 }
Beispiel #2
0
 public function testWrite()
 {
     $inputMock = $this->getMock('Symfony\\Component\\Console\\Input\\InputInterface');
     $outputMock = $this->getMock('Symfony\\Component\\Console\\Output\\OutputInterface');
     $outputMock->expects($this->once())->method('write')->with($this->equalTo('some information about something'), $this->equalTo(false));
     $helperMock = $this->getMock('Symfony\\Component\\Console\\Helper\\HelperSet');
     $consoleIO = new ConsoleIO($inputMock, $outputMock, $helperMock);
     $consoleIO->write('some information about something', false);
 }
Beispiel #3
0
 public function testOverwrite()
 {
     $inputMock = $this->getMock('Symfony\\Component\\Console\\Input\\InputInterface');
     $outputMock = $this->getMock('Symfony\\Component\\Console\\Output\\OutputInterface');
     $outputMock->expects($this->at(0))->method('write')->with($this->equalTo('something (<question>strlen = 23</question>)'));
     $outputMock->expects($this->at(1))->method('write')->with($this->equalTo(str_repeat("", 23)), $this->equalTo(false));
     $outputMock->expects($this->at(2))->method('write')->with($this->equalTo('shorter (<comment>12</comment>)'), $this->equalTo(false));
     $outputMock->expects($this->at(3))->method('write')->with($this->equalTo(str_repeat(' ', 11)), $this->equalTo(false));
     $outputMock->expects($this->at(4))->method('write')->with($this->equalTo(str_repeat("", 11)), $this->equalTo(false));
     $outputMock->expects($this->at(5))->method('write')->with($this->equalTo(str_repeat("", 12)), $this->equalTo(false));
     $outputMock->expects($this->at(6))->method('write')->with($this->equalTo('something longer than initial (<info>34</info>)'));
     $helperMock = $this->getMock('Symfony\\Component\\Console\\Helper\\HelperSet');
     $consoleIO = new ConsoleIO($inputMock, $outputMock, $helperMock);
     $consoleIO->write('something (<question>strlen = 23</question>)');
     $consoleIO->overwrite('shorter (<comment>12</comment>)', false);
     $consoleIO->overwrite('something longer than initial (<info>34</info>)');
 }
Beispiel #4
0
 public static function migrateDatabase(Event $event = null, $testing = false)
 {
     if ($event) {
         // Use the event's IO
         $io = $event->getIO();
         $arguments = $event->getArguments();
         $testingArguments = array('testing', '--testing', '-t');
         $testing = count(array_intersect($arguments, $testingArguments)) > 0;
     } else {
         // Create our own IO
         $input = new ArrayInput(array());
         $output = new ConsoleOutput();
         $helperSet = new HelperSet(array(new QuestionHelper()));
         $io = new ConsoleIO($input, $output, $helperSet);
     }
     try {
         $config = self::getDatabaseConfig($testing);
     } catch (\Exception $e) {
         $io->write("<bg=red>\n\n [WARNING] " . $e->getMessage() . ", the database won't be updated\n</>");
         return;
     }
     // If the database doesn't exist, ask the user to create it and perform
     // the necessary migrations (unless the user didn't agree to
     // create the database)
     if (self::createDatabase($io, $config['host'], $config['username'], $config['password'], $config['database'])) {
         $io->write('');
         // newline
         $arguments = array('migrate', '-e' => $testing ? 'test' : 'main');
         $app = new PhinxApplication();
         $app->doRun(new ArrayInput($arguments), new ConsoleOutput());
     }
 }