diff --git a/bundle/src/BillingFakeLicenseProvider.php b/bundle/src/BillingFakeLicenseProvider.php deleted file mode 100644 index c9a695c..0000000 --- a/bundle/src/BillingFakeLicenseProvider.php +++ /dev/null @@ -1,37 +0,0 @@ - $internalFakeClass - */ - public function __construct(string $internalFakeClass) - { - $this->internalFake = new $internalFakeClass(); - } - - public function license(int $userId, Component $component): ?License - { - return $this->internalFake->license($userId, $component); - } - - /** - * @param int[] $organizationIds - * @return array - */ - public function licenses(array $organizationIds, Component $component): array - { - return $this->internalFake->licenses($organizationIds, $component); - } - -} diff --git a/src/Auth/AuthFactory.php b/src/Auth/AuthFactory.php index a284408..47ea347 100644 --- a/src/Auth/AuthFactory.php +++ b/src/Auth/AuthFactory.php @@ -21,7 +21,7 @@ public function create(): AuthInterface if ($this->internalConfig->getDeployment()->isCloud()) { if ($this->internalConfig->isFake()) { $fake = InternalFake::getInstance(); - return new AuthFake($fake->user(), $fake->usersDatabase()); + return new AuthFake($fake->user(), $fake->organization(), $fake->usersDatabase()); } return $this->hyvorAuth; } diff --git a/src/Auth/AuthFake.php b/src/Auth/AuthFake.php index a14b9ca..d41e1fb 100644 --- a/src/Auth/AuthFake.php +++ b/src/Auth/AuthFake.php @@ -13,6 +13,8 @@ final class AuthFake implements AuthInterface { + private ?AuthUserOrganization $organization; + /** * If $usersDatabase is set, users will be searched (in fromX() methods) from this collection * Results will only be returned if the search is matched @@ -34,12 +36,14 @@ final class AuthFake implements AuthInterface */ public function __construct( null|AuthUser|array $user = null, + null|AuthUserOrganization $organization = null, ?iterable $usersDatabase = null ) { if (is_array($user)) { $user = self::generateUser($user); } $this->user = $user; + $this->organization = $organization; $this->usersDatabase = $usersDatabase ? self::getAuthUsersFromPartial($usersDatabase) : null; } @@ -55,9 +59,10 @@ public function __destruct() */ public static function enable( null|AuthUser|array $user = null, + null|AuthUserOrganization $organization = null, ?iterable $usersDatabase = null ): void { - $fake = new self($user, $usersDatabase); + $fake = new self($user, $organization, $usersDatabase); app()->singleton( AuthInterface::class, fn() => $fake @@ -72,6 +77,7 @@ public static function enable( public static function enableForSymfony( Container $container, null|AuthUser|array $user = null, + null|AuthUserOrganization $organization = null, ?iterable $usersDatabase = null ): void { $fake = new self(); @@ -79,6 +85,7 @@ public static function enableForSymfony( $user = self::generateUser($user); } $fake->user = $user; + $fake->organization = $organization; $fake->usersDatabase = $usersDatabase !== null ? self::getAuthUsersFromPartial($usersDatabase) : null; self::$symfonyContainer = $container; $container->set(AuthInterface::class, $fake); @@ -86,7 +93,7 @@ public static function enableForSymfony( public function me(string|Request $request): ?Me { - return $this->user ? new Me($this->user, null) : null; + return $this->user ? new Me($this->user, $this->organization) : null; } public function authUrl(string $page, null|string|Request $redirect = null): string diff --git a/src/Billing/BillingFactory.php b/src/Billing/BillingFactory.php index e5e0413..e4d9536 100644 --- a/src/Billing/BillingFactory.php +++ b/src/Billing/BillingFactory.php @@ -2,7 +2,6 @@ namespace Hyvor\Internal\Billing; -use Hyvor\Internal\Bundle\BillingFakeLicenseProvider; use Hyvor\Internal\InternalConfig; use Hyvor\Internal\InternalFake; @@ -19,10 +18,9 @@ public function create(): BillingInterface { if ($this->internalConfig->isFake()) { $fake = InternalFake::getInstance(); - $fakeLicenseProvider = new BillingFakeLicenseProvider(get_class($fake)); return new BillingFake( $this->internalConfig, - [$fakeLicenseProvider, 'licenses'] + fn ($organizationIds, $component) => $fake->licenses($organizationIds, $component), ); } return $this->billing; diff --git a/src/InternalFake.php b/src/InternalFake.php index 394839b..8d63bb7 100644 --- a/src/InternalFake.php +++ b/src/InternalFake.php @@ -3,6 +3,7 @@ namespace Hyvor\Internal; use Hyvor\Internal\Auth\AuthUser; +use Hyvor\Internal\Auth\AuthUserOrganization; use Hyvor\Internal\Billing\License\License; use Hyvor\Internal\Billing\License\Resolved\ResolvedLicense; use Hyvor\Internal\Billing\License\Resolved\ResolvedLicenseType; @@ -28,6 +29,15 @@ public function user(): ?AuthUser ]); } + public function organization(): ?AuthUserOrganization + { + return new AuthUserOrganization( + id: 1, + name: 'HYVOR', + role: 'admin' + ); + } + /** * @return array|null */ diff --git a/src/InternalServiceProvider.php b/src/InternalServiceProvider.php index 0b7db42..2a05789 100644 --- a/src/InternalServiceProvider.php +++ b/src/InternalServiceProvider.php @@ -120,7 +120,7 @@ private function fake(): void // fake auth $user = $fakeConfig->user(); $usersDatabase = $fakeConfig->usersDatabase(); - AuthFake::enable($user, $usersDatabase); + AuthFake::enable($user, $fakeConfig->organization(), $usersDatabase); // fake billing BillingFake::enable( diff --git a/tests/Bundle/BillingFakeLicenseProviderTest.php b/tests/Bundle/BillingFakeLicenseProviderTest.php deleted file mode 100644 index 2509007..0000000 --- a/tests/Bundle/BillingFakeLicenseProviderTest.php +++ /dev/null @@ -1,25 +0,0 @@ -license(1, Component::BLOGS); - $this->assertNotNull($license); - - $licenses = $fake->licenses([1], Component::BLOGS); - $this->assertCount(1, $licenses); - - } - -}