clock = new \App\Framework\DateTime\SystemClock(); $this->connection = Mockery::mock(ConnectionInterface::class); $this->repository = new DatabaseAssetVariantRepository($this->connection); }); it('saves variant to database', function () { $assetId = AssetId::generate($this->clock); $variant = AssetTestHelpers::createAssetVariant($assetId); $this->connection->shouldReceive('execute') ->once() ->with(Mockery::type(\App\Framework\Database\ValueObjects\SqlQuery::class)) ->andReturn(1); $this->repository->save($variant); }); it('finds variants by asset id', function () { $assetId = AssetId::generate($this->clock); $row = [ 'asset_id' => $assetId->toString(), 'variant' => '1200w.webp', 'bucket' => 'variants', 'key' => 'variants/2025/01/15/test/1200w.webp', 'mime' => 'image/webp', 'bytes' => 512, 'meta' => json_encode(['width' => 1200, 'height' => 675]), ]; $result = Mockery::mock(ResultInterface::class); $result->shouldReceive('fetchAll') ->once() ->andReturn([$row]); $this->connection->shouldReceive('query') ->once() ->andReturn($result); $found = $this->repository->findByAsset($assetId); expect($found)->toBeArray(); expect($found)->toHaveCount(1); expect($found[0])->toBeInstanceOf(AssetVariant::class); }); it('finds specific variant by asset id and variant name', function () { $assetId = AssetId::generate($this->clock); $variantName = VariantName::fromString('1200w.webp'); $row = [ 'asset_id' => $assetId->toString(), 'variant' => '1200w.webp', 'bucket' => 'variants', 'key' => 'variants/2025/01/15/test/1200w.webp', 'mime' => 'image/webp', 'bytes' => 512, 'meta' => json_encode(['width' => 1200, 'height' => 675]), ]; $result = Mockery::mock(ResultInterface::class); $result->shouldReceive('fetch') ->once() ->andReturn($row); $this->connection->shouldReceive('query') ->once() ->andReturn($result); $found = $this->repository->findByAssetAndVariant($assetId, $variantName); expect($found)->toBeInstanceOf(AssetVariant::class); expect($found->variant->equals($variantName))->toBeTrue(); }); it('deletes all variants for asset', function () { $assetId = AssetId::generate($this->clock); $this->connection->shouldReceive('execute') ->once() ->with(Mockery::type(\App\Framework\Database\ValueObjects\SqlQuery::class)) ->andReturn(1); $this->repository->deleteByAsset($assetId); }); });