-
Notifications
You must be signed in to change notification settings - Fork 11.1k
/
Copy pathConsoleEventSchedulerTest.php
119 lines (94 loc) · 4.21 KB
/
ConsoleEventSchedulerTest.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
<?php
namespace Illuminate\Tests\Console;
use Mockery as m;
use PHPUnit\Framework\TestCase;
use Illuminate\Container\Container;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Console\Scheduling\EventMutex;
use Illuminate\Console\Scheduling\SchedulingMutex;
class ConsoleEventSchedulerTest extends TestCase
{
public function setUp()
{
parent::setUp();
$container = Container::getInstance();
$container->instance('Illuminate\Console\Scheduling\EventMutex', m::mock('Illuminate\Console\Scheduling\CacheEventMutex'));
$container->instance('Illuminate\Console\Scheduling\SchedulingMutex', m::mock('Illuminate\Console\Scheduling\CacheSchedulingMutex'));
$container->instance(
'Illuminate\Console\Scheduling\Schedule', $this->schedule = new Schedule(m::mock('Illuminate\Console\Scheduling\EventMutex'))
);
}
public function tearDown()
{
m::close();
}
public function testMutexCanReceiveCustomStore()
{
Container::getInstance()->make(EventMutex::class)->shouldReceive('useStore')->once()->with('test');
Container::getInstance()->make(SchedulingMutex::class)->shouldReceive('useStore')->once()->with('test');
$this->schedule->useCache('test');
}
public function testExecCreatesNewCommand()
{
$escape = '\\' === DIRECTORY_SEPARATOR ? '"' : '\'';
$escapeReal = '\\' === DIRECTORY_SEPARATOR ? '\\"' : '"';
$schedule = $this->schedule;
$schedule->exec('path/to/command');
$schedule->exec('path/to/command -f --foo="bar"');
$schedule->exec('path/to/command', ['-f']);
$schedule->exec('path/to/command', ['--foo' => 'bar']);
$schedule->exec('path/to/command', ['-f', '--foo' => 'bar']);
$schedule->exec('path/to/command', ['--title' => 'A "real" test']);
$schedule->exec('path/to/command', [['one', 'two']]);
$schedule->exec('path/to/command', ['-1 minute']);
$events = $schedule->events();
$this->assertEquals('path/to/command', $events[0]->command);
$this->assertEquals('path/to/command -f --foo="bar"', $events[1]->command);
$this->assertEquals('path/to/command -f', $events[2]->command);
$this->assertEquals("path/to/command --foo={$escape}bar{$escape}", $events[3]->command);
$this->assertEquals("path/to/command -f --foo={$escape}bar{$escape}", $events[4]->command);
$this->assertEquals("path/to/command --title={$escape}A {$escapeReal}real{$escapeReal} test{$escape}", $events[5]->command);
$this->assertEquals("path/to/command {$escape}one{$escape} {$escape}two{$escape}", $events[6]->command);
$this->assertEquals("path/to/command {$escape}-1 minute{$escape}", $events[7]->command);
}
public function testCommandCreatesNewArtisanCommand()
{
$escape = '\\' === DIRECTORY_SEPARATOR ? '"' : '\'';
$schedule = $this->schedule;
$schedule->command('queue:listen');
$schedule->command('queue:listen --tries=3');
$schedule->command('queue:listen', ['--tries' => 3]);
$events = $schedule->events();
$binary = $escape.PHP_BINARY.$escape;
$this->assertEquals($binary.' artisan queue:listen', $events[0]->command);
$this->assertEquals($binary.' artisan queue:listen --tries=3', $events[1]->command);
$this->assertEquals($binary.' artisan queue:listen --tries=3', $events[2]->command);
}
public function testCreateNewArtisanCommandUsingCommandClass()
{
$escape = '\\' === DIRECTORY_SEPARATOR ? '"' : '\'';
$schedule = $this->schedule;
$schedule->command(ConsoleCommandStub::class, ['--force']);
$events = $schedule->events();
$binary = $escape.PHP_BINARY.$escape;
$this->assertEquals($binary.' artisan foo:bar --force', $events[0]->command);
}
}
class FooClassStub
{
protected $schedule;
public function __construct(Schedule $schedule)
{
$this->schedule = $schedule;
}
}
class ConsoleCommandStub extends \Illuminate\Console\Command
{
protected $signature = 'foo:bar';
protected $foo;
public function __construct(FooClassStub $foo)
{
parent::__construct();
$this->foo = $foo;
}
}