How to use setWorkingDirectory method of builder class

Best Atoum code snippet using builder.setWorkingDirectory

FilesystemTest.php

Source:FilesystemTest.php Github

copy

Full Screen

...30{31 public function testSetWorkingDirectory()32 {33 $filesystem = new Magento_Filesystem($this->_getDefaultAdapterMock());34 $filesystem->setWorkingDirectory('/tmp');35 $this->assertEquals('/tmp', $filesystem->getWorkingDirectory());36 }37 /**38 * @expectedException InvalidArgumentException39 * @exceptedExceptionMessage Working directory "/tmp" does not exists40 */41 public function testSetWorkingDirectoryException()42 {43 $adapterMock = $this->getMockBuilder('Magento_Filesystem_AdapterInterface')44 ->getMock();45 $adapterMock->expects($this->once())46 ->method('isDirectory')47 ->with('/tmp')48 ->will($this->returnValue(false));49 $filesystem = new Magento_Filesystem($adapterMock);50 $filesystem->setWorkingDirectory('/tmp');51 }52 /**53 * @dataProvider allowCreateDirectoriesDataProvider54 * @param bool $allow55 * @param int $mode56 */57 public function testSetIsAllowCreateDirectories($allow, $mode)58 {59 $adapterMock = $this->getMockBuilder('Magento_Filesystem_AdapterInterface')60 ->getMock();61 $filesystem = new Magento_Filesystem($adapterMock);62 $this->assertSame($filesystem, $filesystem->setIsAllowCreateDirectories($allow, $mode));63 $this->assertAttributeEquals($allow, '_isAllowCreateDirs', $filesystem);64 if (!$mode) {65 $mode = 0777;66 }67 $this->assertAttributeEquals($mode, '_newDirPermissions', $filesystem);68 }69 /**70 * @return array71 */72 public function allowCreateDirectoriesDataProvider()73 {74 return array(75 array(true, 0644),76 array(false, null)77 );78 }79 /**80 * @dataProvider twoFilesOperationsValidDataProvider81 *82 * @param string $method83 * @param string $checkMethod84 * @param string $source85 * @param string $target86 * @param string|null $workingDirectory87 * @param string|null $targetDir88 */89 public function testTwoFilesOperation($method, $checkMethod, $source, $target, $workingDirectory = null,90 $targetDir = null91 ) {92 $adapterMock = $this->getMockBuilder('Magento_Filesystem_AdapterInterface')93 ->getMock();94 $adapterMock->expects($this->exactly(2))95 ->method('isDirectory')96 ->will($this->returnValue(true));97 $adapterMock->expects($this->once())98 ->method($checkMethod)99 ->will($this->returnValue(true));100 $adapterMock->expects($this->once())101 ->method($method)102 ->with($source, $target);103 $filesystem = new Magento_Filesystem($adapterMock);104 $filesystem->setWorkingDirectory('/tmp');105 $filesystem->$method($source, $target, $workingDirectory, $targetDir);106 }107 /**108 * @return array109 */110 public function twoFilesOperationsValidDataProvider()111 {112 return array(113 'copy both tmp' => array('copy', 'isFile', '/tmp/path/file001.log', '/tmp/path/file001.bak'),114 'move both tmp' => array('rename', 'exists', '/tmp/path/file001.log', '/tmp/path/file001.bak'),115 'copy both tmp #2' => array('copy', 'isFile', '/tmp/path/file001.log', '/tmp/path/file001.bak', '/tmp'),116 'move both tmp #2' => array('rename', 'exists', '/tmp/path/file001.log', '/tmp/path/file001.bak', '/tmp'),117 'copy different'118 => array('copy', 'isFile', '/tmp/path/file001.log', '/storage/file001.bak', null, '/storage'),119 'move different'120 => array('rename', 'exists', '/tmp/path/file001.log', '/storage/file001.bak', null, '/storage'),121 'copy different #2'122 => array('copy', 'isFile', '/tmp/path/file001.log', '/storage/file001.bak', '/tmp', '/storage'),123 'move different #2'124 => array('rename', 'exists', '/tmp/path/file001.log', '/storage/file001.bak', '/tmp', '/storage'),125 );126 }127 /**128 * @dataProvider twoFilesOperationsInvalidDataProvider129 * @param string $method130 * @param string $source131 * @param string $destination132 * @param string $exceptionMessage133 * @param string|null $workingDirectory134 * @param string|null $targetDir135 */136 public function testTwoFilesOperationsIsolationException(137 $method, $source, $destination, $exceptionMessage, $workingDirectory = null, $targetDir = null138 ) {139 $adapterMock = $this->_getDefaultAdapterMock();140 $adapterMock->expects($this->never())141 ->method($method);142 $filesystem = new Magento_Filesystem($adapterMock);143 $filesystem->setWorkingDirectory('/tmp');144 $this->setExpectedException('InvalidArgumentException', $exceptionMessage);145 $filesystem->$method($source, $destination, $workingDirectory, $targetDir);146 }147 /**148 * @return array149 */150 public function twoFilesOperationsInvalidDataProvider()151 {152 return array(153 'copy first path invalid' => array(154 'copy',155 '/tmp/../etc/passwd',156 '/tmp/path001',157 "Path '/tmp/../etc/passwd' is out of working directory '/tmp'",158 ),159 'copy first path invalid #2' => array(160 'copy',161 '/tmp/../etc/passwd',162 '/tmp/path001',163 "Path '/tmp/../etc/passwd' is out of working directory '/tmp'",164 '/tmp'165 ),166 'copy second path invalid' => array(167 'copy',168 '/tmp/uploaded.txt',169 '/tmp/../etc/passwd',170 "Path '/tmp/../etc/passwd' is out of working directory '/tmp'",171 ),172 'copy both path invalid' => array(173 'copy',174 '/tmp/../etc/passwd',175 '/tmp/../dev/null',176 "Path '/tmp/../etc/passwd' is out of working directory '/tmp'",177 ),178 'rename first path invalid' => array(179 'rename',180 '/tmp/../etc/passwd',181 '/tmp/path001',182 "Path '/tmp/../etc/passwd' is out of working directory '/tmp'",183 ),184 'rename first path invalid #2' => array(185 'rename',186 '/tmp/../etc/passwd',187 '/tmp/path001',188 "Path '/tmp/../etc/passwd' is out of working directory '/tmp'",189 '/tmp'190 ),191 'rename second path invalid' => array(192 'rename',193 '/tmp/uploaded.txt',194 '/tmp/../etc/passwd',195 "Path '/tmp/../etc/passwd' is out of working directory '/tmp'",196 ),197 'rename both path invalid' => array(198 'rename',199 '/tmp/../etc/passwd',200 '/tmp/../dev/null',201 "Path '/tmp/../etc/passwd' is out of working directory '/tmp'",202 ),203 'copy target path invalid' => array(204 'copy',205 '/tmp/passwd',206 '/etc/../dev/null',207 "Path '/etc/../dev/null' is out of working directory '/etc'",208 null,209 '/etc'210 ),211 'rename target path invalid' => array(212 'rename',213 '/tmp/passwd',214 '/etc/../dev/null',215 "Path '/etc/../dev/null' is out of working directory '/etc'",216 null,217 '/etc'218 ),219 'copy target path invalid #2' => array(220 'copy',221 '/tmp/passwd',222 '/etc/../dev/null',223 "Path '/etc/../dev/null' is out of working directory '/etc'",224 '/tmp',225 '/etc'226 ),227 'rename target path invalid #2' => array(228 'rename',229 '/tmp/passwd',230 '/etc/../dev/null',231 "Path '/etc/../dev/null' is out of working directory '/etc'",232 '/tmp',233 '/etc'234 ),235 );236 }237 public function testEnsureDirectoryExists()238 {239 $dir = '/tmp/path';240 $adapterMock = $this->getMockBuilder('Magento_Filesystem_AdapterInterface')241 ->getMock();242 $adapterMock->expects($this->at(0))243 ->method('isDirectory')244 ->with('/tmp')245 ->will($this->returnValue(true));246 $adapterMock->expects($this->at(1))247 ->method('isDirectory')248 ->with($dir)249 ->will($this->returnValue(true));250 $adapterMock->expects($this->exactly(2))251 ->method('isDirectory');252 $adapterMock->expects($this->never())253 ->method('createDirectory');254 $filesystem = new Magento_Filesystem($adapterMock);255 $filesystem->setWorkingDirectory('/tmp');256 $filesystem->ensureDirectoryExists($dir, 0644);257 }258 /**259 * @expectedException Magento_Filesystem_Exception260 * @expectedExceptionMessage Directory '/tmp/path' doesn't exist.261 */262 public function testEnsureDirectoryExistsException()263 {264 $dir = '/tmp/path';265 $adapterMock = $this->getMockBuilder('Magento_Filesystem_AdapterInterface')266 ->getMock();267 $adapterMock->expects($this->at(0))268 ->method('isDirectory')269 ->with('/tmp')270 ->will($this->returnValue(true));271 $adapterMock->expects($this->at(1))272 ->method('isDirectory')273 ->with($dir)274 ->will($this->returnValue(false));275 $adapterMock->expects($this->exactly(2))276 ->method('isDirectory');277 $adapterMock->expects($this->never())278 ->method('createDirectory');279 $filesystem = new Magento_Filesystem($adapterMock);280 $filesystem->setWorkingDirectory('/tmp');281 $filesystem->ensureDirectoryExists($dir, 0644);282 }283 public function testEnsureDirectoryExistsNoDir()284 {285 $dir = '/tmp/path1/path2';286 $adapterMock = $this->getMockBuilder('Magento_Filesystem_AdapterInterface')287 ->getMock();288 $adapterMock->expects($this->at(0))289 ->method('isDirectory')290 ->with('/tmp')291 ->will($this->returnValue(true));292 $adapterMock->expects($this->at(1))293 ->method('isDirectory')294 ->with($dir)295 ->will($this->returnValue(false));296 $adapterMock->expects($this->at(2))297 ->method('isDirectory')298 ->with('/tmp/path1')299 ->will($this->returnValue(false));300 $adapterMock->expects($this->at(3))301 ->method('isDirectory')302 ->with('/tmp')303 ->will($this->returnValue(true));304 $adapterMock->expects($this->exactly(4))305 ->method('isDirectory');306 $adapterMock->expects($this->at(4))307 ->method('createDirectory')308 ->with('/tmp/path1');309 $adapterMock->expects($this->at(5))310 ->method('createDirectory')311 ->with('/tmp/path1/path2');312 $adapterMock->expects($this->exactly(2))313 ->method('createDirectory');314 $filesystem = new Magento_Filesystem($adapterMock);315 $filesystem->setWorkingDirectory('/tmp');316 $filesystem->setIsAllowCreateDirectories(true);317 $filesystem->ensureDirectoryExists($dir, 0644);318 }319 /**320 * @dataProvider allowCreateDirsDataProvider321 * @param bool $allowCreateDirs322 */323 public function testTouch($allowCreateDirs)324 {325 $validPath = '/tmp/path/file.txt';326 $adapterMock = $this->getMockBuilder('Magento_Filesystem_AdapterInterface')327 ->getMock();328 $adapterMock->expects($this->exactly(2))329 ->method('isDirectory')330 ->will($this->returnValue(true));331 $filesystem = new Magento_Filesystem($adapterMock);332 $filesystem->setIsAllowCreateDirectories($allowCreateDirs);333 $filesystem->setWorkingDirectory('/tmp');334 $filesystem->touch($validPath);335 }336 /**337 * @expectedException InvalidArgumentException338 * @expectedExceptionMessage Path '/etc/passwd' is out of working directory '/tmp'339 */340 public function testTouchIsolation()341 {342 $filesystem = new Magento_Filesystem($this->_getDefaultAdapterMock());343 $filesystem->setWorkingDirectory('/tmp');344 $filesystem->touch('/etc/passwd');345 }346 /**347 * @return array348 */349 public function allowCreateDirsDataProvider()350 {351 return array(array(true), array(false));352 }353 public function testCreateStreamCustom()354 {355 $path = '/tmp/test.txt';356 $streamMock = $this->getMockBuilder('Magento_Filesystem_Stream_Local')357 ->disableOriginalConstructor()358 ->getMock();359 $adapterMock = $this->getMockBuilder('Magento_Filesystem_Adapter_Local')360 ->getMock();361 $adapterMock->expects($this->once())362 ->method('isDirectory')363 ->with('/tmp')364 ->will($this->returnValue(true));365 $adapterMock->expects($this->once())366 ->method('createStream')367 ->with($path)368 ->will($this->returnValue($streamMock));369 $filesystem = new Magento_Filesystem($adapterMock);370 $filesystem->setWorkingDirectory('/tmp');371 $this->assertInstanceOf('Magento_Filesystem_Stream_Local', $filesystem->createStream($path));372 }373 /**374 * @expectedException InvalidArgumentException375 * @expectedExceptionMessage Path '/tmp/../etc/test.txt' is out of working directory '/tmp'376 */377 public function testCreateStreamIsolation()378 {379 $adapterMock = $this->getMockBuilder('Magento_Filesystem_Adapter_Local')380 ->getMock();381 $adapterMock->expects($this->once())382 ->method('isDirectory')383 ->with('/tmp')384 ->will($this->returnValue(true));385 $filesystem = new Magento_Filesystem($adapterMock);386 $filesystem->setWorkingDirectory('/tmp');387 $filesystem->createStream('/tmp/../etc/test.txt');388 }389 /**390 * @expectedException Magento_Filesystem_Exception391 * @expectedExceptionMessage Filesystem doesn't support streams.392 */393 public function testCreateStreamException()394 {395 $filesystem = new Magento_Filesystem($this->_getDefaultAdapterMock());396 $filesystem->setWorkingDirectory('/tmp');397 $filesystem->createStream('/tmp/test.txt');398 }399 /**400 * @dataProvider modeDataProvider401 * @param string|Magento_Filesystem_Stream_Mode $mode402 */403 public function testCreateAndOpenStream($mode)404 {405 $path = '/tmp/test.txt';406 $streamMock = $this->getMockBuilder('Magento_Filesystem_Stream_Local')407 ->disableOriginalConstructor()408 ->getMock();409 $streamMock->expects($this->once())410 ->method('open');411 $adapterMock = $this->getMockBuilder('Magento_Filesystem_Adapter_Local')412 ->getMock();413 $adapterMock->expects($this->once())414 ->method('isDirectory')415 ->with('/tmp')416 ->will($this->returnValue(true));417 $adapterMock->expects($this->once())418 ->method('createStream')419 ->with($path)420 ->will($this->returnValue($streamMock));421 $filesystem = new Magento_Filesystem($adapterMock);422 $filesystem->setWorkingDirectory('/tmp');423 $this->assertInstanceOf('Magento_Filesystem_Stream_Local', $filesystem->createAndOpenStream($path, $mode));424 }425 /**426 * @expectedException InvalidArgumentException427 * @expectedExceptionMessage Wrong mode parameter428 */429 public function testCreateAndOpenStreamException()430 {431 $path = '/tmp/test.txt';432 $streamMock = $this->getMockBuilder('Magento_Filesystem_Stream_Local')433 ->disableOriginalConstructor()434 ->getMock();435 $streamMock->expects($this->never())436 ->method('open');437 $adapterMock = $this->getMockBuilder('Magento_Filesystem_Adapter_Local')438 ->getMock();439 $adapterMock->expects($this->once())440 ->method('isDirectory')441 ->with('/tmp')442 ->will($this->returnValue(true));443 $adapterMock->expects($this->once())444 ->method('createStream')445 ->with($path)446 ->will($this->returnValue($streamMock));447 $filesystem = new Magento_Filesystem($adapterMock);448 $filesystem->setWorkingDirectory('/tmp');449 $this->assertInstanceOf('Magento_Filesystem_Stream_Local',450 $filesystem->createAndOpenStream($path, new stdClass()));451 }452 /**453 * @return array454 */455 public function modeDataProvider()456 {457 return array(458 array('r'),459 array(new Magento_Filesystem_Stream_Mode('w'))460 );461 }462 /**463 * @dataProvider adapterMethods464 * @param string $method465 * @param string $adapterMethod466 * @param array|null $params467 */468 public function testAdapterMethods($method, $adapterMethod, array $params = null)469 {470 $validPath = '/tmp/path/file.txt';471 $adapterMock = $this->_getDefaultAdapterMock();472 $adapterMock->expects($this->once())473 ->method($adapterMethod)474 ->with($validPath);475 $filesystem = new Magento_Filesystem($adapterMock);476 $filesystem->setWorkingDirectory('/tmp');477 $params = (array)$params;478 array_unshift($params, $validPath);479 call_user_func_array(array($filesystem, $method), $params);480 }481 /**482 * @return array483 */484 public function adapterMethods()485 {486 return array(487 'exists' => array('has', 'exists'),488 'delete' => array('delete', 'delete'),489 'isFile' => array('isFile', 'isFile'),490 'isWritable' => array('isWritable', 'isWritable'),491 'isReadable' => array('isReadable', 'isReadable'),492 'getNestedKeys' => array('getNestedKeys', 'getNestedKeys'),493 'changePermissions' => array('changePermissions', 'changePermissions', array(0777, true)),494 'exists #2' => array('has', 'exists', array('/tmp')),495 'delete #2' => array('delete', 'delete', array('/tmp')),496 'isFile #2' => array('isFile', 'isFile', array('/tmp')),497 'isWritable #2' => array('isWritable', 'isWritable', array('/tmp')),498 'isReadable #2' => array('isReadable', 'isReadable', array('/tmp')),499 'getNestedKeys #2' => array('getNestedKeys', 'getNestedKeys', array('/tmp')),500 'changePermissions #2' => array('changePermissions', 'changePermissions', array(0777, true, '/tmp')),501 );502 }503 /**504 * @expectedException InvalidArgumentException505 * @expectedExceptionMessage Path '/tmp/../etc/passwd' is out of working directory '/tmp'506 * @dataProvider adapterIsolationMethods507 * @param string $method508 * @param string $adapterMethod509 * @param array|null $params510 */511 public function testIsolationException($method, $adapterMethod, array $params = null)512 {513 $invalidPath = '/tmp/../etc/passwd';514 $adapterMock = $this->_getDefaultAdapterMock();515 $adapterMock->expects($this->never())516 ->method($adapterMethod);517 $filesystem = new Magento_Filesystem($adapterMock);518 $filesystem->setWorkingDirectory('/tmp');519 $params = (array)$params;520 array_unshift($params, $invalidPath);521 call_user_func_array(array($filesystem, $method), $params);522 }523 /**524 * @return array525 */526 public function adapterIsolationMethods()527 {528 return $this->adapterMethods()529 + array(530 'mtime' => array('getMTime', 'getMTime'),531 'read' => array('read', 'read'),532 'read #2' => array('read', 'read', array('/tmp')),533 'createDirectory' => array('createDirectory', 'createDirectory', array(0777)),534 'createDirectory #2' => array('createDirectory', 'createDirectory', array(0777, '/tmp')),535 'getFileMd5' => array('getFileMd5', 'getFileMd5'),536 'getFileSize' => array('getFileSize', 'getFileSize')537 );538 }539 /**540 * @dataProvider adapterMethodsWithFileCheckDataProvider541 * @param string $method542 * @param string $adapterMethod543 */544 public function testAdapterMethodsWithFileChecks($method, $adapterMethod)545 {546 $validPath = '/tmp/path/file.txt';547 $adapterMock = $this->_getDefaultAdapterMock();548 $adapterMock->expects($this->once())549 ->method('isFile')550 ->with($validPath)551 ->will($this->returnValue(true));552 $adapterMock->expects($this->once())553 ->method($adapterMethod)554 ->with($validPath)555 ->will($this->returnValue(1));556 $filesystem = new Magento_Filesystem($adapterMock);557 $filesystem->setWorkingDirectory('/tmp');558 $this->assertEquals(1, $filesystem->$method($validPath));559 }560 /**561 * @return array562 */563 public function adapterMethodsWithFileCheckDataProvider()564 {565 return array(566 'read' => array('read', 'read'),567 'getFileMd5' => array('getFileMd5', 'getFileMd5'),568 'getFileSize' => array('getFileSize', 'getFileSize')569 );570 }571 /**572 * @dataProvider workingDirDataProvider573 * @param string|null $workingDirectory574 */575 public function testCreateDirectory($workingDirectory)576 {577 $validPath = '/tmp/path';578 $adapterMock = $this->getMockBuilder('Magento_Filesystem_AdapterInterface')579 ->getMock();580 $adapterMock->expects($this->exactly(2))581 ->method('isDirectory')582 ->with('/tmp')583 ->will($this->returnValue(true));584 $adapterMock->expects($this->once())585 ->method('createDirectory')586 ->with($validPath);587 $filesystem = new Magento_Filesystem($adapterMock);588 $filesystem->setWorkingDirectory('/tmp');589 $filesystem->createDirectory($validPath, 0777, $workingDirectory);590 }591 /**592 * @dataProvider workingDirDataProvider593 * @param string|null $workingDirectory594 */595 public function testWrite($workingDirectory)596 {597 $validPath = '/tmp/path/file.txt';598 $adapterMock = $this->getMockBuilder('Magento_Filesystem_AdapterInterface')599 ->getMock();600 $adapterMock->expects($this->at(0))601 ->method('isDirectory')602 ->with('/tmp')603 ->will($this->returnValue(true));604 $adapterMock->expects($this->at(1))605 ->method('isDirectory')606 ->with('/tmp/path')607 ->will($this->returnValue(true));608 $adapterMock->expects($this->exactly(2))609 ->method('isDirectory');610 $adapterMock->expects($this->once())611 ->method('write')612 ->with($validPath, 'TEST TEST');613 $filesystem = new Magento_Filesystem($adapterMock);614 $filesystem->setWorkingDirectory('/tmp');615 $filesystem->write($validPath, 'TEST TEST', $workingDirectory);616 }617 /**618 * @expectedException InvalidArgumentException619 * @expectedExceptionMessage Path '/tmp/../path/file.txt' is out of working directory '/tmp'620 * @dataProvider workingDirDataProvider621 * @param string|null $workingDirectory622 */623 public function testWriteIsolation($workingDirectory)624 {625 $invalidPath = '/tmp/../path/file.txt';626 $adapterMock = $this->getMockBuilder('Magento_Filesystem_AdapterInterface')627 ->getMock();628 $adapterMock->expects($this->once())629 ->method('isDirectory')630 ->with('/tmp')631 ->will($this->returnValue(true));632 $adapterMock->expects($this->never())633 ->method('write');634 $filesystem = new Magento_Filesystem($adapterMock);635 $filesystem->setWorkingDirectory('/tmp');636 $filesystem->write($invalidPath, 'TEST TEST', $workingDirectory);637 }638 /**639 * @return array640 */641 public function workingDirDataProvider()642 {643 return array(644 array(null), array('/tmp')645 );646 }647 /**648 * @expectedException InvalidArgumentException649 * @expectedExceptionMessage "/tmp/test/file.txt" does not exists650 * @dataProvider methodsWithFileChecksDataProvider651 * @param string $method652 * @param array|null $params653 */654 public function testFileChecks($method, array $params = null)655 {656 $path = '/tmp/test/file.txt';657 $adapterMock = $this->getMockBuilder('Magento_Filesystem_AdapterInterface')658 ->getMock();659 $adapterMock->expects($this->once())660 ->method('isDirectory')661 ->with('/tmp')662 ->will($this->returnValue(true));663 $adapterMock->expects($this->once())664 ->method('exists')665 ->with($path)666 ->will($this->returnValue(false));667 $filesystem = new Magento_Filesystem($adapterMock);668 $filesystem->setWorkingDirectory('/tmp');669 $params = (array)$params;670 array_unshift($params, $path);671 call_user_func_array(array($filesystem, $method), $params);672 }673 /**674 * @return array675 */676 public function methodsWithFileChecksDataProvider()677 {678 return array(679 'rename' => array('rename', array('/tmp/file001.txt'))680 );681 }682 /**683 * @expectedException InvalidArgumentException684 * @expectedExceptionMessage "/tmp/test/file.txt" does not exists685 * @dataProvider methodsWithPathChecksDataProvider686 * @param string $method687 * @param array|null $params688 */689 public function testPathChecks($method, array $params = null)690 {691 $path = '/tmp/test/file.txt';692 $adapterMock = $this->getMockBuilder('Magento_Filesystem_AdapterInterface')693 ->getMock();694 $adapterMock->expects($this->once())695 ->method('isDirectory')696 ->with('/tmp')697 ->will($this->returnValue(true));698 $adapterMock->expects($this->once())699 ->method('isFile')700 ->with($path)701 ->will($this->returnValue(false));702 $filesystem = new Magento_Filesystem($adapterMock);703 $filesystem->setWorkingDirectory('/tmp');704 $params = (array)$params;705 array_unshift($params, $path);706 call_user_func_array(array($filesystem, $method), $params);707 }708 /**709 * @return array710 */711 public function methodsWithPathChecksDataProvider()712 {713 return array(714 'read' => array('read'),715 'copy' => array('copy', array('/tmp/file001.txt')),716 );717 }718 /**719 * Test isDirectory720 *721 * @dataProvider workingDirDataProvider722 * @param string|null $workingDirectory723 */724 public function testIsDirectory($workingDirectory)725 {726 $validPath = '/tmp/path';727 $adapterMock = $this->getMockBuilder('Magento_Filesystem_AdapterInterface')728 ->getMock();729 $adapterMock->expects($this->at(0))730 ->method('isDirectory')731 ->with('/tmp')732 ->will($this->returnValue(true));733 $adapterMock->expects($this->at(1))734 ->method('isDirectory')735 ->with($validPath)736 ->will($this->returnValue(true));737 $adapterMock->expects($this->exactly(2))738 ->method('isDirectory');739 $filesystem = new Magento_Filesystem($adapterMock);740 $filesystem->setWorkingDirectory('/tmp');741 $this->assertTrue($filesystem->isDirectory($validPath, $workingDirectory));742 }743 /**744 * Test isDirectory isolation745 * @expectedException InvalidArgumentException746 * @expectedExceptionMessage Path '/tmp/../etc/passwd' is out of working directory '/tmp'747 * @dataProvider workingDirDataProvider748 * @param string|null $workingDirectory749 */750 public function testIsDirectoryIsolation($workingDirectory)751 {752 $validPath = '/tmp/../etc/passwd';753 $filesystem = new Magento_Filesystem($this->_getDefaultAdapterMock());754 $filesystem->setWorkingDirectory('/tmp');755 $this->assertTrue($filesystem->isDirectory($validPath, $workingDirectory));756 }757 /**758 * @dataProvider absolutePathDataProvider759 * @param string $path760 * @param string $expected761 */762 public function testGetAbsolutePath($path, $expected)763 {764 $this->assertEquals($expected, Magento_Filesystem::getAbsolutePath($path));765 }766 /**767 * @return array768 */769 public function absolutePathDataProvider()770 {771 return array(772 array('/tmp/../file.txt', '/file.txt'),773 array('/tmp/../etc/mysql/file.txt', '/etc/mysql/file.txt'),774 array('/tmp/../file.txt', '/file.txt'),775 array('/tmp/./file.txt', '/tmp/file.txt'),776 array('/tmp/./../file.txt', '/file.txt'),777 array('/tmp/../../../file.txt', '/file.txt'),778 array('../file.txt', '/file.txt'),779 array('/../file.txt', '/file.txt'),780 array('/tmp/path/file.txt', '/tmp/path/file.txt'),781 array('/tmp/path', '/tmp/path'),782 array('C:\\Windows', 'C:/Windows'),783 array('C:\\Windows\\system32\\..', 'C:/Windows'),784 );785 }786 /**787 * @dataProvider pathDataProvider788 * @param array $parts789 * @param string $expected790 * @param bool $isAbsolute791 */792 public function testGetPathFromArray(array $parts, $expected, $isAbsolute)793 {794 $expected = Magento_Filesystem::fixSeparator($expected);795 $this->assertEquals($expected, Magento_Filesystem::getPathFromArray($parts, $isAbsolute));796 }797 /**798 * @return array799 */800 public function pathDataProvider()801 {802 return array(803 array(array('etc', 'mysql', 'my.cnf'), '/etc/mysql/my.cnf',true),804 array(array('etc', 'mysql', 'my.cnf'), 'etc/mysql/my.cnf', false),805 array(array('C:', 'Windows', 'my.cnf'), 'C:/Windows/my.cnf', false),806 array(array('C:', 'Windows', 'my.cnf'), 'C:/Windows/my.cnf', true),807 array(array('C:', 'Windows', 'my.cnf'), 'C:\\Windows/my.cnf', true),808 );809 }810 /**811 * @dataProvider pathDataProvider812 * @param array $expected813 * @param string $path814 */815 public function testGetPathAsArray(array $expected, $path)816 {817 $this->assertEquals($expected, Magento_Filesystem::getPathAsArray($path));818 }819 /**820 * @dataProvider isAbsolutePathDataProvider821 * @param bool $isReal822 * @param string $path823 */824 public function testIsAbsolutePath($isReal, $path)825 {826 $this->assertEquals($isReal, Magento_Filesystem::isAbsolutePath($path));827 }828 /**829 * @return array830 */831 public function isAbsolutePathDataProvider()832 {833 return array(834 array(true, '/tmp/file.txt'),835 array(false, '/tmp/../etc/mysql/my.cnf'),836 array(false, '/tmp/../tmp/file.txt'),837 array(false, 'C:\Temp\..\tmpfile.txt'),838 array(true, 'C:\Temp\tmpfile.txt'),839 array(true, '/tmp/'),840 array(true, '/tmp'),841 );842 }843 /**844 * @expectedException InvalidArgumentException845 * @expectedExceptionMessage Path must contain at least one node846 */847 public function testGetPathFromArrayException()848 {849 Magento_Filesystem::getPathFromArray(array());850 }851 /**852 * @return PHPUnit_Framework_MockObject_MockObject853 */854 protected function _getDefaultAdapterMock()855 {856 $adapterMock = $this->getMockBuilder('Magento_Filesystem_AdapterInterface')857 ->getMock();858 $adapterMock->expects($this->once())859 ->method('isDirectory')860 ->with('/tmp')861 ->will($this->returnValue(true));862 $adapterMock->expects($this->any())863 ->method('exists')864 ->will($this->returnValue(true));865 return $adapterMock;866 }867 /**868 * @dataProvider isPathInDirectoryDataProvider869 * @param string $path870 * @param string $directory871 * @param boolean $expectedValue872 */873 public function testIsPathInDirectory($path, $directory, $expectedValue)874 {875 $this->assertEquals($expectedValue, Magento_Filesystem::isPathInDirectory($path, $directory));876 }877 /**878 * @return array879 */880 public function isPathInDirectoryDataProvider()881 {882 return array(883 array('/tmp/file', '/tmp', true),884 array('/tmp/file', '/tmp/dir', false),885 array('/tmp', '/tmp/', true),886 array('/tmp/', '/tmp', true),887 );888 }889 /**890 * @dataProvider testSearchFilesDataProvider891 * @param string $workingDirectory892 * @param string $baseDirectory893 * @param string $pattern894 * @param string $expectedValue895 */896 public function testSearchFiles($workingDirectory, $baseDirectory, $pattern, $expectedValue)897 {898 $adapterMock = $this->getMock('Magento_Filesystem_AdapterInterface');899 $adapterMock->expects($this->once())900 ->method('isDirectory')901 ->with($workingDirectory)902 ->will($this->returnValue(true));903 $searchResult = array('result');904 $adapterMock->expects($this->once())905 ->method('searchKeys')906 ->with($expectedValue)907 ->will($this->returnValue($searchResult));908 $filesystem = new Magento_Filesystem($adapterMock);909 $filesystem->setWorkingDirectory($workingDirectory);910 $this->assertEquals($searchResult, $filesystem->searchKeys($baseDirectory, $pattern));911 }912 public function testSearchFilesDataProvider()913 {914 return array(915 array('/tmp', '/tmp/some/folder', '*', '/tmp/some/folder/*'),916 array('/tmp', '/tmp/some/folder/', '/*', '/tmp/some/folder/*'),917 array('/tmp', '/tmp/some/folder/', '/../../*', '/tmp/some/folder/../../*'),918 );919 }920 /**921 * @dataProvider searchFilesIsolationDataProvider922 * @param string $workingDirectory923 * @param string $baseDirectory924 * @param string $pattern925 * @param string $expectedMessage926 */927 public function testSearchFilesIsolation($workingDirectory, $baseDirectory, $pattern, $expectedMessage)928 {929 $adapterMock = $this->getMock('Magento_Filesystem_AdapterInterface');930 $adapterMock->expects($this->once())931 ->method('isDirectory')932 ->with($workingDirectory)933 ->will($this->returnValue(true));934 $filesystem = new Magento_Filesystem($adapterMock);935 $filesystem->setWorkingDirectory($workingDirectory);936 $this->setExpectedException('InvalidArgumentException', $expectedMessage);937 $filesystem->searchKeys($baseDirectory, $pattern);938 }939 public function searchFilesIsolationDataProvider()940 {941 return array(942 array(943 '/tmp',944 '/tmp/some/folder',945 '/../../../*',946 "Path '/tmp/some/folder/../../../*' is out of working directory '/tmp'"947 ),948 array(949 '/tmp/log',...

Full Screen

Full Screen

pre-commit

Source:pre-commit Github

copy

Full Screen

...113 'text',114 'private/git_hooks/phpmd.xml',115 ]116 );117 $processBuilder->setWorkingDirectory(__DIR__ . '/../../');118 $process = $processBuilder->getProcess();119 $process->run();120 if (!$process->isSuccessful()) {121 $this->output->writeln($file);122 $this->output->writeln(sprintf('<error>%s</error>', trim($process->getErrorOutput())));123 $this->output->writeln(sprintf('<info>%s</info>', trim($process->getOutput())));124 if ($succeed) {125 $succeed = FALSE;126 }127 }128 }129 return $succeed;130 }131 private function unitTests() {132 $processBuilder = new ProcessBuilder([133 'php',134 'vendor/bin/phpunit',135 '-c',136 'phpunit.xml',137 '--testsuite',138 'unit',139 ]);140 $processBuilder->setWorkingDirectory(__DIR__ . '/../../');141 $processBuilder->setTimeout(3600);142 $phpunit = $processBuilder->getProcess();143 $phpunit->run(144 function ($type, $buffer) {145 $this->output->write($buffer);146 }147 );148 return $phpunit->isSuccessful();149 }150 private function compileTestAssets() {151 $processBuilder = new ProcessBuilder(['yarn', 'run', 'dev']);152 $processBuilder->setTimeout(5200);153 $compileAssets = $processBuilder->getProcess();154 $compileAssets->run();155 return $compileAssets->isSuccessful();156 }157 private function integrationTests() {158 $processBuilder = new ProcessBuilder([159 'php',160 'vendor/bin/phpunit',161 '-c',162 'phpunit_integration.xml',163 ]);164 $processBuilder->setWorkingDirectory(__DIR__ . '/../../');165 $processBuilder->setTimeout(5200);166 $phpunit = $processBuilder->getProcess();167 $phpunit->run(168 function ($type, $buffer) {169 $this->output->write($buffer);170 }171 );172 return $phpunit->isSuccessful();173 }174 private function functionalTests() {175 $processBuilder = new ProcessBuilder([176 'php',177 'vendor/bin/behat',178 '-c',179 'behat.yml',180 '--format',181 'progress',182 ]);183 $processBuilder->setWorkingDirectory(__DIR__ . '/../../');184 $processBuilder->setTimeout(5200);185 $behat = $processBuilder->getProcess();186 $behat->run(187 function ($type, $buffer) {188 $this->output->write($buffer);189 }190 );191 return $behat->isSuccessful();192 }193 private function jestTests() {194 $processBuilder = new ProcessBuilder(['yarn', 'test']);195 $processBuilder->setWorkingDirectory(__DIR__ . '/../../');196 $processBuilder->setTimeout(5200);197 $jest = $processBuilder->getProcess();198 $jest->run(199 function ($type, $buffer) {200 $this->output->write($buffer);201 }202 );203 return $jest->isSuccessful();204 }205 private function codeStyle(array $files) {206 $succeed = TRUE;207 foreach ($files as $file) {208 $srcFile = preg_match(self::PHP_FILES_IN_SRC, $file);209 if (!$srcFile) {210 continue;211 }212 $processBuilder = new ProcessBuilder(213 [214 'php',215 'vendor/bin/php-cs-fixer',216 'fix',217 '--dry-run',218 '--verbose',219 $file,220 ]221 );222 $processBuilder->setWorkingDirectory(__DIR__ . '/../../');223 $phpCsFixer = $processBuilder->getProcess();224 $phpCsFixer->run();225 if (!$phpCsFixer->isSuccessful()) {226 $this->output->writeln(sprintf('<error>%s</error>', trim($phpCsFixer->getOutput())));227 if ($succeed) {228 $succeed = FALSE;229 }230 }231 }232 return $succeed;233 }234 private function codeStylePsr(array $files) {235 $succeed = TRUE;236 $needle = self::PHP_FILES_IN_SRC;237 foreach ($files as $file) {238 if ($this->checkFileIsExclude($file)) {239 continue;240 }241 if (!preg_match($needle, $file)) {242 continue;243 }244 $processBuilder = new ProcessBuilder([245 'php',246 'vendor/bin/phpcs',247 $file,248 '--ignore=/var/SymfonyRequirements.php,/vendor/*',249 '--standard=Drupal',250 '--encoding=utf-8 -n -p',251 ]);252 $processBuilder->setWorkingDirectory(__DIR__ . '/../../');253 $phpCsFixer = $processBuilder->getProcess();254 $phpCsFixer->run();255 if (!$phpCsFixer->isSuccessful()) {256 $this->output->writeln(sprintf('<error>%s</error>', trim($phpCsFixer->getOutput())));257 if ($succeed) {258 $succeed = FALSE;259 }260 }261 }262 return $succeed;263 }264 private function codeStyleCbf(array $files) {265 $succeed = TRUE;266 $needle = self::PHP_FILES_IN_SRC;267 foreach ($files as $file) {268 if ($this->checkFileIsExclude($file)) {269 continue;270 }271 if (!preg_match($needle, $file)) {272 continue;273 }274 $processBuilder = new ProcessBuilder([275 'php',276 'vendor/bin/phpcbf',277 $file,278 '--ignore=/var/SymfonyRequirements.php,/vendor/*',279 '--standard=Drupal',280 '--encoding=utf-8 -n -p',281 ]);282 $processBuilder->setWorkingDirectory(__DIR__ . '/../../');283 $phpCsFixer = $processBuilder->getProcess();284 $phpCsFixer->run();285 if (!$phpCsFixer->isSuccessful()) {286 $this->output->writeln(sprintf('<error>%s</error>', trim($phpCsFixer->getOutput())));287 if ($succeed) {288 $succeed = FALSE;289 }290 }291 }292 return $succeed;293 }294 private function esLint($files) {295 $succeed = TRUE;296 $needle = '/\.js$/';297 foreach ($files as $file) {298 if (!preg_match($needle, $file)) {299 continue;300 }301 if ($this->checkJsFileLocation($file)) {302 continue;303 }304 $processBuilder = new ProcessBuilder(305 array_merge([306 './node_modules/.bin/prettier',307 '-c',308 './web/core/.prettierrc.json',309 '--write',310 ], [$file])311 );312 $processBuilder->setWorkingDirectory(__DIR__ . '/../../');313 $eSLint = $processBuilder->getProcess();314 $eSLint->run();315 $processBuilder = new ProcessBuilder(316 array_merge([317 './node_modules/.bin/eslint',318 '-c',319 './web/core/.eslintrc.json',320 ], [$file])321 );322 $processBuilder->setWorkingDirectory(__DIR__ . '/../../');323 $eSLint = $processBuilder->getProcess();324 $eSLint->run();325 if (!$eSLint->isSuccessful()) {326 $this->output->write($eSLint->getOutput());327 if ($succeed) {328 $succeed = FALSE;329 }330 }331 }332 return $succeed;333 }334 private function styleLint($files) {335 $needle = '/app\/Resources\/(.*)(\.scss)$/';336 $styleLintFiles = array_filter(337 $files,338 function ($file) use ($needle) {339 return preg_match($needle, $file);340 }341 );342 $processBuilder = new ProcessBuilder(343 array_merge(344 [345 './node_modules/.bin/stylelint',346 '-c',347 '.stylelintrc.json',348 '--syntax',349 'scss',350 ],351 $styleLintFiles352 )353 );354 $processBuilder->setWorkingDirectory(__DIR__ . '/../../');355 $styleLint = $processBuilder->getProcess();356 $styleLint->run();357 if (!$styleLint->isSuccessful()) {358 $this->output->write($styleLint->getOutput());359 }360 return $styleLint->isSuccessful();361 }362 private function checkFileIsExclude($file) {363 if (preg_match('/vendor/', $file)) {364 return TRUE;365 }366 elseif (preg_match('/contrib/', $file)) {367 return TRUE;368 }...

Full Screen

Full Screen

Builder.php

Source:Builder.php Github

copy

Full Screen

...87 public function clean($source, $callback = null)88 {89 if (true === file_exists($this->directory . DIRECTORY_SEPARATOR . 'Makefile')) {90 $process = $this->builder->create(array('make', 'clean'))91 ->setWorkingDirectory($source)92 ->getProcess()93 ;94 $process->run($callback);95 if (false === $process->isSuccessful()) {96 throw new ProcessFailedException($process);97 }98 }99 return $this;100 }101 /**102 * @param \jubianchi\PhpSwitch\PHP\Version $version103 * @param string $source104 * @param \jubianchi\PhpSwitch\PHP\Option\OptionCollection $options105 * @param callable $callback106 *107 * @throws \Symfony\Component\Process\Exception\ProcessFailedException108 *109 * @return \jubianchi\PhpSwitch\PHP\Builder110 */111 public function configure(Version $version, $source, OptionCollection $options, $callback = null)112 {113 $prefix = $this->getDestination($version);114 if (null !== $callback) {115 $callback('init', $prefix);116 }117 $builder = $this->builder118 ->create(119 array(120 './configure',121 '--prefix=' . $prefix,122 '--with-config-file-path=' . $prefix . '/etc',123 '--with-config-file-scan-dir=' . $prefix . '/var/db',124 '--with-pear=' . $prefix . '/lib/php'125 )126 )127 ->setTimeout(null)128 ->setWorkingDirectory($source)129 ;130 foreach ($options as $option) {131 $builder->add((string) $option);132 }133 $process = $builder->getProcess();134 $process->run($callback);135 if (false === $process->isSuccessful()) {136 throw new ProcessFailedException($process);137 }138 return $this;139 }140 /**141 * @param \jubianchi\PhpSwitch\PHP\Version $version142 * @param string $source143 * @param \jubianchi\PhpSwitch\PHP\Option\OptionCollection $options144 * @param int $jobs145 * @param callable $callback146 *147 * @throws \Symfony\Component\Process\Exception\ProcessFailedException148 *149 * @return \jubianchi\PhpSwitch\PHP\Builder150 */151 public function make(Version $version, $source, OptionCollection $options, $jobs = null, $callback = null)152 {153 $builder = $this->builder154 ->create(array('make'))155 ->setTimeout(null)156 ->setWorkingDirectory($source)157 ;158 if (null !== $jobs) {159 $builder->add('-j' . (int) $jobs);160 }161 $process = $builder->getProcess();162 $process->run($callback);163 if (false === $process->isSuccessful()) {164 throw new ProcessFailedException($process);165 }166 $root = $options->contains(ApacheOption::ARG)167 || $options->contains(ApxsOption::ARG)168 || $options->contains(Apxs2Option::ARG);169 $process = $this->builder170 ->create(array('make', 'install'))171 ->setRoot($root)172 ->setTimeout(null)173 ->setWorkingDirectory($source)174 ->getProcess();175 $process->run($callback);176 if(true === $root) {177 $this->builder178 ->create(array('chown', '-R', posix_geteuid() . ':' . posix_getgid(), $this->getDestination($version)))179 ->setRoot()180 ->setTimeout(null)181 ->setWorkingDirectory($source)182 ->getProcess()183 ->run($callback);184 }185 if (false === $process->isSuccessful()) {186 throw new ProcessFailedException($process);187 }188 return $this;189 }190 /**191 * @param \jubianchi\PhpSwitch\PHP\Version $version192 *193 * @return string194 */195 public function getDestination(Version $version)...

Full Screen

Full Screen

setWorkingDirectory

Using AI Code Generation

copy

Full Screen

1$builder = new ProcessBuilder();2$builder->setWorkingDirectory('/home/user');3$process = $builder->getProcess();4$process->run();5$process = new Process('ls -la');6$process->setWorkingDirectory('/home/user');7$process->run();

Full Screen

Full Screen

setWorkingDirectory

Using AI Code Generation

copy

Full Screen

1$builder = new ProcessBuilder(array('php', '2.php'));2$builder->setWorkingDirectory('/home/someuser');3$process = $builder->getProcess();4$process->run();5$process = new Process('php 3.php');6$process->setWorkingDirectory('/home/someuser');7$process->run();8$process = new Process('php 4.php');9$process->setWorkingDirectory('/home/someuser');10$process->run();11$process = new Process('php 5.php');12$process->setWorkingDirectory('/home/someuser');13$process->run();14$process = new Process('php 6.php');15$process->setWorkingDirectory('/home/someuser');16$process->run();17$process = new Process('php 7.php');18$process->setWorkingDirectory('/home/someuser');19$process->run();20$process = new Process('php 8.php');21$process->setWorkingDirectory('/home/someuser');22$process->run();23$process = new Process('php 9.php');24$process->setWorkingDirectory('/home/someuser');25$process->run();26$process = new Process('php 10.php');27$process->setWorkingDirectory('/home/someuser');28$process->run();29$process = new Process('php 11.php');30$process->setWorkingDirectory('/home/someuser');31$process->run();32$process = new Process('php 12.php');

Full Screen

Full Screen

setWorkingDirectory

Using AI Code Generation

copy

Full Screen

1$builder = new Builder();2$builder->setWorkingDirectory("/tmp");3$builder->add("ls");4$builder->run();5$run = new Run();6$run->setWorkingDirectory("/tmp");7$run->add("ls");8$run->run();9$command = new Command("ls");10$command->setWorkingDirectory("/tmp");11$run = new Run();12$run->add($command);13$run->run();14$command = new Command("ls");15$command->setWorkingDirectory("/tmp");16$builder = new Builder();17$builder->add($command);18$builder->run();19$run = new Run();20$run->setWorkingDirectory("/tmp");21$run->add("ls");22$run->run();23$builder = new Builder();24$builder->setWorkingDirectory("/tmp");25$builder->add("ls");26$builder->run();27$command = new Command("ls");28$command->setWorkingDirectory("/tmp");29$run = new Run();30$run->add($command);31$run->run();32$command = new Command("ls");33$command->setWorkingDirectory("/tmp");34$builder = new Builder();35$builder->add($command);36$builder->run();37$run = new Run();38$run->setWorkingDirectory("/tmp");39$run->add("ls");40$run->run();41$builder = new Builder();42$builder->setWorkingDirectory("/tmp");43$builder->add("ls");44$builder->run();45$command = new Command("

Full Screen

Full Screen

setWorkingDirectory

Using AI Code Generation

copy

Full Screen

1$path = getcwd();2echo $path;3$builder = new ProcessBuilder();4$path = $builder->getWorkingDirectory();5echo $path;6$builder = new ProcessBuilder();7$builder->setPrefix('php');8$process = $builder->getProcess();9$process->run();10echo $process->getOutput();11$builder = new ProcessBuilder();12$builder->setPrefix('php');13$prefix = $builder->getPrefix();14echo $prefix;15$builder = new ProcessBuilder();16$builder->setArguments(array('php', '1.php'));17$process = $builder->getProcess();18$process->run();19echo $process->getOutput();20$builder = new ProcessBuilder();21$builder->setArguments(array('php', '1.php'));22$arguments = $builder->getArguments();23print_r($arguments);24$builder = new ProcessBuilder();25$builder->setEnv('PHP', 'php');26$process = $builder->getProcess();27$process->run();28echo $process->getOutput();29$builder = new ProcessBuilder();30$builder->setEnv('PHP', 'php');31$env = $builder->getEnv();32print_r($env);

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Atoum automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Trigger setWorkingDirectory code on LambdaTest Cloud Grid

Execute automation tests with setWorkingDirectory on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful