forked from laravel/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScheduleListCommandTest.php
148 lines (124 loc) · 6.87 KB
/
ScheduleListCommandTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
namespace Illuminate\Tests\Integration\Console\Scheduling;
use Illuminate\Console\Command;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Console\Scheduling\ScheduleListCommand;
use Illuminate\Support\Carbon;
use Illuminate\Support\ProcessUtils;
use Orchestra\Testbench\TestCase;
class ScheduleListCommandTest extends TestCase
{
public $schedule;
protected function setUp(): void
{
parent::setUp();
Carbon::setTestNow(now()->startOfYear());
ScheduleListCommand::resolveTerminalWidthUsing(fn () => 80);
$this->schedule = $this->app->make(Schedule::class);
}
public function testDisplayEmptySchedule()
{
$this->artisan(ScheduleListCommand::class)
->assertSuccessful()
->expectsOutputToContain('No scheduled tasks have been defined.');
}
public function testDisplaySchedule()
{
$this->schedule->command(FooCommand::class)->quarterly();
$this->schedule->command('inspire')->twiceDaily(14, 18);
$this->schedule->command('foobar', ['a' => 'b'])->everyMinute();
$this->schedule->job(FooJob::class)->everyMinute();
$this->schedule->job(new FooParamJob('test'))->everyMinute();
$this->schedule->job(FooJob::class)->name('foo-named-job')->everyMinute();
$this->schedule->job(new FooParamJob('test'))->name('foo-named-param-job')->everyMinute();
$this->schedule->command('inspire')->cron('0 9,17 * * *');
$this->schedule->command('inspire')->cron("0 10\t* * *");
$this->schedule->call(FooCall::class)->everyMinute();
$this->schedule->call([FooCall::class, 'fooFunction'])->everyMinute();
$this->schedule->call(fn () => '')->everyMinute();
$closureLineNumber = __LINE__ - 1;
$closureFilePath = __FILE__;
$this->artisan(ScheduleListCommand::class)
->assertSuccessful()
->expectsOutput(' 0 0 1 1-12/3 * php artisan foo:command .... Next Due: 3 months from now')
->expectsOutput(' 0 14,18 * * * php artisan inspire ........ Next Due: 14 hours from now')
->expectsOutput(' * * * * * php artisan foobar a='.ProcessUtils::escapeArgument('b').' ... Next Due: 1 minute from now')
->expectsOutput(' * * * * * Illuminate\Tests\Integration\Console\Scheduling\FooJob Next Due: 1 minute from now')
->expectsOutput(' * * * * * Illuminate\Tests\Integration\Console\Scheduling\FooParamJob Next Due: 1 minute from now')
->expectsOutput(' * * * * * foo-named-job .............. Next Due: 1 minute from now')
->expectsOutput(' * * * * * foo-named-param-job ........ Next Due: 1 minute from now')
->expectsOutput(' 0 9,17 * * * php artisan inspire ......... Next Due: 9 hours from now')
->expectsOutput(' 0 10 * * * php artisan inspire ........ Next Due: 10 hours from now')
->expectsOutput(' * * * * * Illuminate\Tests\Integration\Console\Scheduling\FooCall Next Due: 1 minute from now')
->expectsOutput(' * * * * * Closure at: Illuminate\Tests\Integration\Console\Scheduling\FooCall::fooFunction Next Due: 1 minute from now')
->expectsOutput(' * * * * * Closure at: '.$closureFilePath.':'.$closureLineNumber.' Next Due: 1 minute from now');
}
public function testDisplayScheduleWithSort()
{
$this->schedule->command(FooCommand::class)->quarterly();
$this->schedule->command('inspire')->twiceDaily(14, 18);
$this->schedule->command('foobar', ['a' => 'b'])->everyMinute();
$this->schedule->job(FooJob::class)->everyMinute();
$this->schedule->job(new FooParamJob('test'))->everyMinute();
$this->schedule->job(FooJob::class)->name('foo-named-job')->everyMinute();
$this->schedule->job(new FooParamJob('test'))->name('foo-named-param-job')->everyMinute();
$this->schedule->command('inspire')->cron('0 9,17 * * *');
$this->schedule->command('inspire')->cron("0 10\t* * *");
$this->schedule->call(FooCall::class)->everyMinute();
$this->schedule->call([FooCall::class, 'fooFunction'])->everyMinute();
$this->schedule->call(fn () => '')->everyMinute();
$closureLineNumber = __LINE__ - 1;
$closureFilePath = __FILE__;
$this->artisan(ScheduleListCommand::class, ['--next' => true])
->assertSuccessful()
->expectsOutput(' * * * * * php artisan foobar a='.ProcessUtils::escapeArgument('b').' ... Next Due: 1 minute from now')
->expectsOutput(' * * * * * Illuminate\Tests\Integration\Console\Scheduling\FooJob Next Due: 1 minute from now')
->expectsOutput(' * * * * * Illuminate\Tests\Integration\Console\Scheduling\FooParamJob Next Due: 1 minute from now')
->expectsOutput(' * * * * * foo-named-job .............. Next Due: 1 minute from now')
->expectsOutput(' * * * * * foo-named-param-job ........ Next Due: 1 minute from now')
->expectsOutput(' * * * * * Illuminate\Tests\Integration\Console\Scheduling\FooCall Next Due: 1 minute from now')
->expectsOutput(' * * * * * Closure at: Illuminate\Tests\Integration\Console\Scheduling\FooCall::fooFunction Next Due: 1 minute from now')
->expectsOutput(' * * * * * Closure at: '.$closureFilePath.':'.$closureLineNumber.' Next Due: 1 minute from now')
->expectsOutput(' 0 9,17 * * * php artisan inspire ......... Next Due: 9 hours from now')
->expectsOutput(' 0 10 * * * php artisan inspire ........ Next Due: 10 hours from now')
->expectsOutput(' 0 14,18 * * * php artisan inspire ........ Next Due: 14 hours from now')
->expectsOutput(' 0 0 1 1-12/3 * php artisan foo:command .... Next Due: 3 months from now');
}
public function testDisplayScheduleInVerboseMode()
{
$this->schedule->command(FooCommand::class)->everyMinute();
$this->artisan(ScheduleListCommand::class, ['-v' => true])
->assertSuccessful()
->expectsOutputToContain('Next Due: '.now()->setMinutes(1)->format('Y-m-d H:i:s P'))
->expectsOutput(' ⇁ This is the description of the command.');
}
protected function tearDown(): void
{
parent::tearDown();
putenv('SHELL_VERBOSITY');
ScheduleListCommand::resolveTerminalWidthUsing(null);
}
}
class FooCommand extends Command
{
protected $signature = 'foo:command';
protected $description = 'This is the description of the command.';
}
class FooJob
{
}
class FooParamJob
{
public function __construct($param)
{
}
}
class FooCall
{
public function __invoke(): void
{
}
public function fooFunction(): void
{
}
}