-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Modify service override registration so they're mapped to a…
… "service" (#85) * refactor: Modify service override registration so they're mapped to a "service" * fix: Correct tests to use new registration method
- Loading branch information
Showing
6 changed files
with
139 additions
and
13 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
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,19 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Sprout\Support; | ||
|
||
final class Services | ||
{ | ||
public const AUTH = 'auth'; | ||
|
||
public const CACHE = 'cache'; | ||
|
||
public const COOKIE = 'cookie'; | ||
|
||
public const JOB = 'job'; | ||
|
||
public const SESSION = 'session'; | ||
|
||
public const STORAGE = 'storage'; | ||
} |
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,59 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Sprout\Tests\Unit\Overrides; | ||
|
||
use Illuminate\Config\Repository; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use Sprout\Contracts\BootableServiceOverride; | ||
use Sprout\Contracts\DeferrableServiceOverride; | ||
use Sprout\Overrides\Auth\TenantAwarePasswordBrokerManager; | ||
use Sprout\Overrides\AuthOverride; | ||
use Sprout\Support\Services; | ||
use Sprout\Tests\Unit\UnitTestCase; | ||
use function Sprout\sprout; | ||
|
||
class AuthOverrideTest extends UnitTestCase | ||
{ | ||
protected function defineEnvironment($app): void | ||
{ | ||
tap($app['config'], static function (Repository $config) { | ||
$config->set('sprout.services', []); | ||
}); | ||
} | ||
|
||
#[Test] | ||
public function isBuiltCorrectly(): void | ||
{ | ||
$this->assertTrue(is_subclass_of(AuthOverride::class, BootableServiceOverride::class)); | ||
$this->assertFalse(is_subclass_of(AuthOverride::class, DeferrableServiceOverride::class)); | ||
} | ||
|
||
#[Test] | ||
public function isRegisteredWithSproutCorrectly(): void | ||
{ | ||
$sprout = sprout(); | ||
|
||
$sprout->registerOverride(Services::AUTH, AuthOverride::class); | ||
|
||
$this->assertTrue($sprout->hasRegisteredOverride(AuthOverride::class)); | ||
$this->assertTrue($sprout->isBootableOverride(AuthOverride::class)); | ||
$this->assertFalse($sprout->isDeferrableOverride(AuthOverride::class)); | ||
} | ||
|
||
#[Test] | ||
public function isBootedCorrectly(): void | ||
{ | ||
$sprout = sprout(); | ||
|
||
$sprout->registerOverride(Services::AUTH, AuthOverride::class); | ||
|
||
$this->assertFalse(app()->isDeferredService('auth.password')); | ||
$this->assertTrue(app()->bound('auth.password')); | ||
$this->assertFalse(app()->resolved('auth.password')); | ||
$this->assertFalse(app()->resolved('auth.password.broker')); | ||
$this->assertInstanceOf(TenantAwarePasswordBrokerManager::class, app()->make('auth.password')); | ||
$this->assertTrue(app()->resolved('auth.password')); | ||
$this->assertFalse(app()->resolved('auth.password.broker')); | ||
} | ||
} |
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