Skip to content

Commit eaf022a

Browse files
committed
Add tests
1 parent 3655f12 commit eaf022a

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

tests/VeryBasicAuthTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@
1717
expect(file_exists(__DIR__.'/../src/config.php'))->toBeTrue();
1818
});
1919

20+
test('install package', function () {
21+
$this->artisan('vendor:publish', [
22+
'--provider' => 'Olssonm\VeryBasicAuth\VeryBasicAuthServiceProvider',
23+
])->assertExitCode(0);
24+
25+
expect(file_exists(config_path('very_basic_auth.php')))->toBeTrue();
26+
});
27+
2028
test('request with no credentials and no config passes', function () {
2129
config()->set('very_basic_auth.user', '');
2230
config()->set('very_basic_auth.password', '');
@@ -171,3 +179,30 @@
171179
expect($response->getStatusCode())->toEqual(401);
172180
expect($response->getContent())->toEqual(config('very_basic_auth.error_message'));
173181
});
182+
183+
// Test for the console command PasswordGenerateCommand
184+
test('console command sets password in .env file', function () {
185+
$envPath = base_path('.env');
186+
187+
// Clean up any existing .env before the test
188+
if (file_exists($envPath)) {
189+
unlink($envPath);
190+
}
191+
192+
// Create a fresh .env
193+
file_put_contents($envPath, "APP_NAME=Laravel\nBASIC_AUTH_PASSWORD=test");
194+
195+
$password = 'newpassword123';
196+
197+
// Simulate user input for the console command
198+
$this->artisan('very-basic-auth:password-generate')
199+
->expectsQuestion('Please enter a password for the very basic auth', $password)
200+
->expectsQuestion('Please confirm your password', $password)
201+
->assertExitCode(0);
202+
203+
// Load and parse the .env file to get the new hash via Laravels env helper
204+
$hashedPassword = env('BASIC_AUTH_PASSWORD');
205+
206+
expect($hashedPassword)->not->toBeNull();
207+
expect(app()->make('hash')->check($password, $hashedPassword))->toBeTrue();
208+
});

0 commit comments

Comments
 (0)