Skip to content

Commit

Permalink
Merge pull request #398 from laravel/fix-test
Browse files Browse the repository at this point in the history
[1.x] Fixes time usage in test
  • Loading branch information
timacdonald authored Jul 25, 2024
2 parents 419a9bf + 572951b commit d17417d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 37 deletions.
60 changes: 30 additions & 30 deletions tests/Feature/Recorders/ExceptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,50 +115,50 @@
it('can sample', function () {
Config::set('pulse.recorders.'.Exceptions::class.'.sample_rate', 0.1);

report(new MyReportedException());
report(new MyReportedException());
report(new MyReportedException());
report(new MyReportedException());
report(new MyReportedException());
report(new MyReportedException());
report(new MyReportedException());
report(new MyReportedException());
report(new MyReportedException());
report(new MyReportedException());
report(new MyReportedException);
report(new MyReportedException);
report(new MyReportedException);
report(new MyReportedException);
report(new MyReportedException);
report(new MyReportedException);
report(new MyReportedException);
report(new MyReportedException);
report(new MyReportedException);
report(new MyReportedException);

expect(Pulse::ingest())->toEqualWithDelta(1, 4);
});

it('can sample at zero', function () {
Config::set('pulse.recorders.'.Exceptions::class.'.sample_rate', 0);

report(new MyReportedException());
report(new MyReportedException());
report(new MyReportedException());
report(new MyReportedException());
report(new MyReportedException());
report(new MyReportedException());
report(new MyReportedException());
report(new MyReportedException());
report(new MyReportedException());
report(new MyReportedException());
report(new MyReportedException);
report(new MyReportedException);
report(new MyReportedException);
report(new MyReportedException);
report(new MyReportedException);
report(new MyReportedException);
report(new MyReportedException);
report(new MyReportedException);
report(new MyReportedException);
report(new MyReportedException);

expect(Pulse::ingest())->toBe(0);
});

it('can sample at one', function () {
Config::set('pulse.recorders.'.Exceptions::class.'.sample_rate', 1);

report(new MyReportedException());
report(new MyReportedException());
report(new MyReportedException());
report(new MyReportedException());
report(new MyReportedException());
report(new MyReportedException());
report(new MyReportedException());
report(new MyReportedException());
report(new MyReportedException());
report(new MyReportedException());
report(new MyReportedException);
report(new MyReportedException);
report(new MyReportedException);
report(new MyReportedException);
report(new MyReportedException);
report(new MyReportedException);
report(new MyReportedException);
report(new MyReportedException);
report(new MyReportedException);
report(new MyReportedException);

expect(Pulse::ingest())->toBe(10);
});
Expand Down
4 changes: 3 additions & 1 deletion tests/Feature/Recorders/UserRequestsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Illuminate\Auth\GuardHelpers;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\DB;
Expand All @@ -15,14 +16,15 @@
use function Pest\Laravel\post;

it('captures authenticated requests', function () {
Carbon::setTestNow('2000-01-02 03:04:05');
Route::get('users', fn () => []);

actingAs(User::make(['id' => '567']))->get('users');

$entries = Pulse::ignore(fn () => DB::table('pulse_entries')->get());
expect($entries)->toHaveCount(1);
expect($entries[0])->toHaveProperties([
'timestamp' => now()->timestamp,
'timestamp' => 946782245,
'type' => 'user_request',
'key' => '567',
'value' => null,
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/RedisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function prepareForDriver($driver)
->output();
[$firstEntryKey, $lastEntryKey] = collect(explode("\n", $output))->only([17, 21])->values();

$commands = captureRedisCommands(fn () => $ingest->digest(new StorageFake()));
$commands = captureRedisCommands(fn () => $ingest->digest(new StorageFake));

expect($commands)->toContain('"XRANGE" "laravel_database_laravel:pulse:ingest" "-" "+" "COUNT" "567"');
expect($commands)->toContain('"XDEL" "laravel_database_laravel:pulse:ingest" "'.$firstEntryKey.'" "'.$lastEntryKey.'"');
Expand Down
10 changes: 5 additions & 5 deletions tests/StorageFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function purge(?array $types = null): void
*/
public function values(string $type, ?array $keys = null): Collection
{
return new Collection();
return new Collection;
}

/**
Expand All @@ -74,7 +74,7 @@ public function values(string $type, ?array $keys = null): Collection
*/
public function graph(array $types, string $aggregate, CarbonInterval $interval): Collection
{
return new Collection();
return new Collection;
}

/**
Expand All @@ -97,7 +97,7 @@ public function aggregate(
string $direction = 'desc',
int $limit = 101,
): Collection {
return new Collection();
return new Collection;
}

/**
Expand All @@ -114,7 +114,7 @@ public function aggregateTypes(
string $direction = 'desc',
int $limit = 101,
): Collection {
return new Collection();
return new Collection;
}

/**
Expand All @@ -128,6 +128,6 @@ public function aggregateTotal(
string $aggregate,
CarbonInterval $interval,
): Collection {
return new Collection();
return new Collection;
}
}

0 comments on commit d17417d

Please sign in to comment.