53 lines
1.6 KiB
PHP
53 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace FecaMailshots\Tests\Unit;
|
|
|
|
use FecaMailshots\Application\SourceMetadataProvider;
|
|
|
|
final class FakeMetadataProvider implements SourceMetadataProvider
|
|
{
|
|
/** @var array<string, list<string>> */
|
|
private array $fields;
|
|
|
|
/** @param array<string, list<string>> $fields */
|
|
public function __construct(array $fields)
|
|
{
|
|
$this->fields = $fields;
|
|
}
|
|
|
|
public function sourceExists(string $source): bool
|
|
{
|
|
return isset($this->fields[$source]);
|
|
}
|
|
|
|
public function sourceFields(string $source): array
|
|
{
|
|
return $this->fields[$source] ?? [];
|
|
}
|
|
|
|
public function hasEmailField(string $source): bool
|
|
{
|
|
return in_array('Email', $this->fields[$source] ?? [], true) || in_array('email', $this->fields[$source] ?? [], true);
|
|
}
|
|
|
|
public function joinPath(string $left, string $right): ?array
|
|
{
|
|
$pairs = [
|
|
'contacts|accounts' => ['left' => 'contacts.Accountid', 'right' => 'accounts.ID'],
|
|
'accounts|contacts' => ['left' => 'accounts.ID', 'right' => 'contacts.Accountid'],
|
|
'renewals|accounts' => ['left' => 'renewals.account_id', 'right' => 'accounts.ID'],
|
|
'accounts|renewals' => ['left' => 'accounts.ID', 'right' => 'renewals.account_id'],
|
|
'renewals|contacts' => ['left' => 'renewals.account_id', 'right' => 'contacts.Accountid'],
|
|
'contacts|renewals' => ['left' => 'contacts.Accountid', 'right' => 'renewals.account_id'],
|
|
];
|
|
return $pairs[$left . '|' . $right] ?? null;
|
|
}
|
|
|
|
public function allKnownSources(): array
|
|
{
|
|
return array_keys($this->fields);
|
|
}
|
|
}
|