Passed
Push — master ( 18c542...46352d )
by Kevin
02:34
created

CallbackTaskTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 17
c 0
b 0
f 0
dl 0
loc 42
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A can_create_successful_result() 0 6 1
outputProvider() 0 17 ?
A hp$0 ➔ __toString() 0 3 1
A stringifies_output() 0 6 1
A hp$0 ➔ outputProvider() 0 17 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 Zenstruck\ScheduleBundle\Schedule\Task\CallbackTask;
7
8
/**
9
 * @author Kevin Bond <[email protected]>
10
 */
11
final class CallbackTaskTest extends TestCase
12
{
13
    /**
14
     * @test
15
     */
16
    public function can_create_successful_result()
17
    {
18
        $result = (new CallbackTask(function () {}))();
19
20
        $this->assertTrue($result->isSuccessful());
21
        $this->assertNull($result->getOutput());
22
    }
23
24
    /**
25
     * @test
26
     * @dataProvider outputProvider
27
     */
28
    public function stringifies_output($output, $expectedOutput)
29
    {
30
        $result = (new CallbackTask(function () use ($output) { return $output; }))();
31
32
        $this->assertTrue($result->isSuccessful());
33
        $this->assertSame($expectedOutput, $result->getOutput());
34
    }
35
36
    public static function outputProvider()
37
    {
38
        $stringClass = new class() {
39
            public function __toString(): string
40
            {
41
                return 'as string';
42
            }
43
        };
44
45
        return [
46
            [null, null],
47
            [10, '10'],
48
            [true, '1'],
49
            [false, ''],
50
            [new \stdClass(), '[object] stdClass'],
51
            [['foo'], '(array)'],
52
            [$stringClass, 'as string'],
53
        ];
54
    }
55
}
56