Repository navigation
Expand file tree
/
Copy pathQueueListFailedCommandTest.php
More file actions
176 lines (155 loc) · 6.13 KB
/
Copy pathQueueListFailedCommandTest.php
File metadata and controls
176 lines (155 loc) · 6.13 KB
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?php
namespace Illuminate\Tests\Queue;
use Illuminate\Foundation\Application;
use Illuminate\Queue\Console\ListFailedCommand;
use Illuminate\Queue\Failed\FailedJobProviderInterface;
use Mockery;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;
class QueueListFailedCommandTest extends TestCase
{
public function testQueuedListenerShowsUnderlyingListenerClassNotWrapper()
{
// CallQueuedListener is the wrapper class Laravel uses to dispatch
// queued event listeners. The legacy regex matched the wrapper out
// of data.command — payload.displayName carries the actual listener.
$output = $this->runListFailedCommandWith([
$this->fakeFailedJob([
'displayName' => 'App\\Listeners\\HandleStripeWebhookHandled',
'data' => [
'commandName' => 'Illuminate\\Events\\CallQueuedListener',
'command' => 'O:42:"Illuminate\\Events\\CallQueuedListener":3:{s:5:"class";s:43:"App\\Listeners\\HandleStripeWebhookHandled";s:6:"method";s:6:"handle";s:4:"data";a:0:{}}',
],
]),
]);
$this->assertStringContainsString('App\\Listeners\\HandleStripeWebhookHandled', $output);
$this->assertStringNotContainsString('CallQueuedListener', $output);
}
public function testRegularQueuedJobStillShowsJobClass()
{
// Regression: the common ShouldQueue path must keep showing the job class.
$output = $this->runListFailedCommandWith([
$this->fakeFailedJob([
'displayName' => 'App\\Jobs\\ProcessPodcast',
'data' => [
'commandName' => 'App\\Jobs\\ProcessPodcast',
'command' => 'O:25:"App\\Jobs\\ProcessPodcast":0:{}',
],
]),
]);
$this->assertStringContainsString('App\\Jobs\\ProcessPodcast', $output);
}
public function testLegacyPayloadWithoutDisplayNameFallsBackToRegex()
{
// Pre-5.6 failed_jobs rows have no displayName. The legacy regex path
// must still extract the first quoted class from data.command.
$output = $this->runListFailedCommandWith([
$this->fakeFailedJob([
'data' => [
'commandName' => 'App\\Jobs\\LegacyJob',
'command' => 'O:18:"App\\Jobs\\LegacyJob":0:{}',
],
]),
]);
$this->assertStringContainsString('App\\Jobs\\LegacyJob', $output);
}
public function testEncryptedJobShowsUnderlyingClass()
{
// Encrypted queue payloads store ciphertext in data.command, so the
// legacy regex falls back to CallQueuedHandler@call (the value at
// payload.job). displayName carries the real underlying class.
$output = $this->runListFailedCommandWith([
$this->fakeFailedJob([
'displayName' => 'App\\Jobs\\ProcessOrder',
'job' => 'Illuminate\\Queue\\CallQueuedHandler@call',
'data' => [
'commandName' => 'Illuminate\\Queue\\CallEncryptedQueuedHandler',
'command' => 'eyJpdiI6IlhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFg9IiwidmFsdWUiOiJjaXBoZXJ0ZXh0LWJsb2Itd2l0aC1uby1jbGFzcy1uYW1lcyIsIm1hYyI6ImZha2UifQ==',
],
]),
]);
$this->assertStringContainsString('App\\Jobs\\ProcessOrder', $output);
$this->assertStringNotContainsString('CallQueuedHandler', $output);
}
public function testMalformedPayloadDoesNotThrow()
{
// Malformed JSON in the payload column must not bubble up an exception;
// the row should render with an empty Class cell.
$output = $this->runListFailedCommandWithRawPayload('not-json-at-all');
$this->assertStringContainsString('1', $output);
}
/**
* Build a fake failed_jobs row with an encoded JSON payload.
*
* @param array $payload
* @return array
*/
private function fakeFailedJob(array $payload): array
{
return [
'id' => 1,
'connection' => 'database',
'queue' => 'default',
'payload' => json_encode($payload + ['uuid' => 'fake-uuid']),
'exception' => 'Exception: boom',
'failed_at' => '2026-01-01 00:00:00',
];
}
/**
* Build a row with a raw (possibly malformed) payload string.
*
* @param string $rawPayload
* @return array
*/
private function rawFailedJob(string $rawPayload): array
{
return [
'id' => 1,
'connection' => 'database',
'queue' => 'default',
'payload' => $rawPayload,
'exception' => 'Exception: boom',
'failed_at' => '2026-01-01 00:00:00',
];
}
/**
* Run queue:failed with the given failed_jobs rows and return captured output.
*
* @param array $rows
* @return string
*/
private function runListFailedCommandWith(array $rows): string
{
return $this->executeCommand($rows);
}
/**
* Run queue:failed with a single raw-payload row and return captured output.
*
* @param string $rawPayload
* @return string
*/
private function runListFailedCommandWithRawPayload(string $rawPayload): string
{
return $this->executeCommand([$this->rawFailedJob($rawPayload)]);
}
/**
* Wire up a stub failer, run the command, and return the buffered output.
*
* @param array $rows
* @return string
*/
private function executeCommand(array $rows): string
{
$container = new Application;
// The command resolves the failer via the queue.failer container binding.
$failer = Mockery::mock(FailedJobProviderInterface::class);
$failer->expects('all')->andReturn($rows);
$container->instance('queue.failer', $failer);
$command = new ListFailedCommand;
$command->setLaravel($container);
$output = new BufferedOutput;
$command->run(new ArrayInput([]), $output);
return $output->fetch();
}
}