Skip to content

Commit c9c93ef

Browse files
Merge pull request #10 from stackkit/bugfix/failing-tests
Prefer psr/log 1.0 for older PHP support
2 parents 30db208 + 473fb7a commit c9c93ef

File tree

4 files changed

+61
-19
lines changed

4 files changed

+61
-19
lines changed

.github/workflows/run-tests.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Run tests
22

33
on:
4-
push:
4+
pull_request:
55
schedule:
66
- cron: '0 0 * * *'
77

@@ -11,7 +11,7 @@ jobs:
1111

1212
strategy:
1313
matrix:
14-
php: [8.0, 7.4, 7.3]
14+
php: [8.1, 8.0, 7.4, 7.3]
1515
laravel: [8.*, 7.*, 6.*, 5.8.*, 5.7.*, 5.6.*]
1616
os: [ubuntu-latest]
1717
include:
@@ -40,6 +40,16 @@ jobs:
4040
php: 8.0
4141
- laravel: 5.6.*
4242
php: 8.0
43+
- laravel: 5.6.*
44+
php: 8.1
45+
- laravel: 5.7.*
46+
php: 8.1
47+
- laravel: 5.8.*
48+
php: 8.1
49+
- laravel: 6.*
50+
php: 8.1
51+
- laravel: 7.*
52+
php: 8.1
4353

4454
name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}
4555

@@ -57,6 +67,6 @@ jobs:
5767
- name: Install dependencies
5868
run: |
5969
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
60-
composer update --prefer-stable --prefer-dist --no-interaction --no-suggest --ignore-platform-reqs
70+
composer update --prefer-stable --prefer-dist --no-interaction --ignore-platform-reqs
6171
- name: Execute tests
6272
run: vendor/bin/phpunit

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"mockery/mockery": "^1.2",
1818
"orchestra/testbench": "^3.5 || ^3.6 || ^3.7 || ^3.8 || ^4.0 || ^5.0",
1919
"symfony/console": "^4.4|^5.0",
20-
"timacdonald/log-fake": "^1.6"
20+
"psr/log": "^1.0",
21+
"spatie/macroable": "^1.0"
2122
},
2223
"autoload": {
2324
"psr-4": {

tests/GooglePublicKeyTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Illuminate\Cache\Events\CacheHit;
99
use Illuminate\Cache\Events\CacheMissed;
1010
use Illuminate\Cache\Events\KeyWritten;
11-
use Illuminate\Support\Facades\Cache;
1211
use Illuminate\Support\Facades\Event;
1312
use Mockery;
1413
use phpseclib\Crypt\RSA;

tests/TaskHandlerTest.php

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,15 @@
1212
use Illuminate\Container\Container;
1313
use Illuminate\Contracts\Console\Kernel;
1414
use Illuminate\Http\Request;
15+
use Illuminate\Log\LogManager;
1516
use Illuminate\Support\Facades\Event;
16-
use Illuminate\Support\Facades\Log;
1717
use Mockery;
1818
use phpseclib\Crypt\RSA;
1919
use Stackkit\LaravelGoogleCloudScheduler\CloudSchedulerException;
2020
use Stackkit\LaravelGoogleCloudScheduler\Command;
2121
use Stackkit\LaravelGoogleCloudScheduler\OpenIdVerificator;
2222
use Stackkit\LaravelGoogleCloudScheduler\TaskHandler;
2323
use Throwable;
24-
use TiMacDonald\Log\LogFake;
2524

2625
class TaskHandlerTest extends TestCase
2726
{
@@ -31,6 +30,16 @@ class TaskHandlerTest extends TestCase
3130
private $request;
3231
private $jwt;
3332

33+
/**
34+
* @var LogManager
35+
*/
36+
private $laravelLogger = null;
37+
38+
/**
39+
* @var Mockery\Mock
40+
*/
41+
private $log;
42+
3443
public function setUp(): void
3544
{
3645
parent::setUp();
@@ -66,6 +75,26 @@ public function setUp(): void
6675
app(Schedule::class),
6776
Container::getInstance()
6877
);
78+
79+
$this->registerLogFake();
80+
}
81+
82+
/**
83+
* Mock the Laravel logger so we can assert the commands are or aren't called.
84+
*
85+
* @return void
86+
*/
87+
private function registerLogFake()
88+
{
89+
if (is_null($this->laravelLogger)) {
90+
$this->laravelLogger = app('log');
91+
}
92+
93+
$this->log = Mockery::mock($this->laravelLogger);
94+
95+
$this->app->singleton('log', function () {
96+
return $this->log;
97+
});
6998
}
7099

71100
/** @test */
@@ -180,21 +209,28 @@ public function it_prevents_overlapping_if_the_command_is_scheduled_without_over
180209

181210
cache()->clear();
182211

183-
Log::shouldReceive('debug')->twice();
184-
185212
$this->taskHandler->handle();
186213

214+
$this->log->shouldHaveReceived('debug')->once();
215+
187216
$expression = '* * * * *';
188217
$command = ConsoleApplication::formatCommandString('test:command');
189218
$mutex = 'framework'.DIRECTORY_SEPARATOR.'schedule-'.sha1($expression.$command);
190219

191220
cache()->add($mutex, true, 60);
221+
$this->registerLogFake();
192222

193223
$this->taskHandler->handle();
194224

225+
$this->log->shouldNotHaveReceived('debug');
226+
195227
cache()->delete($mutex);
196228

229+
$this->registerLogFake();
230+
197231
$this->taskHandler->handle();
232+
233+
$this->log->shouldNotHaveReceived('debug');
198234
}
199235

200236
/** @test */
@@ -205,13 +241,11 @@ public function it_runs_the_before_and_after_callbacks()
205241
$this->openId->shouldReceive('getKidFromOpenIdToken')->andReturnNull();
206242
$this->openId->shouldReceive('decodeOpenIdToken')->andReturnNull();
207243

208-
Log::swap(new LogFake());
209-
210244
$this->taskHandler->handle();
211245

212-
Log::assertLoggedMessage('info', 'log after');
213-
Log::assertLoggedMessage('warning', 'log before');
214-
Log::assertLoggedMessage('debug', 'did something testy');
246+
$this->log->shouldHaveReceived()->info('log after')->once();
247+
$this->log->shouldHaveReceived()->warning('log before')->once();
248+
$this->log->shouldHaveReceived()->debug('did something testy')->once();
215249
}
216250

217251
/** @test */
@@ -238,13 +272,11 @@ public function it_can_run_the_schedule_run_command()
238272
$this->openId->shouldReceive('getKidFromOpenIdToken')->andReturnNull();
239273
$this->openId->shouldReceive('decodeOpenIdToken')->andReturnNull();
240274

241-
Log::swap(new LogFake());
242-
243275
$this->taskHandler->handle();
244276

245-
Log::assertLoggedMessage('info', 'log after');
246-
Log::assertLoggedMessage('warning', 'log before');
247-
Log::assertLoggedMessage('info', 'log call');
277+
$this->log->shouldHaveReceived()->info('log after')->once();
278+
$this->log->shouldHaveReceived()->warning('log before')->once();
279+
$this->log->shouldHaveReceived()->info('log call')->once();
248280

249281
// @todo - can't test commands run from schedule:run because testbench has no artisan binary.
250282
// Log::assertLoggedMessage('debug', 'did something testy');

0 commit comments

Comments
 (0)