Example #1
0
    public function testGroups()
    {
        $builder = new Builder();
        $builder->load_runfile($this->getFixture('groups.php'));
        $this->expectOutputString(<<<EOF
a:b
b:a
y:z:a

EOF
);
        $builder->get_application()->invoke('default');
    }
Example #2
0
 public function testCycleDetection()
 {
     $builder = new Builder();
     $builder->load_runfile($this->getFixture('Cycle.php'));
     $root_node = $builder->get_application()->root();
     $cycles = (new CycleDetector($root_node))->get_cycles();
     $this->assertCount(1, $cycles);
     $this->assertCount(3, $cycles[0]);
     $task_names = array_map(function ($task) {
         return $task->get_name();
     }, $cycles[0]);
     $this->assertContains('bleem', $task_names);
     $this->assertContains('baz', $task_names);
     $this->assertContains('foo', $task_names);
 }
Example #3
0
File: Bin.php Project: jaz303/phake
 public function execute($args)
 {
     try {
         //
         // Defaults
         $action = 'invoke';
         $task_names = array('default');
         $trace = false;
         $runfile = false;
         $run_safely = true;
         array_shift($args);
         $parser = new OptionParser($args);
         foreach ($parser->get_options() as $option => $value) {
             switch ($option) {
                 case 't':
                 case 'trace':
                     $trace = true;
                     break;
                 case 'T':
                 case 'tasks':
                     $action = 'list';
                     break;
                 case 'f':
                 case 'file':
                     $runfile = $value;
                     break;
                 case 'u':
                 case 'unsafe':
                     $run_safely = false;
                     break;
                 default:
                     throw new Exception("Unknown command line option '{$option}'");
             }
         }
         $cli_args = array();
         $cli_task_names = array();
         foreach ($parser->get_non_options() as $option) {
             if (strpos($option, '=') > 0) {
                 $cli_args[] = $option;
             } else {
                 $cli_task_names[] = $option;
             }
         }
         $cli_args = Utils::parse_args($cli_args);
         if (count($cli_task_names)) {
             $task_names = $cli_task_names;
         }
         $application = new Application();
         $builder = new Builder($application);
         //
         // Locate runfile
         if (!$runfile) {
             $runfile = $builder->resolve_runfile(getcwd());
             $directory = dirname($runfile);
             if (!@chdir($directory)) {
                 throw new Exception("Couldn't change to directory '{$directory}'");
             } else {
                 echo "(in {$directory})\n";
             }
         }
         $builder->load_runfile($runfile);
         //
         // Go, go, go
         $application->set_args($cli_args);
         $application->reset();
         if ($run_safely) {
             $does_cycle = $this->detect_and_display_cycles($application);
             if ($does_cycle) {
                 throw new TaskCycleFoundException();
             }
         }
         switch ($action) {
             case 'list':
                 $task_list = $application->get_task_list();
                 if (count($task_list)) {
                     $max = max(array_map('strlen', array_keys($task_list)));
                     foreach ($task_list as $name => $desc) {
                         echo str_pad($name, $max + 4) . $desc . "\n";
                     }
                 }
                 break;
             case 'invoke':
                 foreach ($task_names as $task_name) {
                     $application->invoke($task_name);
                 }
                 break;
         }
     } catch (TaskNotFoundException $tnfe) {
         $this->fatal($tnfe, sprintf("Don't know how to build task '%s'\n", $tnfe->getTaskName()), $trace);
     } catch (Exception $e) {
         $this->fatal($e, null, $trace);
     }
 }