container = $this->prophesize(ContainerInterface::class); $this->em = $this->prophesize(EntityManagerInterface::class); $this->container->get(EntityManager::class)->willReturn($this->em->reveal()); $this->factory = new ConnectionFactory(); } /** @test */ public function properServiceFallbackOccursWhenInvoked(): void { $connection = $this->prophesize(Connection::class)->reveal(); $getConnection = $this->em->getConnection()->willReturn($connection); $result = ($this->factory)($this->container->reveal()); $this->assertSame($connection, $result); $getConnection->shouldHaveBeenCalledOnce(); $this->container->get(EntityManager::class)->shouldHaveBeenCalledOnce(); } }