public function testZipShouldBePreferredOverPharEvenWhenRepeated() { $files = [new File('test.zip', new Format\Zip()), new File('test.phar', new Format\Phar()), new File('test.ph', new Format\Phar())]; $methodMock = m::mock('Distill\\Method\\MethodInterface'); $methodMock->shouldReceive('isSupported')->andReturn(true); $methodMock->shouldReceive('isFormatSupported')->andReturn(true); $methodMock->shouldReceive('getUncompressionSpeedLevel')->withAnyArgs()->andReturnUsing(function ($format) { if ($format instanceof Format\Zip) { return MethodInterface::SPEED_LEVEL_HIGHEST; } else { return MethodInterface::SPEED_LEVEL_LOWEST; } })->getMock(); $preferredFiles = $this->strategy->getPreferredFilesOrdered($files, [$methodMock]); $this->assertInstanceOf('\\Distill\\Format\\Zip', $preferredFiles[0]->getFormat()); array_reverse($files); $preferredFiles = $this->strategy->getPreferredFilesOrdered($files, [$methodMock]); $this->assertInstanceOf('\\Distill\\Format\\Zip', $preferredFiles[0]->getFormat()); }
protected function registerStrategies(Container $container) { $container['distill.strategy.' . Strategy\MinimumSize::getName()] = $container->factory(function ($c) { return new Strategy\MinimumSize(); }); $container['distill.strategy.' . Strategy\UncompressionSpeed::getName()] = $container->factory(function ($c) { return new Strategy\UncompressionSpeed(); }); $container['distill.strategy.' . Strategy\Random::getName()] = $container->factory(function ($c) { return new Strategy\Random(); }); }