|
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
|
|
|
|
|
38
|
|
|
if(!file_exists(app()->path()->tests())){
|
|
39
|
|
|
$this->directory['test'] = app()->path()->tests();
|
|
40
|
|
|
$this->file->makeDirectory($this);
|
|
41
|
|
|
}
|
|
42
|
|
|
|
|
43
|
|
|
$this->argument['testPath'] = app()->namespace()->tests();
|
|
44
|
|
|
$this->argument['testNamespace'] = ucfirst($this->argument['test']);
|
|
45
|
|
|
$this->argument['projectName'] = strtolower($this->projectName());
|
|
46
|
|
|
|
|
47
|
|
|
$this->touch['test/test']= app()->path()->tests().'/'.ucfirst($this->argument['test']).'.php';
|
|
48
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
$this->file->touch($this);
|
|
51
|
|
|
|
|
52
|
|
|
echo $this->classical(' > Test file called as "'.$this->argument['test'].'" has been successfully created in the '.app()->namespace()->tests().'');
|
|
53
|
|
|
}
|
|
54
|
|
|
|
|
55
|
|
|
/**
|
|
56
|
|
|
* @return mixed
|
|
57
|
|
|
*/
|
|
58
|
|
|
public function publish()
|
|
59
|
|
|
{
|
|
60
|
|
|
$phpunit = ''.root.'/phpunit.xml';
|
|
61
|
|
|
|
|
62
|
|
|
$xml = new SimpleXmlManager($phpunit);
|
|
63
|
|
|
|
|
64
|
|
|
$array = $xml->toArray();
|
|
65
|
|
|
|
|
66
|
|
|
$new = (new PhpUnitManager($array))->add(strtolower($this->projectName()),'directory',
|
|
67
|
|
|
str_replace(root.''.DIRECTORY_SEPARATOR,"",app()->path()->tests()));
|
|
68
|
|
|
|
|
69
|
|
|
$newDataXml = $xml->toXml($new);
|
|
70
|
|
|
|
|
71
|
|
|
app()->get('fileSystem')->writeFile($phpunit,$newDataXml);
|
|
72
|
|
|
|
|
73
|
|
|
echo $this->classical(' > phpunit.xml file has been updated');
|
|
74
|
|
|
}
|
|
75
|
|
|
|
|
76
|
|
|
/**
|
|
77
|
|
|
* @return mixed
|
|
78
|
|
|
*/
|
|
79
|
|
|
public function run()
|
|
80
|
|
|
{
|
|
81
|
|
|
$process = new Process(['vendor'.DIRECTORY_SEPARATOR.'bin'.DIRECTORY_SEPARATOR.'phpunit','--group',strtolower($this->projectName())]);
|
|
82
|
|
|
|
|
83
|
|
|
try {
|
|
84
|
|
|
$process->mustRun();
|
|
85
|
|
|
|
|
86
|
|
|
echo $process->getOutput();
|
|
87
|
|
|
} catch (ProcessFailedException $exception) {
|
|
88
|
|
|
echo $exception->getMessage();
|
|
89
|
|
|
}
|
|
90
|
|
|
}
|
|
91
|
|
|
} |