feat: added install script
This commit is contained in:
3 files changed
+129
No files matched your search
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\File;
|
||||
|
||||
beforeEach(function () {
|
||||
$this->envPath = base_path('.env');
|
||||
$this->configPath = config_path('mattitja-analytics.php');
|
||||
|
||||
if (File::exists($this->configPath)) {
|
||||
File::delete($this->configPath);
|
||||
}
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
if (File::exists($this->configPath)) {
|
||||
File::delete($this->configPath);
|
||||
}
|
||||
});
|
||||
|
||||
it('publishes the config file', function () {
|
||||
$this->artisan('mattitja:install')
|
||||
->assertSuccessful();
|
||||
|
||||
expect(File::exists($this->configPath))->toBeTrue();
|
||||
});
|
||||
|
||||
it('displays success message', function () {
|
||||
$this->artisan('mattitja:install')
|
||||
->expectsOutputToContain('Mattitja Analytics installed successfully')
|
||||
->assertSuccessful();
|
||||
});
|
||||
|
||||
it('displays warning about site key', function () {
|
||||
$this->artisan('mattitja:install')
|
||||
->expectsOutputToContain('MATTITJA_ANALYTICS_SITE_KEY')
|
||||
->assertSuccessful();
|
||||
});
|
||||
|
||||
it('adds env variable if .env exists and key is missing', function () {
|
||||
$originalContent = "APP_NAME=Test\n";
|
||||
File::put($this->envPath, $originalContent);
|
||||
|
||||
$this->artisan('mattitja:install')
|
||||
->assertSuccessful();
|
||||
|
||||
$envContent = File::get($this->envPath);
|
||||
|
||||
expect($envContent)->toContain('MATTITJA_ANALYTICS_SITE_KEY=');
|
||||
|
||||
File::put($this->envPath, $originalContent);
|
||||
});
|
||||
|
||||
it('does not duplicate env variable if already exists', function () {
|
||||
$originalContent = "APP_NAME=Test\nMATTITJA_ANALYTICS_SITE_KEY=existing-key\n";
|
||||
File::put($this->envPath, $originalContent);
|
||||
|
||||
$this->artisan('mattitja:install')
|
||||
->assertSuccessful();
|
||||
|
||||
$envContent = File::get($this->envPath);
|
||||
|
||||
expect(substr_count($envContent, 'MATTITJA_ANALYTICS_SITE_KEY'))->toBe(1);
|
||||
|
||||
File::put($this->envPath, "APP_NAME=Test\n");
|
||||
});
|
||||
Reference in new issue
Block a user