-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add config_version to config file; * Throw exception if published config version in outdated; * Add tests; * Apply fixes from StyleCI --------- Co-authored-by: StyleCI Bot <[email protected]>
- Loading branch information
1 parent
451784a
commit a5a8d49
Showing
4 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/Exceptions/Package/PublishedVersionOutDatedException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace Hans\Valravn\Exceptions\Package; | ||
|
||
use Hans\Valravn\Exceptions\VException; | ||
|
||
class PublishedVersionOutDatedException extends VException | ||
{ | ||
protected string $errorCodePrefix = 'ValravnECx'; | ||
|
||
public function __construct() | ||
{ | ||
parent::__construct('Published config file is outdated! please republish it.', 3); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace Hans\Valravn\Tests\Feature; | ||
|
||
use Hans\Valravn\Exceptions\Package\PublishedVersionOutDatedException; | ||
use Hans\Valravn\Tests\TestCase; | ||
use Hans\Valravn\ValravnServiceProvider; | ||
use Illuminate\Support\Facades\File; | ||
use PHPUnit\Framework\Attributes\Test; | ||
|
||
class ValravnServiceProviderTest extends TestCase | ||
{ | ||
protected function tearDown(): void | ||
{ | ||
$configFile = __DIR__.'/../../config/config.php'; | ||
$publishedVersion = config('valravn.config_version'); | ||
$newVersion = str_split($publishedVersion, strrpos($publishedVersion, '.'))[0].'.999'; | ||
|
||
// revert 'config_version' key | ||
$configContent = file_get_contents($configFile); | ||
$configContent = str_replace($newVersion, $publishedVersion, $configContent); | ||
file_put_contents($configFile, $configContent); | ||
|
||
File::delete(base_path('config/valravn.php')); | ||
self::assertFileDoesNotExist(base_path('config/valravn.php')); | ||
|
||
parent::tearDown(); | ||
} | ||
|
||
#[Test] | ||
public function publishedConfigFileVersion() | ||
{ | ||
$publishedVersion = config('valravn.config_version'); | ||
$configVersion = require __DIR__.'/../../config/config.php'; | ||
$configVersion = $configVersion['config_version']; | ||
|
||
self::assertGreaterThanOrEqual($configVersion, $publishedVersion); | ||
} | ||
|
||
#[Test] | ||
public function publishedConfigFileVersionIsOutdated() | ||
{ | ||
$this->artisan('vendor:publish', ['--tag' => 'valravn-config']); | ||
self::assertFileExists(base_path('config/valravn.php')); | ||
|
||
$configFile = __DIR__.'/../../config/config.php'; | ||
$publishedVersion = config('valravn.config_version'); | ||
|
||
$newVersion = str_split($publishedVersion, strrpos($publishedVersion, '.'))[0].'.999'; | ||
// change 'config_version' key | ||
$newConfigContent = file_get_contents($configFile); | ||
$newConfigContent = str_replace($publishedVersion, $newVersion, $newConfigContent); | ||
file_put_contents($configFile, $newConfigContent); | ||
|
||
$this->expectException(PublishedVersionOutDatedException::class); | ||
|
||
$provider = new ValravnServiceProvider($this->app); | ||
$provider->boot(); | ||
} | ||
} |