Skip to content

Commit

Permalink
test(ExceptionNotifyManagerTest): spy runningInConsole method
Browse files Browse the repository at this point in the history
- Change runningInConsole method to return false using a spy
- Remove unused make method
  • Loading branch information
guanguans committed Aug 10, 2023
1 parent c69a750 commit d65c297
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions tests/ExceptionNotifyManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,21 @@
use Guanguans\LaravelExceptionNotify\ExceptionNotifyManager;
use Illuminate\Contracts\Foundation\Application;

use function Pest\Faker\faker;

it('can call', function (): void {
ExceptionNotifyManager::macro('foo', fn ($param) => $param);
expect($this->app->make(ExceptionNotifyManager::class))
->foo('foo')->toBe('foo');
})->group(__DIR__, __FILE__);

it('will throw error', function (): void {
$this->app->make(ExceptionNotifyManager::class)->bar();
})->group(__DIR__, __FILE__)->throws(InvalidArgumentException::class)->skip();
try {
$this->app->make(ExceptionNotifyManager::class)->bar();
} catch (Throwable $throwable) {
expect($throwable)->toBeInstanceOf(Error::class);
}
})->group(__DIR__, __FILE__);

it('can report if', function (): void {
expect($this->app->make(ExceptionNotifyManager::class))
Expand All @@ -34,9 +40,9 @@
->report(new Exception())->toBeNull();

config()->set('exception-notify.enabled', true);
$mockApplication = Mockery::mock(Application::class);
$mockApplication->allows('make')->with('config')->andReturn(config());
$mockApplication->allows('runningInConsole')->andReturn(false);
$mockApplication = Mockery::spy(Application::class);
// $mockApplication->allows('make')->with('config')->andReturn(config());
$mockApplication->allows('runningInConsole')->andReturnFalse();

/** @noinspection PhpVoidFunctionResultUsedInspection */
expect(new ExceptionNotifyManager($mockApplication))
Expand Down Expand Up @@ -66,14 +72,20 @@
config()->set('exception-notify.except', []);
config()->set('exception-notify.rate_limit.max_attempts', 1);
expect($shouldntReporter)
->call($this->app->make(ExceptionNotifyManager::class))->toBeFalse();
expect($shouldntReporter)
->call($this->app->make(ExceptionNotifyManager::class))->toBeFalse();
expect($shouldntReporter)
->call($this->app->make(ExceptionNotifyManager::class))->toBeFalse()
->call($this->app->make(ExceptionNotifyManager::class))->toBeFalse();
})->group(__DIR__, __FILE__);

it('can get default driver', function (): void {
expect($this->app->make(ExceptionNotifyManager::class))
->getDefaultDriver()->toBeString();
})->group(__DIR__, __FILE__);

it('can attempt key', function (): void {
$uuid = faker()->uuid();
expect(fn () => $this->attempt($uuid, 3))
->call($this->app->make(ExceptionNotifyManager::class))->toBeTrue()
->call($this->app->make(ExceptionNotifyManager::class))->toBeTrue()
->call($this->app->make(ExceptionNotifyManager::class))->toBeTrue()
->call($this->app->make(ExceptionNotifyManager::class))->toBeFalse();
})->group(__DIR__, __FILE__);

0 comments on commit d65c297

Please sign in to comment.