-
-
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.
Merge pull request #270 from hydephp/218-add-config-version-property-…
…so-that-a-warning-can-be-sent-if-a-config-file-is-outdated Send a non-intrusive warning when the config file is out of date
- Loading branch information
Showing
4 changed files
with
119 additions
and
0 deletions.
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
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,34 @@ | ||
<?php | ||
|
||
namespace Hyde\Framework\Actions; | ||
|
||
use Hyde\Framework\Contracts\ActionContract; | ||
use Hyde\Framework\Hyde; | ||
|
||
/** | ||
* Checks if the installed config is up-to-date with the Framework's config. | ||
* Works by comparing the number of title blocks, which is a crude but fast way to check. | ||
* | ||
* @see \Tests\Feature\Actions\ChecksIfConfigIsUpToDateTest | ||
*/ | ||
class ChecksIfConfigIsUpToDate implements ActionContract | ||
{ | ||
public string $hydeConfig; | ||
public string $frameworkConfig; | ||
|
||
public function __construct() | ||
{ | ||
$this->hydeConfig = file_get_contents(Hyde::path('config/hyde.php')); | ||
$this->frameworkConfig = file_get_contents(Hyde::vendorPath('config/hyde.php')); | ||
} | ||
|
||
public function execute(): bool | ||
{ | ||
return $this->findOptions($this->hydeConfig) === $this->findOptions($this->frameworkConfig); | ||
} | ||
|
||
public function findOptions(string $config): int | ||
{ | ||
return substr_count($config, '--------------------------------------------------------------------------'); | ||
} | ||
} |
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,53 @@ | ||
<?php | ||
|
||
namespace Tests\Feature\Actions; | ||
|
||
use Hyde\Framework\Actions\ChecksIfConfigIsUpToDate; | ||
use Tests\TestCase; | ||
|
||
/** | ||
* @covers \Hyde\Framework\Actions\ChecksIfConfigIsUpToDate | ||
*/ | ||
class ChecksIfConfigIsUpToDateTest extends TestCase | ||
{ | ||
public function test_it_returns_true_if_config_is_up_to_date() | ||
{ | ||
$action = new ChecksIfConfigIsUpToDate(); | ||
|
||
$action->hydeConfig = $this->makeConfig(); | ||
$action->frameworkConfig = $this->makeConfig(); | ||
|
||
$this->assertTrue($action->execute()); | ||
} | ||
|
||
public function test_it_returns_false_if_config_is_not_up_to_date() | ||
{ | ||
$action = new ChecksIfConfigIsUpToDate(); | ||
|
||
$action->hydeConfig = $this->makeConfig(); | ||
$action->frameworkConfig = 'foo'; | ||
|
||
$this->assertFalse($action->execute()); | ||
} | ||
|
||
protected function makeConfig(): string | ||
{ | ||
return <<<'EOF' | ||
<?php return [ | ||
/* | ||
|-------------------------------------------------------------------------- | ||
| Foo Bar | ||
|-------------------------------------------------------------------------- | ||
| | ||
*/ | ||
/* | ||
|-------------------------------------------------------------------------- | ||
| Second Option | ||
|-------------------------------------------------------------------------- | ||
| | ||
*/ | ||
]; | ||
EOF; | ||
} | ||
} |