Skip to content

Commit

Permalink
Remove getServiceConfig from Provider & Account
Browse files Browse the repository at this point in the history
  • Loading branch information
r-kujawa committed Jun 26, 2024
1 parent be55e09 commit e2cf082
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 76 deletions.
7 changes: 0 additions & 7 deletions src/Contracts/Accountable.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,4 @@ public function getId();
* @return string
*/
public function getName();

/**
* Get the accountable service config.
*
* @return \Payavel\Orchestration\Fluent\ServiceConfig
*/
public function getServiceConfig();
}
7 changes: 0 additions & 7 deletions src/Contracts/Providable.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,4 @@ public function getId();
* @return string
*/
public function getName();

/**
* Get the providable service config.
*
* @return \Payavel\Orchestration\Fluent\ServiceConfig
*/
public function getServiceConfig();
}
11 changes: 0 additions & 11 deletions src/Fluent/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class Account extends Fluent implements Accountable
* The service config.
*
* @var \Payavel\Orchestration\Fluent\ServiceConfig
* @var string|int $id
*/
private ServiceConfig $serviceConfig;

Expand Down Expand Up @@ -71,14 +70,4 @@ public function getName()
{
return $this->attributes['name'] ?? $this->attributes['id'];
}

/**
* Get the accountable service config.
*
* @return \Payavel\Orchestration\Fluent\ServiceConfig
*/
public function getServiceConfig()
{
return $this->serviceConfig;
}
}
11 changes: 0 additions & 11 deletions src/Fluent/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class Provider extends Fluent implements Providable
* The service config.
*
* @var \Payavel\Orchestration\Fluent\ServiceConfig
* @var string|int $id
*/
public ServiceConfig $serviceConfig;

Expand Down Expand Up @@ -70,14 +69,4 @@ public function getName()
{
return $this->attributes['name'] ?? $this->attributes['id'];
}

/**
* Get the providable service config.
*
* @return \Payavel\Orchestration\Fluent\ServiceConfig
*/
public function getServiceConfig()
{
return $this->serviceConfig;
}
}
25 changes: 13 additions & 12 deletions src/Models/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ class Account extends Model implements Accountable
*/
protected $guarded = [];

/**
* The service config.
*
* @var \Payavel\Orchestration\Fluent\ServiceConfig
*/
private ServiceConfig $serviceConfig;

/**
* Get the accountable id.
*
Expand All @@ -46,16 +53,6 @@ public function getName()
return $this->name ?? $this->id;
}

/**
* Get the accountable service config.
*
* @return \Payavel\Orchestration\Fluent\ServiceConfig
*/
public function getServiceConfig()
{
return ServiceConfig::find($this->service_id);
}

/**
* Get the account's related providers.
*
Expand All @@ -73,11 +70,15 @@ public function providers()
*/
private function getProviderModelClass()
{
if(! isset($this->providerModelClass)) {
if(!isset($this->providerModelClass)) {
$this->providerModelClass = $this->guessProviderModelClass();
}

return $this->getServiceConfig()->get("models.{$this->providerModelClass}", $this->providerModelClass);
if(!isset($this->serviceConfig)) {
$this->serviceConfig = ServiceConfig::find($this->service_id);
}

return $this->serviceConfig->get("models.{$this->providerModelClass}", $this->providerModelClass);
}

/**
Expand Down
25 changes: 13 additions & 12 deletions src/Models/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ class Provider extends Model implements Providable
*/
protected $guarded = [];

/**
* The service config.
*
* @var \Payavel\Orchestration\Fluent\ServiceConfig
*/
private ServiceConfig $serviceConfig;

/**
* Get the providable id.
*
Expand All @@ -46,16 +53,6 @@ public function getName()
return $this->name ?? $this->id;
}

/**
* Get the providable service config.
*
* @return \Payavel\Orchestration\Fluent\ServiceConfig
*/
public function getServiceConfig()
{
return ServiceConfig::find($this->service_id);
}

/**
* Get the provider's related accounts.
*
Expand All @@ -73,11 +70,15 @@ public function accounts()
*/
private function getAccountModelClass()
{
if(! isset($this->accountModelClass)) {
if(!isset($this->accountModelClass)) {
$this->accountModelClass = $this->guessAccountModelClass();
}

return $this->getServiceConfig()->get("models.{$this->accountModelClass}", $this->accountModelClass);
if (!isset($this->serviceConfig)) {
$this->serviceConfig = ServiceConfig::find($this->service_id);
}

return $this->serviceConfig->get("models.{$this->accountModelClass}", $this->accountModelClass);
}


Expand Down
6 changes: 3 additions & 3 deletions tests/Feature/Console/TestOrchestrateProviderCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ public function orchestrate_provider_command_completes_without_asking_questions_
$serviceConfig = $this->createServiceConfig();
$provider = $this->createProvider($serviceConfig);

$gateway = $this->gatewayPath($provider->getServiceConfig(), $provider);
$gateway = $this->gatewayPath($serviceConfig, $provider);

$ds = DIRECTORY_SEPARATOR;
$this->artisan('orchestrate:provider', [
'provider' => $provider->getName(),
'--id' => $provider->getId(),
'--service' => $provider->getServiceConfig()->id,
'--service' => $serviceConfig->id,
])
->expectsOutputToContain("Gateway [app{$ds}{$gateway->request}] created successfully.")
->expectsOutputToContain("Gateway [app{$ds}{$gateway->response}] created successfully.")
->assertSuccessful();

$this->assertGatewayExists($provider->getServiceConfig(), $provider);
$this->assertGatewayExists($serviceConfig, $provider);
}

#[Test]
Expand Down
14 changes: 1 addition & 13 deletions tests/Traits/CreatesConfigServiceables.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,6 @@ public function linkAccountToProvider(Accountable $account, Providable $provider
throw new RuntimeException();
}

$serviceConfig = $account->getServiceConfig();

$providers = [
...$serviceConfig->get('accounts.'.$account->getId().'.providers', []),
$provider->getId() => $data,
];

$account->set('providers', $providers);

$serviceConfig->set(
'accounts.'.$account->id.'.providers',
$providers
);
$account->set('providers.'.$provider->getId(), $data);
}
}

0 comments on commit e2cf082

Please sign in to comment.