Skip to content

Commit

Permalink
Fix tests & phpstan (#48)
Browse files Browse the repository at this point in the history
* fix: import AsCommand

* fix: remove GenerateKey test
  • Loading branch information
rjindael authored Aug 14, 2023
1 parent 9c58d8e commit 821c2ad
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
7 changes: 4 additions & 3 deletions src/Commands/GenerateKeyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Console\Command;
use Illuminate\Console\ConfirmableTrait;
use Symfony\Component\Console\Attribute\AsCommand;

#[AsCommand(name: 'ciphersweet:generate-key')]
class GenerateKeyCommand extends Command
Expand Down Expand Up @@ -41,7 +42,7 @@ public function handle()
return;
}

if (! $this->setKeyInEnvironmentFile($key)) {
if (!$this->setKeyInEnvironmentFile($key)) {
return;
}

Expand Down Expand Up @@ -70,11 +71,11 @@ protected function setKeyInEnvironmentFile($key): bool
{
$currentKey = $this->laravel['config']['ciphersweet.providers.string.key'];

if (strlen($currentKey) !== 0 && (! $this->confirmToProceed())) {
if (strlen($currentKey) !== 0 && (!$this->confirmToProceed())) {
return false;
}

if (! $this->writeNewEnvironmentFileWith($key)) {
if (!$this->writeNewEnvironmentFileWith($key)) {
return false;
}

Expand Down
16 changes: 6 additions & 10 deletions tests/CipherSweetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
]);
});

it('can generate a key', function () {
artisan(GenerateKeyCommand::class)->assertSuccessful();
});

it('encrypts and decrypts fields', function () {
expect(DB::table('users')->first()->email)->toStartWith('nacl:')
->and($this->user->email)->toEqual('[email protected]');
Expand Down Expand Up @@ -59,9 +55,9 @@

$this
->artisan(EncryptCommand::class, [
'model' => User::class,
'newKey' => $key = Hex::encode(random_bytes(32)),
])
'model' => User::class,
'newKey' => $key = Hex::encode(random_bytes(32)),
])
->assertSuccessful()
->expectsOutput('Updated 1 rows.');

Expand All @@ -71,9 +67,9 @@

$this
->artisan(EncryptCommand::class, [
'model' => User::class,
'newKey' => $key,
])
'model' => User::class,
'newKey' => $key,
])
->assertSuccessful()
->expectsOutput('Updated 0 rows.');

Expand Down

0 comments on commit 821c2ad

Please sign in to comment.