mageekguy\atoum\test\engines\concurrent: lines coverage

62% of 554

OPs

66% of 106

Lines

39% of 82

Branches

0% of 4124

Paths
Method OPs OPs % Lines Line % Branches Branches % Paths Path %
mageekguy\atoum\test\engines\concurrent::__construct() 12 100% 4 100% 1 0% 1 100%
mageekguy\atoum\test\engines\concurrent::setScoreFactory() 12 100% 2 100% 1 100% 1 100%
mageekguy\atoum\test\engines\concurrent::getScoreFactory() 6 100% 1 100% 1 100% 1 100%
mageekguy\atoum\test\engines\concurrent::setPhp() 16 100% 2 100% 1 100% 1 100%
mageekguy\atoum\test\engines\concurrent::getPhp() 6 100% 2 100% 1 100% 1 100%
mageekguy\atoum\test\engines\concurrent::isAsynchronous() 6 100% 1 100% 1 100% 1 100%
mageekguy\atoum\test\engines\concurrent::run() 325 58% 72 61% 54 30% 4096 0%
mageekguy\atoum\test\engines\concurrent::getScore() 171 55% 22 64% 22 50% 22 14%
#
1
<?php
2

                    
3
namespace mageekguy\atoum\test\engines;
4

                    
5
use
6
	mageekguy\atoum,
7
	mageekguy\atoum\test,
8
	mageekguy\atoum\exceptions
9
;
10

                    
11
class concurrent extends test\engine
12
{
13
	protected $scoreFactory = null;
14
	protected $php = null;
15
	protected $test = null;
16
	protected $method = '';
17

                    
18
	public function __construct()100%
19
	{
20
		$this
21
			->setScoreFactory()
22
			->setPhp()
23
		;
24
	}
25

                    
26
	public function setScoreFactory(\closure $factory = null)100%
27
	{
28
		$this->scoreFactory = $factory ?: function() { return new atoum\score(); };
29

                    
30
		return $this;
31
	}
32

                    
33
	public function getScoreFactory()100%
34
	{
35
		return $this->scoreFactory;
36
	}
37

                    
38
	public function setPhp(atoum\php $php = null)100%
39
	{
40
		$this->php = $php ?: new atoum\php();
41

                    
42
		return $this;
43
	}
44

                    
45
	public function getPhp()100%
46
	{
47
		return $this->php;
48
	}
49

                    
50
	public function isAsynchronous()100%
51
	{
52
		return true;
53
	}
54

                    
55
	public function run(atoum\test $test)61%
56
	{
57
		$currentTestMethod = $test->getCurrentMethod();
58

                    
59
		if ($currentTestMethod !== null)
60
		{
61
			$this->test = $test;
62
			$this->method = $currentTestMethod;
63

                    
64
			$phpPath = $this->test->getPhpPath();
65

                    
66
			$phpCode =
67
				'<?php ' .
68
				'ob_start();' .
69
				'require \'' . atoum\directory . '/classes/autoloader.php\';'
70
			;
71

                    
72
			$bootstrapFile = $this->test->getBootstrapFile();
73

                    
74
			if ($bootstrapFile !== null)
75
			{
76
				$phpCode .=
77
					'$includer = new mageekguy\atoum\includer();' .
78
					'try { $includer->includePath(\'' . $bootstrapFile . '\'); }' .
79
					'catch (mageekguy\atoum\includer\exception $exception)' .
80
					'{ die(\'Unable to include bootstrap file \\\'' . $bootstrapFile . '\\\'\'); }'
81
				;
82
			}
83

                    
84
			$phpCode .=
85
				'require \'' . $this->test->getPath() . '\';' .
86
				'$test = new ' . $this->test->getClass() . '();' .
87
				'$test->setLocale(new ' . get_class($this->test->getLocale()) . '(' . $this->test->getLocale()->get() . '));' .
88
				'$test->setPhpPath(\'' . $phpPath . '\');'
89
			;
90

                    
91
			if ($this->test->debugModeIsEnabled() === true)
92
			{
93
				$phpCode .= '$test->enableDebugMode();';
94
			}
95

                    
96
			if ($this->test->codeCoverageIsEnabled() === false)
97
			{
98
				$phpCode .= '$test->disableCodeCoverage();';
99
			}
100
			else
101
			{
102
				if ($this->test->branchCoverageIsEnabled() === true)
103
				{
104
					$phpCode .= '$test->enableBranchCoverage();';
105
				}
106

                    
107
				$phpCode .= '$coverage = $test->getCoverage();';
108

                    
109
				foreach ($this->test->getCoverage()->getExcludedMethods() as $excludedMethod)
110
				{
111
					$phpCode .= '$coverage->excludeMethod(\'' . $excludedMethod . '\');';
112
				}
113

                    
114
				foreach ($this->test->getCoverage()->getExcludedClasses() as $excludedClass)
115
				{
116
					$phpCode .= '$coverage->excludeClass(\'' . $excludedClass . '\');';
117
				}
118

                    
119
				foreach ($this->test->getCoverage()->getExcludedNamespaces() as $excludedNamespace)
120
				{
121
					$phpCode .= '$coverage->excludeNamespace(\'' . $excludedNamespace . '\');';
122
				}
123

                    
124
				foreach ($this->test->getCoverage()->getExcludedDirectories() as $excludedDirectory)
125
				{
126
					$phpCode .= '$coverage->excludeDirectory(\'' . $excludedDirectory . '\');';
127
				}
128
			}
129

                    
130
			if ($this->test->getMockGenerator()->undefinedMethodUsageIsAllowed() === false)
131
			{
132
				$phpCode .= '$test->getMockGenerator()->disallowUndefinedMethodUsage();';
133
			}
134

                    
135
			foreach ($test->getExtensions() as $extension)
136
			{
137
				$phpCode .= '$test->addExtension(new ' . get_class($extension) . ');';
138
			}
139

                    
140
			$phpCode .=
141
				'ob_end_clean();' .
142
				'mageekguy\atoum\scripts\runner::disableAutorun();' .
143
				'echo serialize($test->runTestMethod(\'' . $this->method . '\')->getScore());'
144
			;
145

                    
146
			$xdebugConfig = $test->getXdebugConfig();
147

                    
148
			if ($xdebugConfig !== null)
149
			{
150
				if (getenv('XDEBUG_CONFIG') !== false || ini_get('xdebug.remote_autostart') != 0)
151
				{
152
					throw new exceptions\runtime('XDEBUG_CONFIG variable must not be set or value of xdebug.remote_autostart must be 0 to use xdebug with concurrent engine');
153
				}
154

                    
155
				$this->php->XDEBUG_CONFIG = $xdebugConfig;
156
			}
157

                    
158
			$this->php
159
				->reset()
160
				->setBinaryPath($phpPath)
161
				->run($phpCode)
162
			;
163
		}
164

                    
165
		return $this;
166
	}
167

                    
168
	public function getScore()64%
169
	{
170
		$score = null;
171

                    
172
		if ($this->test !== null && $this->php->isRunning() === false)
173
		{
174
			$stdOut = $this->php->getStdout();
175

                    
176
			$score = @unserialize($stdOut);
177

                    
178
			if ($score instanceof atoum\score === false)
179
			{
180
				$score = call_user_func($this->scoreFactory)->addUncompletedMethod($this->test->getPath(), $this->test->getClass(), $this->method, $this->php->getExitCode(), $this->php->getStdOut());
181
			}
182

                    
183
			$stdErr = $this->php->getStderr();
184

                    
185
			if ($stdErr !== '')
186
			{
187
				if (preg_match_all('/([^:]+): (.+) in (.+) on line ([0-9]+)/', trim($stdErr), $errors, PREG_SET_ORDER) === 0)
188
				{
189
					$score->addError($this->test->getPath(), $this->test->getClass(), $this->method, null, 'UNKNOWN', $stdErr);
190
				}
191
				else foreach ($errors as $error)
192
				{
193
					$score->addError($this->test->getPath(), $this->test->getClass(), $this->method, null, $error[1], $error[2], $error[3], $error[4]);
194
				}
195
			}
196
		}
197

                    
198
		return $score;
199
	}
200
}