Some checks failed
Deploy Application / deploy (push) Has been cancelled
67 lines
2.0 KiB
PHP
67 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Framework\Database\ConnectionInterface;
|
|
use App\Framework\Database\Seed\SeedRepository;
|
|
use App\Framework\Database\ValueObjects\SqlQuery;
|
|
use App\Framework\DateTime\SystemClock;
|
|
|
|
describe('SeedRepository', function () {
|
|
beforeEach(function () {
|
|
$this->connection = Mockery::mock(ConnectionInterface::class);
|
|
$this->clock = new SystemClock();
|
|
$this->repository = new SeedRepository($this->connection, $this->clock);
|
|
});
|
|
|
|
it('checks if seeder has run', function () {
|
|
$result = Mockery::mock();
|
|
$result->shouldReceive('fetch')
|
|
->once()
|
|
->andReturn(['count' => 1]);
|
|
|
|
$this->connection->shouldReceive('query')
|
|
->once()
|
|
->with(Mockery::on(function (SqlQuery $query) {
|
|
return str_contains($query->sql, 'SELECT COUNT(*)');
|
|
}))
|
|
->andReturn($result);
|
|
|
|
expect($this->repository->hasRun('TestSeeder'))->toBeTrue();
|
|
});
|
|
|
|
it('returns false when seeder has not run', function () {
|
|
$result = Mockery::mock();
|
|
$result->shouldReceive('fetch')
|
|
->once()
|
|
->andReturn(['count' => 0]);
|
|
|
|
$this->connection->shouldReceive('query')
|
|
->once()
|
|
->andReturn($result);
|
|
|
|
expect($this->repository->hasRun('TestSeeder'))->toBeFalse();
|
|
});
|
|
|
|
it('marks seeder as run', function () {
|
|
$this->connection->shouldReceive('execute')
|
|
->once()
|
|
->with(Mockery::on(function (SqlQuery $query) {
|
|
return str_contains($query->sql, 'INSERT INTO seeds');
|
|
}));
|
|
|
|
$this->repository->markAsRun('TestSeeder', 'Test description');
|
|
});
|
|
|
|
it('clears all seeds', function () {
|
|
$this->connection->shouldReceive('execute')
|
|
->once()
|
|
->with(Mockery::on(function (SqlQuery $query) {
|
|
return str_contains($query->sql, 'DELETE FROM seeds');
|
|
}));
|
|
|
|
$this->repository->clearAll();
|
|
});
|
|
});
|
|
|