getExtensionManagerMock(); $comparator = new TaoComparator($extensionsManagerMock, $this->getExtensionHelperMock()); $versions = [ $versionFoo5 = new Version('Version5_foo'), $versionFoo3 = new Version('Version3_foo'), $extensionBar4 = new Version('Version4_bar'), $extensionBar2 = new Version('Version2_bar'), $extensionBaz1 = new Version('Version1_baz'), ]; usort($versions, [$comparator, 'compare']); $versionKeys = []; foreach ($versions as $version) { $versionKeys[] = (string) $version; } $this->assertEquals([ 'Version3_foo', 'Version5_foo', 'Version1_baz', 'Version2_bar', 'Version4_bar', ], $versionKeys); $this->assertTrue(0 > $comparator->compare(new Version('Version5_foo'), new Version('Version4_bar'))); $this->assertTrue(0 < $comparator->compare(new Version('Version4_bar'), new Version('Version1_baz'))); } private function getExtensionManagerMock() { $extensionFoo = $this->getMockBuilder(Extension::class) ->disableOriginalConstructor() ->getMock(); $extensionFoo->method('getId') ->willReturn('foo'); $extensionFoo->method('getDependencies') ->willReturn([]); $extensionBar = $this->getMockBuilder(Extension::class) ->disableOriginalConstructor() ->getMock(); $extensionBar->method('getId') ->willReturn('bar'); $extensionBar->method('getDependencies') ->willReturn(['foo' => '*', 'baz' => '*']); $extensionBaz = $this->getMockBuilder(Extension::class) ->disableOriginalConstructor() ->getMock(); $extensionBaz->method('getId') ->willReturn('baz'); $extensionBaz->method('getDependencies') ->willReturn(['foo' => '*']); $extensionsManagerMock = $this->getMockBuilder(ExtensionsManager::class) ->getMock(); $extensionsManagerMock->method('getInstalledExtensions') ->willReturn([ 'bar' => $extensionBar, 'foo' => $extensionFoo ]); $extensionsManagerMock->method('getExtensionById') ->willReturnMap([ ['baz', $extensionBaz], ['bar', $extensionBar], ['foo', $extensionFoo] ]); return $extensionsManagerMock; } private function getExtensionHelperMock() { return new ExtensionHelper(); } }