-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Testing): Add ability to assert AppConfig (use AppConfigContract…
… for implementation)
- Loading branch information
Showing
16 changed files
with
452 additions
and
5 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,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaraStrict\Config; | ||
|
||
use LaraStrict\Config\Contracts\AppConfigContract; | ||
use LaraStrict\Config\Laravel\AppConfig; | ||
use LaraStrict\Providers\AbstractServiceProvider; | ||
|
||
class ConfigServiceProvider extends AbstractServiceProvider | ||
{ | ||
public array $bindings = [ | ||
AppConfigContract::class => AppConfig::class, | ||
]; | ||
} |
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,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaraStrict\Config\Contracts; | ||
|
||
use LaraStrict\Enums\EnvironmentType; | ||
|
||
interface AppConfigContract | ||
{ | ||
/** | ||
* Version from an app (Larastrict projects uses app.version). | ||
*/ | ||
public function getVersion(): string; | ||
|
||
public function getKey(): string; | ||
|
||
public function getUrl(): string; | ||
|
||
public function getAssetUrl(): ?string; | ||
|
||
public function getName(): string; | ||
|
||
public function isInDebugMode(): bool; | ||
|
||
public function getEnvironment(): EnvironmentType|string; | ||
} |
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
128 changes: 128 additions & 0 deletions
128
src/Testing/Config/Contracts/AppConfigContractAssert.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,128 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaraStrict\Testing\Config\Contracts; | ||
|
||
use LaraStrict\Config\Contracts\AppConfigContract; | ||
use LaraStrict\Enums\EnvironmentType; | ||
use LaraStrict\Testing\AbstractExpectationCallsMap; | ||
|
||
class AppConfigContractAssert extends AbstractExpectationCallsMap implements AppConfigContract | ||
{ | ||
/** | ||
* @param array<AppConfigContractGetVersionExpectation|null> $getVersion | ||
* @param array<AppConfigContractGetKeyExpectation|null> $getKey | ||
* @param array<AppConfigContractGetUrlExpectation|null> $getUrl | ||
* @param array<AppConfigContractGetAssetUrlExpectation|null> $getAssetUrl | ||
* @param array<AppConfigContractGetNameExpectation|null> $getName | ||
* @param array<AppConfigContractIsInDebugModeExpectation|null> $isInDebugMode | ||
* @param array<AppConfigContractGetEnvironmentExpectation|null> $getEnvironment | ||
*/ | ||
public function __construct( | ||
array $getVersion = [], | ||
array $getKey = [], | ||
array $getUrl = [], | ||
array $getAssetUrl = [], | ||
array $getName = [], | ||
array $isInDebugMode = [], | ||
array $getEnvironment = [], | ||
) { | ||
$this->setExpectations(AppConfigContractGetVersionExpectation::class, array_values(array_filter($getVersion))); | ||
$this->setExpectations(AppConfigContractGetKeyExpectation::class, array_values(array_filter($getKey))); | ||
$this->setExpectations(AppConfigContractGetUrlExpectation::class, array_values(array_filter($getUrl))); | ||
$this->setExpectations( | ||
AppConfigContractGetAssetUrlExpectation::class, | ||
array_values(array_filter($getAssetUrl)) | ||
); | ||
$this->setExpectations(AppConfigContractGetNameExpectation::class, array_values(array_filter($getName))); | ||
$this->setExpectations( | ||
AppConfigContractIsInDebugModeExpectation::class, | ||
array_values(array_filter($isInDebugMode)) | ||
); | ||
$this->setExpectations( | ||
AppConfigContractGetEnvironmentExpectation::class, | ||
array_values(array_filter($getEnvironment)) | ||
); | ||
} | ||
|
||
/** | ||
* Version from an app (Larastrict projects uses app.version). | ||
*/ | ||
public function getVersion(): string | ||
{ | ||
$expectation = $this->getExpectation(AppConfigContractGetVersionExpectation::class); | ||
|
||
if (is_callable($expectation->hook)) { | ||
call_user_func($expectation->hook, $expectation); | ||
} | ||
|
||
return $expectation->return; | ||
} | ||
|
||
public function getKey(): string | ||
{ | ||
$expectation = $this->getExpectation(AppConfigContractGetKeyExpectation::class); | ||
|
||
if (is_callable($expectation->hook)) { | ||
call_user_func($expectation->hook, $expectation); | ||
} | ||
|
||
return $expectation->return; | ||
} | ||
|
||
public function getUrl(): string | ||
{ | ||
$expectation = $this->getExpectation(AppConfigContractGetUrlExpectation::class); | ||
|
||
if (is_callable($expectation->hook)) { | ||
call_user_func($expectation->hook, $expectation); | ||
} | ||
|
||
return $expectation->return; | ||
} | ||
|
||
public function getAssetUrl(): ?string | ||
{ | ||
$expectation = $this->getExpectation(AppConfigContractGetAssetUrlExpectation::class); | ||
|
||
if (is_callable($expectation->hook)) { | ||
call_user_func($expectation->hook, $expectation); | ||
} | ||
|
||
return $expectation->return; | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
$expectation = $this->getExpectation(AppConfigContractGetNameExpectation::class); | ||
|
||
if (is_callable($expectation->hook)) { | ||
call_user_func($expectation->hook, $expectation); | ||
} | ||
|
||
return $expectation->return; | ||
} | ||
|
||
public function isInDebugMode(): bool | ||
{ | ||
$expectation = $this->getExpectation(AppConfigContractIsInDebugModeExpectation::class); | ||
|
||
if (is_callable($expectation->hook)) { | ||
call_user_func($expectation->hook, $expectation); | ||
} | ||
|
||
return $expectation->return; | ||
} | ||
|
||
public function getEnvironment(): EnvironmentType|string | ||
{ | ||
$expectation = $this->getExpectation(AppConfigContractGetEnvironmentExpectation::class); | ||
|
||
if (is_callable($expectation->hook)) { | ||
call_user_func($expectation->hook, $expectation); | ||
} | ||
|
||
return $expectation->return; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/Testing/Config/Contracts/AppConfigContractGetAssetUrlExpectation.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,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaraStrict\Testing\Config\Contracts; | ||
|
||
use Closure; | ||
|
||
final class AppConfigContractGetAssetUrlExpectation | ||
{ | ||
/** | ||
* @param Closure(self):void|null $hook | ||
*/ | ||
public function __construct( | ||
public readonly ?string $return, | ||
public readonly ?Closure $hook = null, | ||
) { | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/Testing/Config/Contracts/AppConfigContractGetEnvironmentExpectation.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,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaraStrict\Testing\Config\Contracts; | ||
|
||
use Closure; | ||
use LaraStrict\Enums\EnvironmentType; | ||
|
||
final class AppConfigContractGetEnvironmentExpectation | ||
{ | ||
/** | ||
* @param Closure(self):void|null $hook | ||
*/ | ||
public function __construct( | ||
public readonly EnvironmentType|string $return, | ||
public readonly ?Closure $hook = null, | ||
) { | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/Testing/Config/Contracts/AppConfigContractGetKeyExpectation.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,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaraStrict\Testing\Config\Contracts; | ||
|
||
use Closure; | ||
|
||
final class AppConfigContractGetKeyExpectation | ||
{ | ||
/** | ||
* @param Closure(self):void|null $hook | ||
*/ | ||
public function __construct( | ||
public readonly string $return, | ||
public readonly ?Closure $hook = null, | ||
) { | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/Testing/Config/Contracts/AppConfigContractGetNameExpectation.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,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaraStrict\Testing\Config\Contracts; | ||
|
||
use Closure; | ||
|
||
final class AppConfigContractGetNameExpectation | ||
{ | ||
/** | ||
* @param Closure(self):void|null $hook | ||
*/ | ||
public function __construct( | ||
public readonly string $return, | ||
public readonly ?Closure $hook = null, | ||
) { | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/Testing/Config/Contracts/AppConfigContractGetUrlExpectation.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,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaraStrict\Testing\Config\Contracts; | ||
|
||
use Closure; | ||
|
||
final class AppConfigContractGetUrlExpectation | ||
{ | ||
/** | ||
* @param Closure(self):void|null $hook | ||
*/ | ||
public function __construct( | ||
public readonly string $return, | ||
public readonly ?Closure $hook = null, | ||
) { | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/Testing/Config/Contracts/AppConfigContractGetVersionExpectation.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,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaraStrict\Testing\Config\Contracts; | ||
|
||
use Closure; | ||
|
||
final class AppConfigContractGetVersionExpectation | ||
{ | ||
/** | ||
* @param Closure(self):void|null $hook | ||
*/ | ||
public function __construct( | ||
public readonly string $return, | ||
public readonly ?Closure $hook = null, | ||
) { | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/Testing/Config/Contracts/AppConfigContractIsInDebugModeExpectation.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,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaraStrict\Testing\Config\Contracts; | ||
|
||
use Closure; | ||
|
||
final class AppConfigContractIsInDebugModeExpectation | ||
{ | ||
/** | ||
* @param Closure(self):void|null $hook | ||
*/ | ||
public function __construct( | ||
public readonly bool $return, | ||
public readonly ?Closure $hook = null, | ||
) { | ||
} | ||
} |
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
Oops, something went wrong.