Skip to content

Commit 8c3dc97

Browse files
committed
Update tests to work with older Laravel versions
1 parent f7d6e2b commit 8c3dc97

File tree

3 files changed

+44
-6
lines changed

3 files changed

+44
-6
lines changed

factories/CrossJoinSequence.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Factories;
4+
5+
use Illuminate\Database\Eloquent\Factories\Sequence;
6+
use Illuminate\Support\Arr;
7+
8+
class CrossJoinSequence extends Sequence
9+
{
10+
/**
11+
* Create a new cross join sequence instance.
12+
*
13+
* @param array $sequences
14+
* @return void
15+
*/
16+
public function __construct(...$sequences)
17+
{
18+
$crossJoined = array_map(
19+
function ($a) {
20+
return array_merge(...$a);
21+
},
22+
Arr::crossJoin(...$sequences),
23+
);
24+
25+
parent::__construct(...$crossJoined);
26+
}
27+
}

factories/StackkitCloudTaskFactory.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,15 @@ public function definition()
2323
'payload' => '{}',
2424
];
2525
}
26+
27+
/**
28+
* Add a new cross joined sequenced state transformation to the model definition.
29+
*
30+
* @param array $sequence
31+
* @return static
32+
*/
33+
public function crossJoinSequence(...$sequence)
34+
{
35+
return $this->state(new CrossJoinSequence(...$sequence));
36+
}
2637
}

tests/CloudTasksMonitoringTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace Tests;
44

5-
use Carbon\Carbon;
65
use Factories\StackkitCloudTaskFactory;
76
use Google\Cloud\Tasks\V2\RetryConfig;
7+
use Illuminate\Support\Carbon;
88
use Stackkit\LaravelGoogleCloudTasksQueue\CloudTasksApi;
99
use Stackkit\LaravelGoogleCloudTasksQueue\OpenIdVerificator;
1010
use Stackkit\LaravelGoogleCloudTasksQueue\StackkitCloudTask;
@@ -34,7 +34,7 @@ public function test_loading_dashboard_works()
3434
public function it_counts_the_number_of_tasks()
3535
{
3636
// Arrange
37-
$this->travelTo(Carbon::parse('2022-01-01 15:15:00'));
37+
Carbon::setTestNow(Carbon::parse('2022-01-01 15:15:00'));
3838
$lastMinute = now()->startOfMinute()->subMinute();
3939
$thisMinute = now()->startOfMinute();
4040
$thisHour = now()->startOfHour();
@@ -302,7 +302,7 @@ public function when_a_job_is_dispatched_it_will_be_added_to_the_monitor()
302302
public function when_a_job_is_running_it_will_be_updated_in_the_monitor()
303303
{
304304
// Arrange
305-
$this->travelTo(now());
305+
\Illuminate\Support\Carbon::setTestNow(now());
306306
CloudTasksApi::fake();
307307
OpenIdVerificator::fake();
308308

@@ -328,7 +328,7 @@ public function when_a_job_is_running_it_will_be_updated_in_the_monitor()
328328
public function when_a_job_is_successful_it_will_be_updated_in_the_monitor()
329329
{
330330
// Arrange
331-
$this->travelTo(now());
331+
\Illuminate\Support\Carbon::setTestNow(now());
332332
CloudTasksApi::fake();
333333
OpenIdVerificator::fake();
334334

@@ -354,7 +354,7 @@ public function when_a_job_is_successful_it_will_be_updated_in_the_monitor()
354354
public function when_a_job_errors_it_will_be_updated_in_the_monitor()
355355
{
356356
// Arrange
357-
$this->travelTo(now());
357+
\Illuminate\Support\Carbon::setTestNow(now());
358358
CloudTasksApi::fake();
359359
OpenIdVerificator::fake();
360360

@@ -381,7 +381,7 @@ public function when_a_job_errors_it_will_be_updated_in_the_monitor()
381381
public function when_a_job_fails_it_will_be_updated_in_the_monitor()
382382
{
383383
// Arrange
384-
$this->travelTo(now());
384+
\Illuminate\Support\Carbon::setTestNow(now());
385385
CloudTasksApi::fake();
386386
OpenIdVerificator::fake();
387387
CloudTasksApi::partialMock()->shouldReceive('getRetryConfig')->andReturn(

0 commit comments

Comments
 (0)