Skip to content

Commit

Permalink
[1.x] Use Contracts for common services (#376)
Browse files Browse the repository at this point in the history
* Uses cache contract

* Uses event contract

* Fix code styling

* Handle relay changes

* Fix code styling

---------

Co-authored-by: timacdonald <timacdonald@users.noreply.github.com>
  • Loading branch information
timacdonald and timacdonald authored May 24, 2024
1 parent ade2b83 commit ce3b631
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/Commands/CheckCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Carbon\CarbonImmutable;
use Illuminate\Console\Command;
use Illuminate\Contracts\Cache\LockProvider;
use Illuminate\Events\Dispatcher;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Support\Env;
use Illuminate\Support\Sleep;
use Illuminate\Support\Str;
Expand Down
2 changes: 1 addition & 1 deletion src/Ingests/RedisIngest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Carbon\CarbonImmutable;
use Carbon\CarbonInterval;
use Illuminate\Config\Repository;
use Illuminate\Contracts\Config\Repository;
use Illuminate\Redis\RedisManager;
use Illuminate\Support\Collection;
use Laravel\Pulse\Contracts\Ingest;
Expand Down
2 changes: 1 addition & 1 deletion src/Recorders/Exceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Laravel\Pulse\Recorders;

use Carbon\CarbonImmutable;
use Illuminate\Config\Repository;
use Illuminate\Contracts\Config\Repository;
use Illuminate\Contracts\Debug\ExceptionHandler;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Contracts\Foundation\Application;
Expand Down
2 changes: 1 addition & 1 deletion src/Recorders/Queues.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Laravel\Pulse\Recorders;

use Carbon\CarbonImmutable;
use Illuminate\Config\Repository;
use Illuminate\Contracts\Config\Repository;
use Illuminate\Events\CallQueuedListener;
use Illuminate\Queue\Events\JobFailed;
use Illuminate\Queue\Events\JobProcessed;
Expand Down
2 changes: 1 addition & 1 deletion src/Recorders/Servers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Laravel\Pulse\Recorders;

use Illuminate\Config\Repository;
use Illuminate\Contracts\Config\Repository;
use Illuminate\Support\Str;
use Laravel\Pulse\Events\SharedBeat;
use Laravel\Pulse\Pulse;
Expand Down
2 changes: 1 addition & 1 deletion src/Recorders/SlowQueries.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Laravel\Pulse\Recorders;

use Carbon\CarbonImmutable;
use Illuminate\Config\Repository;
use Illuminate\Contracts\Config\Repository;
use Illuminate\Database\Events\QueryExecuted;
use Illuminate\Support\Str;
use Laravel\Pulse\Pulse;
Expand Down
2 changes: 1 addition & 1 deletion src/Storage/DatabaseStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Carbon\CarbonImmutable;
use Carbon\CarbonInterval;
use Closure;
use Illuminate\Config\Repository;
use Illuminate\Contracts\Config\Repository;
use Illuminate\Database\Connection;
use Illuminate\Database\DatabaseManager;
use Illuminate\Database\Query\Builder;
Expand Down
2 changes: 1 addition & 1 deletion src/Support/CacheStoreResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace Laravel\Pulse\Support;

use Illuminate\Cache\CacheManager;
use Illuminate\Config\Repository as ConfigRepository;
use Illuminate\Contracts\Cache\Repository as CacheRepository;
use Illuminate\Contracts\Config\Repository as ConfigRepository;

class CacheStoreResolver
{
Expand Down
2 changes: 1 addition & 1 deletion src/Support/RedisAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Laravel\Pulse\Support;

use Illuminate\Config\Repository;
use Illuminate\Contracts\Config\Repository;
use Illuminate\Redis\Connections\Connection;
use Illuminate\Support\Collection;
use Predis\Client as Predis;
Expand Down
25 changes: 15 additions & 10 deletions tests/Feature/RedisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

$drivers = ['predis', 'phpredis', 'relay'];

function skipWhenExtensionMissing($driver)
function prepareForDriver($driver)
{
$extension = match ($driver) {
'phpredis' => 'redis',
Expand All @@ -29,6 +29,11 @@ function skipWhenExtensionMissing($driver)
? test()->markTestSkipped("PHP extension [{$extension}] missing for Redis driver [{$driver}].")
: null,
};

// Relay version 0.8.0 introduced a breaking change that requires the port be an integer.
if ($driver === 'relay') {
Config::set('database.redis.default.port', (int) Config::get('database.redis.default.port'));
}
}

beforeEach(function () {
Expand All @@ -40,7 +45,7 @@ function skipWhenExtensionMissing($driver)
});

it('runs the same commands while ingesting entries', function ($driver) {
skipWhenExtensionMissing($driver);
prepareForDriver($driver);

Config::set('database.redis.client', $driver);

Expand All @@ -52,7 +57,7 @@ function skipWhenExtensionMissing($driver)
})->with($drivers);

it('keeps 7 days of data, by default, when trimming', function ($driver) {
skipWhenExtensionMissing($driver);
prepareForDriver($driver);

Config::set('database.redis.client', $driver);
Date::setTestNow(Date::parse('2000-01-02 03:04:05')->startOfSecond());
Expand All @@ -63,7 +68,7 @@ function skipWhenExtensionMissing($driver)
})->with($drivers);

it('can configure days of data to keep when trimming', function ($driver) {
skipWhenExtensionMissing($driver);
prepareForDriver($driver);

Config::set('database.redis.client', $driver);
Date::setTestNow(Date::parse('2000-01-02 03:04:05')->startOfSecond());
Expand All @@ -75,7 +80,7 @@ function skipWhenExtensionMissing($driver)
})->with($drivers);

it('can configure the number of entries to keep when trimming', function ($driver) {
skipWhenExtensionMissing($driver);
prepareForDriver($driver);

Config::set('database.redis.client', $driver);
Date::setTestNow(Date::parse('2000-01-02 03:04:05')->startOfSecond());
Expand All @@ -87,7 +92,7 @@ function skipWhenExtensionMissing($driver)
})->with($drivers);

it('runs the same commands while storing', function ($driver) {
skipWhenExtensionMissing($driver);
prepareForDriver($driver);

Config::set('database.redis.client', $driver);
Config::set('pulse.ingest.redis.chunk', 567);
Expand All @@ -110,7 +115,7 @@ function skipWhenExtensionMissing($driver)
})->with($drivers);

it('has consistent return for xadd', function ($driver) {
skipWhenExtensionMissing($driver);
prepareForDriver($driver);

Config::set('database.redis.client', $driver);
$redis = new RedisAdapter(Redis::connection(), App::make('config'));
Expand All @@ -128,7 +133,7 @@ function skipWhenExtensionMissing($driver)
})->with($drivers);

it('has consistent return for xrange', function ($driver) {
skipWhenExtensionMissing($driver);
prepareForDriver($driver);

Config::set('database.redis.client', $driver);
$redis = new RedisAdapter(Redis::connection(), App::make('config'));
Expand Down Expand Up @@ -159,7 +164,7 @@ function skipWhenExtensionMissing($driver)
})->with($drivers);

it('has consistent return for xtrim', function ($driver) {
skipWhenExtensionMissing($driver);
prepareForDriver($driver);

Config::set('database.redis.client', $driver);
$redis = new RedisAdapter(Redis::connection(), App::make('config'));
Expand All @@ -186,7 +191,7 @@ function skipWhenExtensionMissing($driver)
})->with($drivers);

it('throws exception on failure', function ($driver) {
skipWhenExtensionMissing($driver);
prepareForDriver($driver);

Config::set('database.redis.client', $driver);
$redis = new RedisAdapter(Redis::connection(), App::make('config'));
Expand Down

0 comments on commit ce3b631

Please sign in to comment.