Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions bundle/src/BillingFakeLicenseProvider.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Auth/AuthFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
11 changes: 9 additions & 2 deletions src/Auth/AuthFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand All @@ -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
Expand All @@ -72,21 +77,23 @@ 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();
if (is_array($user)) {
$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);
}

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
Expand Down
4 changes: 1 addition & 3 deletions src/Billing/BillingFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Hyvor\Internal\Billing;

use Hyvor\Internal\Bundle\BillingFakeLicenseProvider;
use Hyvor\Internal\InternalConfig;
use Hyvor\Internal\InternalFake;

Expand All @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions src/InternalFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,6 +29,15 @@ public function user(): ?AuthUser
]);
}

public function organization(): ?AuthUserOrganization
{
return new AuthUserOrganization(
id: 1,
name: 'HYVOR',
role: 'admin'
);
}

/**
* @return array<int, AuthUser|AuthUserArrayPartial>|null
*/
Expand Down
2 changes: 1 addition & 1 deletion src/InternalServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
25 changes: 0 additions & 25 deletions tests/Bundle/BillingFakeLicenseProviderTest.php

This file was deleted.