1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Zenstruck\ScheduleBundle\Tests\Schedule\Task; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
|
|
|
|
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 task_has_context() |
29
|
|
|
{ |
30
|
|
|
$this->assertRegExp('#Zenstruck\\\\ScheduleBundle\\\\Tests\\\\Schedule\\\\Task\\\\CallbackTaskTest\:\d+$#', (new CallbackTask(function () {}))->getContext()['Callable']); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @test |
35
|
|
|
*/ |
36
|
|
|
public function can_create_successful_result() |
37
|
|
|
{ |
38
|
|
|
$result = (new CallbackTask(function () {}))(); |
39
|
|
|
|
40
|
|
|
$this->assertTrue($result->isSuccessful()); |
41
|
|
|
$this->assertNull($result->getOutput()); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @test |
46
|
|
|
* @dataProvider outputProvider |
47
|
|
|
*/ |
48
|
|
|
public function stringifies_output($output, $expectedOutput) |
49
|
|
|
{ |
50
|
|
|
$result = (new CallbackTask(function () use ($output) { return $output; }))(); |
51
|
|
|
|
52
|
|
|
$this->assertTrue($result->isSuccessful()); |
53
|
|
|
$this->assertSame($expectedOutput, $result->getOutput()); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public static function outputProvider() |
57
|
|
|
{ |
58
|
|
|
$stringClass = new class() { |
59
|
|
|
public function __toString(): string |
60
|
|
|
{ |
61
|
|
|
return 'as string'; |
62
|
|
|
} |
63
|
|
|
}; |
64
|
|
|
|
65
|
|
|
return [ |
66
|
|
|
[null, null], |
67
|
|
|
[10, '10'], |
68
|
|
|
[true, '1'], |
69
|
|
|
[false, ''], |
70
|
|
|
[new \stdClass(), '[object] stdClass'], |
71
|
|
|
[['foo'], '(array)'], |
72
|
|
|
[$stringClass, 'as string'], |
73
|
|
|
]; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
class FixtureForCallbackTaskTest |
78
|
|
|
{ |
79
|
|
|
public function __invoke() |
80
|
|
|
{ |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public static function staticMethod() |
84
|
|
|
{ |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
function callback_task_test_function() |
89
|
|
|
{ |
90
|
|
|
} |
91
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths