repository = Mockery::mock(AssetRepository::class); $this->service = new DeduplicationService($this->repository); }); it('returns null when no duplicate found', function () { $hash = Hash::create('test-content', HashAlgorithm::SHA256); $this->repository->shouldReceive('findBySha256') ->once() ->with($hash) ->andReturn(null); $result = $this->service->checkDuplicate($hash); expect($result)->toBeNull(); }); it('returns existing asset when duplicate found', function () { $clock = new SystemClock(); $hash = Hash::create('test-content', HashAlgorithm::SHA256); $asset = AssetTestHelpers::createAsset($clock); $this->repository->shouldReceive('findBySha256') ->once() ->with($hash) ->andReturn($asset); $result = $this->service->checkDuplicate($hash); expect($result)->toBe($asset); }); it('returns false when no duplicate exists', function () { $hash = Hash::create('test-content', HashAlgorithm::SHA256); $this->repository->shouldReceive('findBySha256') ->once() ->with($hash) ->andReturn(null); expect($this->service->isDuplicate($hash))->toBeFalse(); }); it('returns true when duplicate exists', function () { $clock = new SystemClock(); $hash = Hash::create('test-content', HashAlgorithm::SHA256); $asset = AssetTestHelpers::createAsset($clock); $this->repository->shouldReceive('findBySha256') ->once() ->with($hash) ->andReturn($asset); expect($this->service->isDuplicate($hash))->toBeTrue(); }); });