Ejemplo n.º 1
0
 public function testGetServices()
 {
     $samurai = new Samurai(new Application());
     foreach ($samurai->getServices()->keys() as $key) {
         $this->assertNotNull($samurai->getServices()[$key]);
     }
 }
Ejemplo n.º 2
0
 public function testExecuteInstall()
 {
     $executor = $this->getMock('TRex\\Cli\\Executor');
     $executor->expects($this->any())->method('flush')->will($this->returnValue(0));
     $questionHelper = $this->getMock('Symfony\\Component\\Console\\Helper\\QuestionHelper', array('ask'));
     $questionHelper->expects($this->any())->method('ask')->will($this->returnValue(true));
     $samurai = new Samurai(new Application(), $this->provideServices($executor, $questionHelper));
     $command = $samurai->getApplication()->find('module');
     $commandTester = new CommandTester($command);
     $commandTester->execute(['command' => $command->getName(), 'action' => 'install']);
     $this->assertContains("Starting modules installation\n", $commandTester->getDisplay(true));
 }
Ejemplo n.º 3
0
 /**
  * @depends testExecuteDeleteNoConfirm
  */
 public function testExecuteDeleteConfirm()
 {
     $questionHelper = $this->getMock('Symfony\\Component\\Console\\Helper\\QuestionHelper', array('ask'));
     $questionHelper->expects($this->at(0))->method('ask')->will($this->returnValue(true));
     $samurai = new Samurai(new Application(), $this->provideServices($questionHelper));
     $alias = $samurai->getServices()['alias_manager']->getLocal();
     $this->assertArrayHasKey('test', $alias);
     $command = $samurai->getApplication()->find('alias');
     $commandTester = new CommandTester($command);
     $commandTester->execute(['command' => $command->getName(), 'action' => 'rm', 'name' => 'test']);
     $alias = $samurai->getServices()['alias_manager']->getLocal();
     $this->assertArrayNotHasKey('test', $alias);
 }
Ejemplo n.º 4
0
 public function testFilled()
 {
     $executor = $this->getMock('TRex\\Cli\\Executor');
     $executor->expects($this->any())->method('flush')->will($this->returnValue(0));
     $questionHelper = $this->getMock('Symfony\\Component\\Console\\Helper\\QuestionHelper', array('ask'));
     $questionHelper->expects($this->at(0))->method('ask')->will($this->returnValue('vendor/package'));
     $questionHelper->expects($this->at(1))->method('ask')->will($this->returnValue('desc'));
     $questionHelper->expects($this->at(2))->method('ask')->will($this->returnValue('http://website.com'));
     $questionHelper->expects($this->at(3))->method('ask')->will($this->returnValue(' k1 , k2'));
     $questionHelper->expects($this->at(4))->method('ask')->will($this->returnValue(true));
     //confirm git user
     $questionHelper->expects($this->at(5))->method('ask')->will($this->returnValue(true));
     //add a other user
     $questionHelper->expects($this->at(6))->method('ask')->will($this->returnValue(new Author('add.name <*****@*****.**>')));
     //set author
     $questionHelper->expects($this->at(7))->method('ask')->will($this->returnValue(false));
     //do not add a other user
     $questionHelper->expects($this->at(8))->method('ask')->will($this->returnValue(true));
     //add a package
     $questionHelper->expects($this->at(9))->method('ask')->will($this->returnValue('vendor\\namespace'));
     //add a namespace
     $questionHelper->expects($this->at(10))->method('ask')->will($this->returnValue('src/,tests/,test/'));
     //add dirs
     $questionHelper->expects($this->at(11))->method('ask')->will($this->returnValue(false));
     //do not add another namespace
     $git = $this->getMock('PHPGit\\Git', array('config'));
     $git->expects($this->once())->method('config')->will($this->returnValue(['user.name' => 'git.name', 'user.email' => '*****@*****.**']));
     $application = new Application();
     $samurai = new Samurai($application, $this->provideServices($questionHelper, $git, false), $executor);
     $command = $application->find('new');
     $command->getHelperSet()->set($questionHelper, 'question');
     $commandTester = new CommandTester($command);
     $commandTester->execute(['command' => $command->getName(), 'bootstrap' => 'vendor/bootstrap', 'version' => '1.0.0', '--dir' => 'dir/path', '--no-module' => true]);
     $this->assertRegExp('/Installing project vendor\\/package from vendor\\/bootstrap/', $commandTester->getDisplay());
     $this->assertRegExp('/Initializing composer config/', $commandTester->getDisplay());
     $this->assertNotContains("Running 2 module(s)", $commandTester->getDisplay());
     $this->assertRegExp('/Generated by Samurai in \\d+\\.\\d{2} sec. Banzai!/', $commandTester->getDisplay());
     /**
      * @var Project $project
      */
     $project = $samurai->getServices()['project'];
     $this->assertSame('vendor/package', $project->getName());
     $this->assertSame('vendor/bootstrap', $project->getBootstrap()->getPackage());
     $this->assertSame('1.0.0', $project->getBootstrap()->getVersion());
     $this->assertSame(getcwd() . DIRECTORY_SEPARATOR . 'dir/path', $project->getDirectoryPath());
     $this->assertSame('desc', $project->getDescription());
     $this->assertSame('http://website.com', $project->getHomepage());
     $this->assertSame(['k1', 'k2'], $project->getKeywords());
     $this->assertSame('git.name <*****@*****.**>', (string) $project->getAuthors()[0]);
     $this->assertSame('add.name <*****@*****.**>', (string) $project->getAuthors()[1]);
     $this->assertSame('vendor\\namespace\\', $project->getPackages()[0]->getNamespace());
     $this->assertSame(['src/', 'tests/', 'test/'], $project->getPackages()[0]->getPathList());
 }