Development

/tools/lime/branches/2.0-experimental/lib/LimeTestSuite.php

You must first sign up to be able to contribute.

root/tools/lime/branches/2.0-experimental/lib/LimeTestSuite.php

Revision 21237, 2.8 kB (checked in by bschussek, 4 years ago)

Renamed LimeOutputConsoleDetailed? to LimeOutputTap? and moved plan to the bottom to improve TAP compliancy when multiple test script results are displayed

  • Property svn:mergeinfo set to
  • Property svn:keywords set to Id
Line 
1 <?php
2
3 /*
4  * This file is part of the symfony framework.
5  *
6  * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
7  *
8  * This source file is subject to the MIT license that is bundled
9  * with this source code in the file LICENSE.
10  */
11
12 class LimeTestSuite extends LimeRegistration
13 {
14   protected
15     $options    = array(),
16     $executable = null,
17     $output     = null;
18
19   public function __construct(array $options = array())
20   {
21     $this->options = array_merge(array(
22       'base_dir'     => null,
23       'executable'   => null,
24       'output'       => 'summary',
25       'force_colors' => false,
26       'verbose'      => false,
27       'serialize'    => false,
28       'processes'    => 1,
29     ), $options);
30
31     foreach (LimeShell::parseArguments($GLOBALS['argv']) as $argument => $value)
32     {
33       $this->options[str_replace('-', '_', $argument)] = $value;
34     }
35
36     $this->options['base_dir'] = realpath($this->options['base_dir']);
37
38     if (is_string($this->options['output']))
39     {
40       $factory = new LimeOutputFactory($this->options);
41
42       $type = $this->options['output'];
43       $output = $factory->create($type);
44     }
45     else
46     {
47       $output = $this->options['output'];
48       $type = get_class($output);
49     }
50
51     if ($this->options['processes'] > 1 && !$output->supportsThreading())
52     {
53       throw new LogicException(sprintf('The output "%s" does not support multi-processing', $type));
54     }
55
56     $this->output = new LimeOutputInspectable($output);
57   }
58
59   public function run()
60   {
61     if (!count($this->files))
62     {
63       throw new Exception('You must register some test files before running them!');
64     }
65
66     // sort the files to be able to predict the order
67     sort($this->files);
68     reset($this->files);
69
70     $connectors = array();
71
72     for ($i = 0; $i < $this->options['processes']; ++$i)
73     {
74       $connectors[] = new LimeOutputPipe($this->output, array('focus', 'flush'));
75     }
76
77     do
78     {
79       $done = true;
80
81       foreach ($connectors as $connector)
82       {
83         if ($connector->done() && !is_null(key($this->files)))
84         {
85           // start the file explicitly in case the file contains syntax errors
86           $this->output->focus(current($this->files));
87           $connector->connect(current($this->files));
88
89           next($this->files);
90         }
91         else if (!$connector->done())
92         {
93           $this->output->focus($connector->getConnectedFile());
94         }
95
96         if (!$connector->done())
97         {
98           $connector->proceed();
99           $done = false;
100         }
101       }
102     }
103     while (!$done);
104
105     $this->output->flush();
106
107     $failed = $this->output->getFailed();
108     $errors = $this->output->getErrors();
109     $warnings = $this->output->getWarnings();
110     $skipped = $this->output->getSkipped();
111
112     return 0 == ($failed + $errors + $warnings + $skipped);
113   }
114 }
Note: See TracBrowser for help on using the browser.