1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
namespace Resta\Console\Source\Test;
|
4
|
|
|
|
5
|
|
|
use Resta\Support\PhpUnitManager;
|
6
|
|
|
use Resta\Support\SimpleXmlManager;
|
7
|
|
|
use Resta\Console\ConsoleOutputter;
|
8
|
|
|
use Resta\Console\ConsoleListAccessor;
|
9
|
|
|
use Symfony\Component\Process\Process;
|
10
|
|
|
use Symfony\Component\Process\Exception\ProcessFailedException;
|
11
|
|
|
|
12
|
|
|
class Test extends ConsoleOutputter
|
13
|
|
|
{
|
14
|
|
|
use ConsoleListAccessor;
|
15
|
|
|
|
16
|
|
|
/**
|
17
|
|
|
* @var $type
|
|
|
|
|
18
|
|
|
*/
|
19
|
|
|
public $type = 'test';
|
20
|
|
|
|
21
|
|
|
/**
|
22
|
|
|
* @var $define
|
|
|
|
|
23
|
|
|
*/
|
24
|
|
|
public $define = 'creates test file for application';
|
25
|
|
|
|
26
|
|
|
/**
|
27
|
|
|
* @var $commandRule
|
|
|
|
|
28
|
|
|
*/
|
29
|
|
|
public $commandRule = ['create'=>['test']];
|
30
|
|
|
|
31
|
|
|
/**
|
32
|
|
|
* @method generate
|
33
|
|
|
* @return mixed
|
34
|
|
|
*/
|
35
|
|
|
public function create()
|
36
|
|
|
{
|
37
|
|
|
$type = (isset($this->argument['type'])) ? $this->argument['type'] : 'Unit';
|
38
|
|
|
|
39
|
|
|
if(!file_exists(app()->path()->tests())){
|
40
|
|
|
$this->directory['test'] = app()->path()->tests();
|
41
|
|
|
$this->file->makeDirectory($this);
|
42
|
|
|
}
|
43
|
|
|
|
44
|
|
|
$dirWithType = app()->path()->tests().'/'.$type;
|
45
|
|
|
|
46
|
|
|
|
47
|
|
|
if(!file_exists($dirWithType)){
|
48
|
|
|
$this->directory['testType'] = $dirWithType;
|
49
|
|
|
$this->file->makeDirectory($this);
|
50
|
|
|
}
|
51
|
|
|
|
52
|
|
|
$this->argument['testPath'] = app()->namespace()->tests();
|
53
|
|
|
$this->argument['testDirPath'] = app()->namespace()->tests().'\\'.$type;
|
54
|
|
|
$this->argument['testNamespace'] = ucfirst($this->argument['test']).'Test';
|
55
|
|
|
$this->argument['projectName'] = strtolower($this->projectName());
|
56
|
|
|
|
57
|
|
|
$this->touch['test/test']= $dirWithType.'/'.$this->argument['testNamespace'].'.php';
|
58
|
|
|
|
59
|
|
|
|
60
|
|
|
$this->file->touch($this);
|
61
|
|
|
|
62
|
|
|
echo $this->classical(' > Test file called as "'.$this->argument['test'].'" has been successfully created in the '.$dirWithType.'');
|
63
|
|
|
}
|
64
|
|
|
|
65
|
|
|
/**
|
66
|
|
|
* @return mixed
|
67
|
|
|
*/
|
68
|
|
|
public function publish()
|
69
|
|
|
{
|
70
|
|
|
$phpunit = ''.root.'/phpunit.xml';
|
71
|
|
|
|
72
|
|
|
$xml = new SimpleXmlManager($phpunit);
|
73
|
|
|
|
74
|
|
|
$array = $xml->toArray();
|
75
|
|
|
|
76
|
|
|
$new = (new PhpUnitManager($array))->add(strtolower($this->projectName()),'directory',
|
77
|
|
|
str_replace(root.''.DIRECTORY_SEPARATOR,"",app()->path()->tests()));
|
78
|
|
|
|
79
|
|
|
$newDataXml = $xml->toXml($new);
|
80
|
|
|
|
81
|
|
|
app()->get('fileSystem')->writeFile($phpunit,$newDataXml);
|
82
|
|
|
|
83
|
|
|
echo $this->classical(' > phpunit.xml file has been updated');
|
84
|
|
|
}
|
85
|
|
|
|
86
|
|
|
/**
|
87
|
|
|
* @return mixed
|
88
|
|
|
*/
|
89
|
|
|
public function run()
|
90
|
|
|
{
|
91
|
|
|
$process = new Process(['vendor'.DIRECTORY_SEPARATOR.'bin'.DIRECTORY_SEPARATOR.'phpunit','--group',strtolower($this->projectName())]);
|
92
|
|
|
$process->setTty(true);
|
93
|
|
|
|
94
|
|
|
try {
|
95
|
|
|
$process->mustRun();
|
96
|
|
|
|
97
|
|
|
echo $process->getOutput();
|
98
|
|
|
} catch (ProcessFailedException $exception) {
|
99
|
|
|
echo $exception->getMessage();
|
100
|
|
|
}
|
101
|
|
|
}
|
102
|
|
|
|
103
|
|
|
public function phpUnit()
|
104
|
|
|
{
|
105
|
|
|
|
106
|
|
|
}
|
107
|
|
|
} |