1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Scabbia2 Testing Component |
4
|
|
|
* https://github.com/eserozvataf/scabbia2 |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
* |
9
|
|
|
* @link https://github.com/eserozvataf/scabbia2-testing for the canonical source repository |
10
|
|
|
* @copyright 2010-2016 Eser Ozvataf. (http://eser.ozvataf.com/) |
11
|
|
|
* @license http://www.apache.org/licenses/LICENSE-2.0 - Apache License, Version 2.0 |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Scabbia\Testing; |
15
|
|
|
|
16
|
|
|
use Scabbia\Formatters\FormatterInterface; |
17
|
|
|
use Scabbia\Tasks\TaskBase; |
18
|
|
|
use Scabbia\Testing\Testing; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* A small test implementation which helps us during the development of |
22
|
|
|
* Scabbia2 PHP Framework's itself and related production code |
23
|
|
|
* |
24
|
|
|
* @package Scabbia\Testing |
25
|
|
|
* @author Eser Ozvataf <[email protected]> |
26
|
|
|
* @since 2.0.0 |
27
|
|
|
*/ |
28
|
|
|
class TestTask extends TaskBase |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* Initializes a test task |
32
|
|
|
*/ |
33
|
|
|
public function __construct() |
34
|
|
|
{ |
35
|
|
|
parent::__construct(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Executes the task |
40
|
|
|
* |
41
|
|
|
* @param array $uParameters parameters |
42
|
|
|
* @param FormatterInterface $uFormatter formatter class |
43
|
|
|
* |
44
|
|
|
* @return int exit code |
45
|
|
|
*/ |
46
|
|
|
public function executeTask(array $uParameters, FormatterInterface $uFormatter) |
47
|
|
|
{ |
48
|
|
|
// TODO populate fixtures |
49
|
|
|
$tFixtures = []; |
50
|
|
|
|
51
|
|
|
Testing::coverageStart(); |
52
|
|
|
$tExitCode = Testing::runUnitTests($tFixtures, $uFormatter); |
53
|
|
|
$tCoverageReport = Testing::coverageStop(); |
54
|
|
|
|
55
|
|
|
if ($tCoverageReport !== null) { |
56
|
|
|
$tCoverage = round($tCoverageReport["total"]["percentage"], 2) . "%"; |
57
|
|
|
} else { |
58
|
|
|
$tCoverage = "unknown"; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$uFormatter->writeColor("green", sprintf("Code Coverage = %s", $tCoverage)); |
62
|
|
|
$uFormatter->writeColor("yellow", "done."); |
63
|
|
|
|
64
|
|
|
return $tExitCode; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Returns the usage form and list of available parameters |
69
|
|
|
* |
70
|
|
|
* @param FormatterInterface $uFormatter formatter class |
71
|
|
|
* |
72
|
|
|
* @return void |
73
|
|
|
*/ |
74
|
|
|
public function help(FormatterInterface $uFormatter) |
75
|
|
|
{ |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|