Skip to content

Commit e59597f

Browse files
committed
adjust assertions
1 parent 54ef968 commit e59597f

File tree

1 file changed

+31
-26
lines changed

1 file changed

+31
-26
lines changed

src/Illuminate/Support/Testing/Fakes/BusFake.php

+31-26
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ public function assertDispatched($command, $callback = null)
6565
}
6666

6767
PHPUnit::assertTrue(
68-
$this->dispatched($command, $callback)->count() > 0,
68+
$this->dispatched($command, $callback)->count() > 0 ||
69+
$this->dispatchedAfterResponse($command, $callback)->count() > 0,
6970
"The expected [{$command}] job was not dispatched."
7071
);
7172
}
@@ -79,73 +80,77 @@ public function assertDispatched($command, $callback = null)
7980
*/
8081
public function assertDispatchedTimes($command, $times = 1)
8182
{
83+
$count = $this->dispatched($command)->count() +
84+
$this->dispatchedAfterResponse($command)->count();
85+
8286
PHPUnit::assertTrue(
83-
($count = $this->dispatched($command)->count()) === $times,
87+
$count === $times,
8488
"The expected [{$command}] job was pushed {$count} times instead of {$times} times."
8589
);
8690
}
8791

8892
/**
89-
* Assert if a job was pushed after the response was sent a number of times.
93+
* Determine if a job was dispatched based on a truth-test callback.
9094
*
9195
* @param string $command
92-
* @param int $times
96+
* @param callable|null $callback
9397
* @return void
9498
*/
95-
public function assertDispatchedAfterResponseTimes($command, $times = 1)
99+
public function assertNotDispatched($command, $callback = null)
96100
{
97101
PHPUnit::assertTrue(
98-
($count = $this->dispatchedAfterResponse($command)->count()) === $times,
99-
"The expected [{$command}] job was pushed {$count} times instead of {$times} times."
102+
$this->dispatched($command, $callback)->count() === 0 &&
103+
$this->dispatchedAfterResponse($command, $callback)->count() === 0,
104+
"The unexpected [{$command}] job was dispatched."
100105
);
101106
}
102107

103108
/**
104-
* Determine if a job was dispatched based on a truth-test callback.
109+
* Assert if a job was dispatched after the response was sent based on a truth-test callback.
105110
*
106111
* @param string $command
107-
* @param callable|null $callback
112+
* @param callable|int|null $callback
108113
* @return void
109114
*/
110-
public function assertNotDispatched($command, $callback = null)
115+
public function assertDispatchedAfterResponse($command, $callback = null)
111116
{
117+
if (is_numeric($callback)) {
118+
return $this->assertDispatchedAfterResponseTimes($command, $callback);
119+
}
120+
112121
PHPUnit::assertTrue(
113-
$this->dispatched($command, $callback)->count() === 0,
114-
"The unexpected [{$command}] job was dispatched."
122+
$this->dispatchedAfterResponse($command, $callback)->count() > 0,
123+
"The expected [{$command}] job was not dispatched for after sending the response."
115124
);
116125
}
117126

118127
/**
119-
* Determine if a job was dispatched based on a truth-test callback.
128+
* Assert if a job was pushed after the response was sent a number of times.
120129
*
121130
* @param string $command
122-
* @param callable|null $callback
131+
* @param int $times
123132
* @return void
124133
*/
125-
public function assertNotDispatchedAfterResponse($command, $callback = null)
134+
public function assertDispatchedAfterResponseTimes($command, $times = 1)
126135
{
127136
PHPUnit::assertTrue(
128-
$this->dispatchedAfterResponse($command, $callback)->count() === 0,
129-
"The unexpected [{$command}] job was dispatched for after sending the response."
137+
($count = $this->dispatchedAfterResponse($command)->count()) === $times,
138+
"The expected [{$command}] job was pushed {$count} times instead of {$times} times."
130139
);
131140
}
132141

133142
/**
134-
* Assert if a job was dispatched after the response was sent based on a truth-test callback.
143+
* Determine if a job was dispatched based on a truth-test callback.
135144
*
136145
* @param string $command
137-
* @param callable|int|null $callback
146+
* @param callable|null $callback
138147
* @return void
139148
*/
140-
public function assertDispatchedAfterResponse($command, $callback = null)
149+
public function assertNotDispatchedAfterResponse($command, $callback = null)
141150
{
142-
if (is_numeric($callback)) {
143-
return $this->assertDispatchedAfterResponseTimes($command, $callback);
144-
}
145-
146151
PHPUnit::assertTrue(
147-
$this->dispatchedAfterResponse($command, $callback)->count() > 0,
148-
"The expected [{$command}] job was not dispatched for after sending the response."
152+
$this->dispatchedAfterResponse($command, $callback)->count() === 0,
153+
"The unexpected [{$command}] job was dispatched for after sending the response."
149154
);
150155
}
151156

0 commit comments

Comments
 (0)