Passed
Push — master ( 772daf...874f16 )
by Php Easy Api
03:18
created

Test::publish()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 16
rs 10
c 0
b 0
f 0
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
0 ignored issues
show
Documentation Bug introduced by
The doc comment $type at position 0 could not be parsed: Unknown type name '$type' at position 0 in $type.
Loading history...
18
     */
19
    public $type = 'test';
20
21
    /**
22
     * @var $define
0 ignored issues
show
Documentation Bug introduced by
The doc comment $define at position 0 could not be parsed: Unknown type name '$define' at position 0 in $define.
Loading history...
23
     */
24
    public $define = 'creates test file for application';
25
26
    /**
27
     * @var $commandRule
0 ignored issues
show
Documentation Bug introduced by
The doc comment $commandRule at position 0 could not be parsed: Unknown type name '$commandRule' at position 0 in $commandRule.
Loading history...
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
}