getMockBuilder('Alchemy\Zippy\ProcessBuilder\ProcessBuilderFactory') ->disableOriginalConstructor() ->setMethods(array('useBinary')) ->getMock(); $outputParser = ParserFactory::create(ZipAdapter::getName()); $this->adapter = new ZipAdapter($outputParser, $this->getResourceManagerMock(), $inflator, $deflator); } /** * @expectedException Alchemy\Zippy\Exception\NotSupportedException */ public function testCreateNoFiles() { $mockProcessBuilder = $this->getMock('Symfony\Component\Process\ProcessBuilder'); $this->adapter->setInflator($this->getZippyMockBuilder($mockProcessBuilder)); $this->adapter->create(self::$zipFile, array()); } public function testCreate() { $mockProcessBuilder = $this->getMock('Symfony\Component\Process\ProcessBuilder'); $mockProcessBuilder ->expects($this->at(0)) ->method('add') ->with($this->equalTo('-r')) ->will($this->returnSelf()); $mockProcessBuilder ->expects($this->at(1)) ->method('add') ->with($this->equalTo(self::$zipFile)) ->will($this->returnSelf()); $mockProcessBuilder ->expects($this->at(2)) ->method('setWorkingDirectory') ->will($this->returnSelf()); $mockProcessBuilder ->expects($this->at(3)) ->method('add') ->with($this->equalTo('lalala')) ->will($this->returnSelf()); $mockProcessBuilder ->expects($this->once()) ->method('getProcess') ->will($this->returnValue($this->getSuccessFullMockProcess())); $manager = $this->getResourceManagerMock(__DIR__, array('lalala')); $outputParser = ParserFactory::create(ZipAdapter::getName()); $deflator = $this->getMockBuilder('Alchemy\Zippy\ProcessBuilder\ProcessBuilderFactory') ->disableOriginalConstructor() ->setMethods(array('useBinary')) ->getMock(); $this->adapter = new ZipAdapter($outputParser, $manager, $this->getZippyMockBuilder($mockProcessBuilder), $deflator); $this->adapter->create(self::$zipFile, array(__FILE__)); return self::$zipFile; } /** * @depends testCreate */ public function testOpen($zipFile) { $archive = $this->adapter->open($this->getResource($zipFile)); $this->assertInstanceOf('Alchemy\Zippy\Archive\ArchiveInterface', $archive); } public function testListMembers() { $resource = $this->getResource(self::$zipFile); $archive = $this->adapter->open($resource); $mockProcessBuilder = $this->getMock('Symfony\Component\Process\ProcessBuilder'); $mockProcessBuilder ->expects($this->at(0)) ->method('add') ->with($this->equalTo('-l')) ->will($this->returnSelf()); $mockProcessBuilder ->expects($this->at(1)) ->method('add') ->with($this->equalTo($resource->getResource())) ->will($this->returnSelf()); $mockProcessBuilder ->expects($this->once()) ->method('getProcess') ->will($this->returnValue($this->getSuccessFullMockProcess())); $this->adapter->setDeflator($this->getZippyMockBuilder($mockProcessBuilder)); $this->adapter->listMembers($resource); } public function testAddFile() { $resource = $this->getResource(self::$zipFile); $mockProcessBuilder = $this->getMock('Symfony\Component\Process\ProcessBuilder'); $mockProcessBuilder ->expects($this->at(0)) ->method('add') ->with($this->equalTo('-r')) ->will($this->returnSelf()); $mockProcessBuilder ->expects($this->at(1)) ->method('add') ->with($this->equalTo('-u')) ->will($this->returnSelf()); $mockProcessBuilder ->expects($this->at(2)) ->method('add') ->with($this->equalTo($resource->getResource())) ->will($this->returnSelf()); $mockProcessBuilder ->expects($this->once()) ->method('getProcess') ->will($this->returnValue($this->getSuccessFullMockProcess())); $this->adapter->setInflator($this->getZippyMockBuilder($mockProcessBuilder)); $this->adapter->add($resource, array(__DIR__ . '/../TestCase.php')); } public function testgetInflatorVersion() { $mockProcessBuilder = $this->getMock('Symfony\Component\Process\ProcessBuilder'); $mockProcessBuilder ->expects($this->at(0)) ->method('add') ->with($this->equalTo('-h')) ->will($this->returnSelf()); $mockProcessBuilder ->expects($this->once()) ->method('getProcess') ->will($this->returnValue($this->getSuccessFullMockProcess())); $this->adapter->setParser($this->getMock('Alchemy\Zippy\Parser\ParserInterface')); $this->adapter->setInflator($this->getZippyMockBuilder($mockProcessBuilder)); $this->adapter->getInflatorVersion(); } public function testgetDeflatorVersion() { $mockProcessBuilder = $this->getMock('Symfony\Component\Process\ProcessBuilder'); $mockProcessBuilder ->expects($this->at(0)) ->method('add') ->with($this->equalTo('-h')) ->will($this->returnSelf()); $mockProcessBuilder ->expects($this->once()) ->method('getProcess') ->will($this->returnValue($this->getSuccessFullMockProcess())); $this->adapter->setParser($this->getMock('Alchemy\Zippy\Parser\ParserInterface')); $this->adapter->setDeflator($this->getZippyMockBuilder($mockProcessBuilder)); $this->adapter->getDeflatorVersion(); } public function testRemoveMembers() { $resource = $this->getResource(self::$zipFile); $mockProcessBuilder = $this->getMock('Symfony\Component\Process\ProcessBuilder'); $mockProcessBuilder ->expects($this->at(0)) ->method('add') ->with($this->equalTo('-d')) ->will($this->returnSelf()); $mockProcessBuilder ->expects($this->at(1)) ->method('add') ->with($this->equalTo($resource->getResource())) ->will($this->returnSelf()); $mockProcessBuilder ->expects($this->at(2)) ->method('add') ->with($this->equalTo(__DIR__ . '/../TestCase.php')) ->will($this->returnSelf()); $mockProcessBuilder ->expects($this->at(3)) ->method('add') ->with($this->equalTo('path-to-file')) ->will($this->returnSelf()); $mockProcessBuilder ->expects($this->once()) ->method('getProcess') ->will($this->returnValue($this->getSuccessFullMockProcess())); $archiveFileMock = $this->getMock('Alchemy\Zippy\Archive\MemberInterface'); $archiveFileMock ->expects($this->any()) ->method('getLocation') ->will($this->returnValue('path-to-file')); $this->adapter->setInflator($this->getZippyMockBuilder($mockProcessBuilder)); $this->adapter->remove($resource, array( __DIR__ . '/../TestCase.php', $archiveFileMock )); } public function testExtract() { $resource = $this->getResource(self::$zipFile); $mockProcessBuilder = $this->getMock('Symfony\Component\Process\ProcessBuilder'); $mockProcessBuilder ->expects($this->at(0)) ->method('add') ->with($this->equalTo('-o')) ->will($this->returnSelf()); $mockProcessBuilder ->expects($this->at(1)) ->method('add') ->with($this->equalTo($resource->getResource())) ->will($this->returnSelf()); $mockProcessBuilder ->expects($this->once()) ->method('getProcess') ->will($this->returnValue($this->getSuccessFullMockProcess())); $this->adapter->setDeflator($this->getZippyMockBuilder($mockProcessBuilder)); $dir = $this->adapter->extract($resource); $pathinfo = pathinfo(self::$zipFile); $this->assertEquals($pathinfo['dirname'], $dir->getPath()); } public function testExtractWithExtractDirPrecised() { $resource = $this->getResource(self::$zipFile); $mockProcessBuilder = $this->getMock('Symfony\Component\Process\ProcessBuilder'); $mockProcessBuilder ->expects($this->at(0)) ->method('add') ->with($this->equalTo($resource->getResource())) ->will($this->returnSelf()); $mockProcessBuilder ->expects($this->at(1)) ->method('add') ->with($this->equalTo('-d')) ->will($this->returnSelf()); $mockProcessBuilder ->expects($this->at(2)) ->method('add') ->with($this->equalTo(__DIR__)) ->will($this->returnSelf()); $mockProcessBuilder ->expects($this->at(3)) ->method('add') ->with($this->equalTo(__FILE__)) ->will($this->returnSelf()); $mockProcessBuilder ->expects($this->once()) ->method('getProcess') ->will($this->returnValue($this->getSuccessFullMockProcess())); $this->adapter->setDeflator($this->getZippyMockBuilder($mockProcessBuilder)); $this->adapter->extractMembers($resource, array(__FILE__), __DIR__); } public function testGetName() { $this->assertEquals('zip', ZipAdapter::getName()); } public function testGetDefaultInflatorBinaryName() { $this->assertEquals(array('zip'), ZipAdapter::getDefaultInflatorBinaryName()); } public function testGetDefaultDeflatorBinaryName() { $this->assertEquals(array('unzip'), ZipAdapter::getDefaultDeflatorBinaryName()); } private function getSuccessFullMockProcess() { $mockProcess = $this ->getMockBuilder('Symfony\Component\Process\Process') ->disableOriginalConstructor() ->getMock(); $mockProcess ->expects($this->once()) ->method('run'); $mockProcess ->expects($this->once()) ->method('isSuccessful') ->will($this->returnValue(true)); return $mockProcess; } private function getZippyMockBuilder($mockedProcessBuilder) { $mockBuilder = $this->getMock('Alchemy\Zippy\ProcessBuilder\ProcessBuilderFactoryInterface'); $mockBuilder ->expects($this->once()) ->method('create') ->will($this->returnValue($mockedProcessBuilder)); return $mockBuilder; } }