#Pest Error

2 messages · Page 1 of 1 (latest)

spark lantern
#
<?php

use App\EncryptionService;
use Illuminate\Foundation\Testing\RefreshDatabase;

uses(RefreshDatabase::class);


beforeEach(function () {
    $this->service = new EncryptionService();
});

it('encrypts a plaintext message', function () {
    $plaintext = 'Hello, world!';
    $result = $this->service->encrypt($plaintext);

    expect($result)->toHaveKey('ciphertext');
    expect($result)->toHaveKey('iv');
});

it('decrypts a ciphertext message', function () {
    $plaintext = 'Hello, world!';
    $encrypted = $this->service->encrypt($plaintext);
    $decrypted = $this->service->decrypt($encrypted['ciphertext'], $encrypted['iv']);

    expect($decrypted)->toBeArray()->toHaveKey('plaintext');
    expect($decrypted['plaintext'])->toBe($plaintext);
});

FAILED Tests\Unit\EncryptionServiceTest > it decrypts a ciphertext message RuntimeException
A facade root has not been set.

at vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:354
350▕ {
351▕ $instance = static::getFacadeRoot();
352▕
353▕ if (! $instance) {
➜ 354▕ throw new RuntimeException('A facade root has not been set.');
355▕ }
356▕
357▕ return $instance->$method(...$args);
358▕ }

  +1 vendor frames 

2 app/EncryptionService.php:18
3 tests/Unit/EncryptionServiceTest.php:10

tight bluff
#

Laravel doesn't boot in unit tests, only in feature tests