Passed
Push — master ( 3ce531...7a6df5 )
by Kevin
02:21
created

ProcessTaskTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 2
Metric Value
wmc 5
eloc 19
c 3
b 0
f 2
dl 0
loc 57
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A can_add_a_process_instance() 0 7 1
A has_default_description() 0 4 1
A can_create_failed_result() 0 7 1
A can_create_successful_result() 0 7 1
A task_has_context() 0 7 1
1
<?php
2
3
namespace Zenstruck\ScheduleBundle\Tests\Schedule\Task;
4
5
use PHPUnit\Framework\TestCase;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Symfony\Component\Process\Process;
7
use Zenstruck\ScheduleBundle\Schedule\Task\ProcessTask;
8
9
/**
10
 * @author Kevin Bond <[email protected]>
11
 */
12
final class ProcessTaskTest extends TestCase
13
{
14
    /**
15
     * @test
16
     */
17
    public function has_default_description()
18
    {
19
        $this->assertSame('$(which php) -v', (new ProcessTask('$(which php) -v'))->getDescription());
20
        $this->assertSame('$(which php) -v', (new ProcessTask(Process::fromShellCommandline('$(which php) -v')))->getDescription());
21
    }
22
23
    /**
24
     * @test
25
     */
26
    public function can_create_successful_result()
27
    {
28
        $result = (new ProcessTask('$(which php) -v'))();
29
30
        $this->assertTrue($result->isSuccessful());
31
        $this->assertStringContainsString('PHP', $result->getOutput());
32
        $this->assertStringContainsString(PHP_VERSION, $result->getOutput());
33
    }
34
35
    /**
36
     * @test
37
     */
38
    public function can_create_failed_result()
39
    {
40
        $result = (new ProcessTask('sdfsdfsdf'))();
41
42
        $this->assertTrue($result->isFailure());
43
        $this->assertSame('Exit 127: Command not found', $result->getDescription());
44
        $this->assertSame("sh: 1: sdfsdfsdf: not found\n", $result->getOutput());
45
    }
46
47
    /**
48
     * @test
49
     */
50
    public function can_add_a_process_instance()
51
    {
52
        $result = (new ProcessTask(Process::fromShellCommandline('$(which php) -v')))();
53
54
        $this->assertTrue($result->isSuccessful());
55
        $this->assertStringContainsString('PHP', $result->getOutput());
56
        $this->assertStringContainsString(PHP_VERSION, $result->getOutput());
57
    }
58
59
    /**
60
     * @test
61
     */
62
    public function task_has_context()
63
    {
64
        $task = new ProcessTask('/foo/bar');
65
        $this->assertSame(['Command Line' => '/foo/bar', 'Command Timeout' => 60.0], $task->getContext());
66
67
        $task = new ProcessTask(Process::fromShellCommandline('/foo/bar')->setTimeout(30));
68
        $this->assertSame(['Command Line' => '/foo/bar', 'Command Timeout' => 30.0], $task->getContext());
69
    }
70
}
71