prophesize(DataboxBoundRepositoryFactory::class); $factory ->createRepositoryFor(Argument::type('integer')) ->will(function ($args) { return (object)['databoxId' => $args[0]]; }); $this->sut = new DataboxBoundRepositoryProvider($factory->reveal()); } public function testItCreatesRepositoriesIfUnknown() { $repository = $this->sut->getRepositoryForDatabox(42); $this->assertNotNull($repository, 'Failed to create a repository'); $this->assertSame($repository, $this->sut->getRepositoryForDatabox(42)); } public function testItShouldNotCreateTwoRepositoriesPerDatabox() { $repository1 = $this->sut->getRepositoryForDatabox(1); $repository2 = $this->sut->getRepositoryForDatabox(2); $this->assertNotNull($repository1, 'Failed to create first repository'); $this->assertNotNull($repository2, 'Failed to create second repository'); $this->assertNotSame($repository1, $repository2, 'Different Databoxes should have different repositories'); $this->assertSame($repository2, $this->sut->getRepositoryForDatabox(2), 'Second Repository should be returned'); $this->assertSame($repository1, $this->sut->getRepositoryForDatabox(1), 'First Repository should be returned'); } }