Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Update test for Laravel 9 #1509

Merged
merged 3 commits into from
Nov 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Console/KeysCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class KeysCommand extends Command
/**
* Execute the console command.
*
* @return void
* @return int
*/
public function handle()
{
Expand All @@ -40,6 +40,8 @@ public function handle()

if ((file_exists($publicKey) || file_exists($privateKey)) && ! $this->option('force')) {
$this->error('Encryption keys already exist. Use the --force option to overwrite them.');

return 1;
} else {
if (class_exists(LegacyRSA::class)) {
$keys = (new LegacyRSA)->createKey($this->input ? (int) $this->option('length') : 4096);
Expand All @@ -55,5 +57,7 @@ public function handle()

$this->info('Encryption keys generated successfully.');
}

return 0;
}
}
29 changes: 29 additions & 0 deletions tests/Feature/KeysCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Laravel\Passport\Tests\Feature;

use Mockery as m;

class KeysCommandTest extends PassportTestCase
{
protected function tearDown(): void
{
m::close();

@unlink(self::PUBLIC_KEY);
@unlink(self::PRIVATE_KEY);
}

public function testPrivateAndPublicKeysAreGenerated()
{
$this->assertFileExists(self::PUBLIC_KEY);
$this->assertFileExists(self::PRIVATE_KEY);
}

public function testPrivateAndPublicKeysShouldNotBeGeneratedTwice()
{
$this->artisan('passport:keys')
->assertFailed()
->expectsOutput('Encryption keys already exist. Use the --force option to overwrite them.');
}
}
4 changes: 3 additions & 1 deletion tests/Feature/PassportTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ abstract class PassportTestCase extends TestCase
{
use RefreshDatabase;

const KEYS = __DIR__.'/keys';
const KEYS = __DIR__.'/../keys';
const PUBLIC_KEY = self::KEYS.'/oauth-public.key';
const PRIVATE_KEY = self::KEYS.'/oauth-private.key';

Expand All @@ -24,6 +24,8 @@ protected function setUp(): void

Passport::routes();

Passport::loadKeysFrom(self::KEYS);

@unlink(self::PUBLIC_KEY);
@unlink(self::PRIVATE_KEY);

Expand Down
81 changes: 0 additions & 81 deletions tests/Unit/KeysCommandTest.php

This file was deleted.