mockExtension('ext1', []); $ext2 = $this->mockExtension('ext2', ['ext1']); $ext3 = $this->mockExtension('ext3', ['ext2']); $sorted = \helpers_ExtensionHelper::sortByDependencies([$ext2,$ext3,$ext1]); $this->assertEquals([$ext1,$ext2,$ext3], array_values($sorted)); } public function testCyclicDependencies() { $this->expectException(common_exception_Error::class); $ext1 = $this->mockExtension('ext1', ['ext2']); $ext2 = $this->mockExtension('ext2', ['ext3']); $ext3 = $this->mockExtension('ext3', ['ext1']); $sorted = \helpers_ExtensionHelper::sortByDependencies([$ext2,$ext3,$ext1]); } public function testMissingDependencies() { $this->expectException(common_exception_Error::class); $ext1 = $this->mockExtension('ext1', []); $ext2 = $this->mockExtension('ext2', ['ext4']); $ext3 = $this->mockExtension('ext3', ['ext2','ext4']); $sorted = \helpers_ExtensionHelper::sortByDependencies([$ext2,$ext3,$ext1]); } /** * Moch an extension with its dependencies * @param string $id * @param array $dependencies * @return \common_ext_Extension::class */ protected function mockExtension($id, $dependencies = []) { $prophet = $this->prophesize(); $ext = $this->prophesize(\common_ext_Extension::class); $ext->getId()->willReturn($id); $ext->getDependencies()->willReturn(array_fill_keys($dependencies, '>=0')); return $ext->reveal(); } }