1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* PHPUnit plugin for HiDev. |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/hiqdev/hidev-phpunit |
6
|
|
|
* @package hidev-phpunit |
7
|
|
|
* @license BSD-3-Clause |
8
|
|
|
* @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace hidev\phpunit\components; |
12
|
|
|
|
13
|
|
|
use hidev\base\File; |
14
|
|
|
use hidev\handlers\BaseHandler; |
15
|
|
|
use Yii; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* PHPunit. |
19
|
|
|
*/ |
20
|
|
|
class Phpunit extends \hidev\base\Component |
21
|
|
|
{ |
22
|
|
|
protected $_version; |
23
|
|
|
|
24
|
|
|
protected $_bootstrapFile; |
25
|
|
|
|
26
|
|
|
public $colors; |
27
|
|
|
public $coverageText; |
28
|
|
|
public $coverageClover; |
29
|
|
|
|
30
|
|
|
public function touchBootstrap() |
31
|
|
|
{ |
32
|
|
|
if (!$this->getBootstrapFile()->exists()) { |
33
|
|
|
$this->getBootstrapFile()->save(); |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function getBootstrapFile() |
38
|
|
|
{ |
39
|
|
|
if ($this->_bootstrapFile === null) { |
40
|
|
|
$this->_bootstrapFile = Yii::createObject([ |
41
|
|
|
'class' => File::class, |
42
|
|
|
'template' => 'phpunit/bootstrap.twig', |
43
|
|
|
'path' => 'tests/_bootstrap.php', |
44
|
|
|
]); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
return $this->_bootstrapFile; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function prepareArgs($args = []) |
51
|
|
|
{ |
52
|
|
|
if ($this->coverageText) { |
53
|
|
|
$args[] = '--coverage-text'; |
54
|
|
|
} |
55
|
|
|
if ($this->coverageClover) { |
56
|
|
|
$args[] = '--coverage-clover=' . (is_string($this->coverageClover) ? $this->coverageClover : 'coverage.clover'); |
57
|
|
|
} |
58
|
|
|
if ($this->colors) { |
59
|
|
|
$args[] = '--colors' . (version_compare($this->getVersion(), '4.7.0', '>=') ? '=' . $this->colors : ''); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return $args; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function getVersion() |
66
|
|
|
{ |
67
|
|
|
if ($this->_version === null) { |
68
|
|
|
$this->_version = $this->detectVersion(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return $this->_version; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function detectVersion() |
75
|
|
|
{ |
76
|
|
|
$lines = $this->exec('phpunit', ['--version']); |
77
|
|
|
|
78
|
|
|
return explode(' ', $lines[0], 3)[1]; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
} |
82
|
|
|
|