|
17 | 17 | expect(file_exists(__DIR__.'/../src/config.php'))->toBeTrue(); |
18 | 18 | }); |
19 | 19 |
|
| 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 | + |
20 | 28 | test('request with no credentials and no config passes', function () { |
21 | 29 | config()->set('very_basic_auth.user', ''); |
22 | 30 | config()->set('very_basic_auth.password', ''); |
|
171 | 179 | expect($response->getStatusCode())->toEqual(401); |
172 | 180 | expect($response->getContent())->toEqual(config('very_basic_auth.error_message')); |
173 | 181 | }); |
| 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