Passed
Push — master ( d82328...2285e3 )
by Kevin
01:54
created

FixtureForCallbackTaskTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 8
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
eloc 1
c 1
b 0
f 1
dl 0
loc 8
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 2 1
A staticMethod() 0 2 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 has_default_description()
17
    {
18
        $this->assertRegExp('#^\(callable\) Zenstruck\\\\ScheduleBundle\\\\Tests\\\\Schedule\\\\Task\\\\CallbackTaskTest\:\d+$#', (new CallbackTask(function () {}))->getDescription());
19
        $this->assertRegExp('#^\(callable\) Zenstruck\\\\ScheduleBundle\\\\Tests\\\\Schedule\\\\Task\\\\CallbackTaskTest\:\d+$#', (new CallbackTask([$this, __METHOD__]))->getDescription());
20
        $this->assertRegExp('#^\(callable\) Zenstruck\\\\ScheduleBundle\\\\Tests\\\\Schedule\\\\Task\\\\FixtureForCallbackTaskTest\:\d+$#', (new CallbackTask(new FixtureForCallbackTaskTest()))->getDescription());
21
        $this->assertRegExp('#^\(callable\) Zenstruck\\\\ScheduleBundle\\\\Tests\\\\Schedule\\\\Task\\\\FixtureForCallbackTaskTest\:\d+$#', (new CallbackTask([FixtureForCallbackTaskTest::class, 'staticMethod']))->getDescription());
22
        $this->assertSame('(callable) '.__NAMESPACE__.'\callback_task_test_function', (new CallbackTask(__NAMESPACE__.'\callback_task_test_function'))->getDescription());
23
    }
24
25
    /**
26
     * @test
27
     */
28
    public function can_create_successful_result()
29
    {
30
        $result = (new CallbackTask(function () {}))();
31
32
        $this->assertTrue($result->isSuccessful());
33
        $this->assertNull($result->getOutput());
34
    }
35
36
    /**
37
     * @test
38
     * @dataProvider outputProvider
39
     */
40
    public function stringifies_output($output, $expectedOutput)
41
    {
42
        $result = (new CallbackTask(function () use ($output) { return $output; }))();
43
44
        $this->assertTrue($result->isSuccessful());
45
        $this->assertSame($expectedOutput, $result->getOutput());
46
    }
47
48
    public static function outputProvider()
49
    {
50
        $stringClass = new class() {
51
            public function __toString(): string
52
            {
53
                return 'as string';
54
            }
55
        };
56
57
        return [
58
            [null, null],
59
            [10, '10'],
60
            [true, '1'],
61
            [false, ''],
62
            [new \stdClass(), '[object] stdClass'],
63
            [['foo'], '(array)'],
64
            [$stringClass, 'as string'],
65
        ];
66
    }
67
}
68
69
class FixtureForCallbackTaskTest
70
{
71
    public function __invoke()
72
    {
73
    }
74
75
    public static function staticMethod()
76
    {
77
    }
78
}
79
80
function callback_task_test_function()
81
{
82
}
83