Fix test bootstrap and ActorSyncer test doubles
This commit is contained in:
parent
d9b8853d11
commit
0698589d5b
2 changed files with 9 additions and 49 deletions
|
|
@ -12,7 +12,7 @@ use App\Gateway\TMDBGateway;
|
|||
use App\Import\ActorSyncer;
|
||||
use App\Model\TMDB\TMDBMovieCredit;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\Persistence\ObjectRepository;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ActorSyncerTest extends TestCase
|
||||
|
|
@ -36,60 +36,17 @@ class ActorSyncerTest extends TestCase
|
|||
]),
|
||||
);
|
||||
|
||||
$actorRepository = new class implements ObjectRepository {
|
||||
public function findAll(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
$actorRepository = $this->createMock(EntityRepository::class);
|
||||
$actorRepository->method('findOneBy')->willReturn(null);
|
||||
|
||||
public function findBy(array $criteria, array|null $orderBy = null, int|null $limit = null, int|null $offset = null): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function findOneBy(array $criteria): ?object
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getClassName(): string
|
||||
{
|
||||
return Actor::class;
|
||||
}
|
||||
};
|
||||
|
||||
$movieRoleRepository = new class implements ObjectRepository {
|
||||
public function findAll(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function findBy(array $criteria, array|null $orderBy = null, int|null $limit = null, int|null $offset = null): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function findOneBy(array $criteria): ?object
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getClassName(): string
|
||||
{
|
||||
return MovieRole::class;
|
||||
}
|
||||
|
||||
public function count(array $criteria = []): int
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
$movieRoleRepository = $this->createMock(EntityRepository::class);
|
||||
$movieRoleRepository->method('count')->willReturn(0);
|
||||
|
||||
$persisted = [];
|
||||
|
||||
$em = $this->createMock(EntityManagerInterface::class);
|
||||
$em->method('getRepository')->willReturnCallback(
|
||||
static fn (string $class): ObjectRepository => match ($class) {
|
||||
static fn (string $class): EntityRepository => match ($class) {
|
||||
Actor::class => $actorRepository,
|
||||
MovieRole::class => $movieRoleRepository,
|
||||
default => throw new \InvalidArgumentException("Unexpected repository for {$class}"),
|
||||
|
|
|
|||
|
|
@ -8,6 +8,9 @@ if (method_exists(Dotenv::class, 'bootEnv')) {
|
|||
(new Dotenv())->bootEnv(dirname(__DIR__).'/.env');
|
||||
}
|
||||
|
||||
$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = 'test';
|
||||
$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '1';
|
||||
|
||||
if ($_SERVER['APP_DEBUG']) {
|
||||
umask(0000);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue