. */ declare(strict_types=1); namespace Tests\Unit\Handlers\Events; use FireflyIII\Handlers\Events\APIEventHandler; use FireflyIII\Mail\AccessTokenCreatedMail; use FireflyIII\Repositories\User\UserRepositoryInterface; use Illuminate\Support\Facades\Mail; use Laravel\Passport\Events\AccessTokenCreated; use Log; use Tests\TestCase; /** * * Class APIEventHandlerTest * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.TooManyPublicMethods) */ class APIEventHandlerTest extends TestCase { /** * */ public function setUp(): void { parent::setUp(); Log::info(sprintf('Now in %s.', get_class($this))); } /** * @covers \FireflyIII\Handlers\Events\APIEventHandler */ public function testAccessTokenCreated(): void { Mail::fake(); // mock objects. $repository = $this->mock(UserRepositoryInterface::class); // mock calls. $repository->shouldReceive('findNull')->withArgs([1])->andReturn($this->user())->once(); $event = new AccessTokenCreated('1', '1', '1'); $handler = new APIEventHandler; $handler->accessTokenCreated($event); // assert a message was sent. Mail::assertSent( AccessTokenCreatedMail::class, function ($mail) { return $mail->hasTo('james@firefly-iii.org') && '127.0.0.1' === $mail->ipAddress; } ); } }