How to use isRoot method of path class

Best Atoum code snippet using path.isRoot

DependencyTreeParserTest.php

Source:DependencyTreeParserTest.php Github

copy

Full Screen

...107 $dependencyTree = $treeParser->parseFile( $filePath );108 $this->assertEquals( 'main', $dependencyTree->filename, "Main file should be named main" );109 $this->assertEquals( 'js', $dependencyTree->filetype, "Main file should be of js filetype" );110 $this->assertEquals( $basePath, $dependencyTree->path, "Main file should have base path" );111 $this->assertFalse( $dependencyTree->isRoot, 'Main file should not be marked isRoot' );112 $this->assertEmpty( $dependencyTree->scripts, "Main.js should have no dependent scripts" );113 $this->assertEmpty( $dependencyTree->stylesheets, "Main.js should have no dependent stylesheets" );114 $this->assertEmpty( $dependencyTree->packages, "Main.js should have no dependent packages" );115 $this->assertEmpty(116 $dependencyTree->annotationOrderMap,117 "Main.js should have no annotations in its ordering map"118 );119 }120 /**121 * @depends testParseFileReturnsGivenFile122 */123 public function testParseFileReturnsGivenRootFile()124 {125 $basePath = self::fixturesBasePath . '0_deps_root';126 $filePath = $basePath . '/main.js';127 $treeParser = new DependencyTreeParser();128 $dependencyTree = $treeParser->parseFile( $filePath );129 $this->assertEquals( 'main', $dependencyTree->filename );130 $this->assertEquals( 'js', $dependencyTree->filetype );131 $this->assertEquals( $basePath, $dependencyTree->path );132 $this->assertTrue( $dependencyTree->isRoot, 'Main.js should be marked isRoot' );133 $this->assertEmpty( $dependencyTree->scripts );134 $this->assertEmpty( $dependencyTree->stylesheets );135 $this->assertEmpty( $dependencyTree->packages );136 $this->assertEmpty(137 $dependencyTree->annotationOrderMap,138 "Main.js should have no annotations in its ordering map"139 );140 }141 /**142 * @depends testParseFileReturnsGivenFile143 */144 public function testParseFileLoadsDependentFile()145 {146 $basePath = self::fixturesBasePath . '1_dep';147 $filePath = $basePath . '/main.js';148 $treeParser = new DependencyTreeParser();149 $dependencyTree = $treeParser->parseFile( $filePath );150 $this->assertEquals( 'main', $dependencyTree->filename );151 $this->assertEquals( 'js', $dependencyTree->filetype );152 $this->assertEquals( $basePath, $dependencyTree->path );153 $this->assertFalse( $dependencyTree->isRoot, 'File should not be marked isRoot' );154 $this->assertNotEmpty( $dependencyTree->scripts );155 $this->assertEmpty( $dependencyTree->stylesheets );156 $this->assertEmpty( $dependencyTree->packages );157 $this->assertCount(1, $dependencyTree->scripts, 'Should have a dependent script' );158 $this->assertInstanceOf( 'JsPackager\File', $dependencyTree->scripts[0] );159 $this->assertEquals( 'dep_1', $dependencyTree->scripts[0]->filename );160 $this->assertFalse( $dependencyTree->scripts[0]->isRoot, 'File should not be marked isRoot' );161 $this->assertEquals(162 'require',163 $dependencyTree->annotationOrderMap[0]['action'],164 "Should reflect appropriate bucket"165 );166 $this->assertEquals(167 0,168 $dependencyTree->annotationOrderMap[0]['annotationIndex'],169 "Should reflect appropriate order"170 );171 }172 /**173 * @depends testParseFileReturnsGivenRootFile174 */175 public function testParseFileLoadsDependentRootFile()176 {177 $basePath = self::fixturesBasePath . '1_dep_root';178 $filePath = $basePath . '/main.js';179 $treeParser = new DependencyTreeParser();180 $dependencyTree = $treeParser->parseFile( $filePath );181 $this->assertEquals( 'main', $dependencyTree->filename );182 $this->assertEquals( 'js', $dependencyTree->filetype );183 $this->assertEquals( $basePath, $dependencyTree->path );184 $this->assertFalse( $dependencyTree->isRoot, 'File should not be marked isRoot' );185 $this->assertNotEmpty( $dependencyTree->scripts );186 $this->assertEmpty( $dependencyTree->stylesheets );187 $this->assertNotEmpty( $dependencyTree->packages );188 $this->assertCount(1, $dependencyTree->scripts, 'Should have a dependent script' );189 $this->assertCount(1, $dependencyTree->packages, 'Should have a dependent script package entry' );190 $this->assertInstanceOf( 'JsPackager\File', $dependencyTree->scripts[0] );191 $this->assertEquals( 'dep_1', $dependencyTree->scripts[0]->filename );192 $this->assertTrue( $dependencyTree->scripts[0]->isRoot, 'Dependent script should be marked isRoot');193 $this->assertEquals( $basePath . '/somePackage/dep_1.js', $dependencyTree->packages[0] );194 $this->assertEquals(195 'require',196 $dependencyTree->annotationOrderMap[0]['action'],197 "Should reflect appropriate bucket"198 );199 $this->assertEquals(200 0,201 $dependencyTree->annotationOrderMap[0]['annotationIndex'],202 "Should reflect appropriate order"203 );204 }205 /**206 * Leaving this test for clarity, stylesheets used to be File objects instead of behaving207 * like packages with full paths.208 *209 * Now this test verifies it by just seeing that the dependency tree in total does not have any210 * of the things that the stylesheet is annotated with.211 */212 public function testParseFileIgnoresAnnotationsInStylesheets()213 {214 $basePath = self::fixturesBasePath . 'css_with_annotations';215 $filePath = $basePath . '/main.js';216 $treeParser = new DependencyTreeParser();217 $dependencyTree = $treeParser->parseFile( $filePath );218 $this->assertEquals( 'main', $dependencyTree->filename, "main should be base file's name" );219 $this->assertEquals( 'js', $dependencyTree->filetype, "main.js should be a javascript file" );220 $this->assertEquals( $basePath, $dependencyTree->path, "main.js should be in the css_with_annotations fixture" );221 $this->assertFalse( $dependencyTree->isRoot, 'main.js should not be marked isRoot' );222 $this->assertEmpty( $dependencyTree->scripts, "main.js should have no script dependencies" );223 $this->assertNotEmpty( $dependencyTree->stylesheets, "main.js should have 1 dependent stylesheet" );224 $this->assertEmpty( $dependencyTree->packages, "main.js should have no packaged dependencies" );225 $this->assertCount(1, $dependencyTree->stylesheets, 'Should have one dependent stylesheet' );226 $this->assertEquals( $basePath . '/' . 'main.css', $dependencyTree->stylesheets[0] );227 }228 public function testParseFileThrowsMissingFileExceptionOnBrokenReferencesIfNotMuted()229 {230 // Test JavaScript files231 $basePath = self::fixturesBasePath . '1_broken_js_reference';232 $filePath = $basePath . '/main.js';233 $treeParser = new DependencyTreeParser();234 try {235 $dependencyTree = $treeParser->parseFile( $filePath );236 $this->fail('Set should throw a missing file exception');237 } catch (ParsingException $e) {238 $this->assertEquals(239 'tests/JsPackager/fixtures/1_broken_js_reference/heeper.js',240 $e->getErrors(),241 'Exception should contain failed file\'s path information'242 );243 $this->assertEquals(244 ParsingException::ERROR_CODE,245 $e->getCode(),246 'Exception should contain proper error code'247 );248 }249 // Test Stylesheet files250 $basePath = self::fixturesBasePath . '1_broken_css_reference';251 $filePath = $basePath . '/main.js';252 $treeParser = new DependencyTreeParser();253 try {254 $dependencyTree = $treeParser->parseFile( $filePath );255 $this->fail('Set should throw a missing file exception');256 } catch (MissingFileException $e) {257 $this->assertEquals(258 'tests/JsPackager/fixtures/1_broken_css_reference/heeper.css',259 $e->getMissingFilePath(),260 'Exception should contain failed file\'s path information'261 );262 $this->assertEquals(263 MissingFileException::ERROR_CODE,264 $e->getCode(),265 'Exception should contain proper error code'266 );267 }268 }269 public function testParseFileDoesNotThrowMissingFileExceptionOnBrokenReferencesIfMuted()270 {271 // Test JavaScript files272 $basePath = self::fixturesBasePath . '1_broken_js_reference';273 $filePath = $basePath . '/main.js';274 $treeParser = new DependencyTreeParser();275 $treeParser->muteMissingFileExceptions();276 $dependencyTree = $treeParser->parseFile( $filePath );277 $this->assertEquals(278 $dependencyTree->filename,279 "main",280 "Dependency Tree should have completed with main as the filename"281 );282 // Test Stylesheet files283 $basePath = self::fixturesBasePath . '1_broken_css_reference';284 $filePath = $basePath . '/main.js';285 $treeParser = new DependencyTreeParser();286 $treeParser->muteMissingFileExceptions();287 $dependencyTree = $treeParser->parseFile( $filePath );288 $this->assertEquals(289 $dependencyTree->filename,290 "main",291 "Dependency Tree should have completed with main as the filename"292 );293 }294 public function testParseFileThrowsParsingExceptionOnMissingFileDuringRecursionIntoFile()295 {296 // Test JavaScript files297 $basePath = self::fixturesBasePath . '1_broken_js_reference_recursive';298 $filePath = $basePath . '/main.js';299 $treeParser = new DependencyTreeParser();300 try {301 $dependencyTree = $treeParser->parseFile( $filePath );302 $this->fail('Set should throw a missing file exception');303 } catch (ParsingException $e) {304 $this->assertEquals(305 'Failed to include missing file ' .306 '"tests/JsPackager/fixtures/1_broken_js_reference_recursive/heeper.js"'.307 ' while trying to parse ' .308 '"tests/JsPackager/fixtures/1_broken_js_reference_recursive/helper.js"',309 $e->getMessage(),310 'Exception should contain failed file\'s path information'311 );312 $this->assertEquals(313 'tests/JsPackager/fixtures/1_broken_js_reference_recursive/heeper.js',314 $e->getErrors(),315 'Exception should contain failed file\'s path information'316 );317 $this->assertEquals(318 ParsingException::ERROR_CODE,319 $e->getCode(),320 'Exception should contain proper error code'321 );322 }323 }324 public function testParseFileThrowsParsingExceptionOnMissingFileDuringRecursionIntoRemoteFile()325 {326 // Test JavaScript files327 $basePath = self::fixturesBasePath . '1_broken_js_reference_remote';328 $filePath = $basePath . '/main.js';329 $treeParser = new DependencyTreeParser();330 $treeParser->remoteFolderPath = self::fixturesBasePath . '1_broken_js_reference_remote-remote';331 try {332 $dependencyTree = $treeParser->parseFile( $filePath );333 $this->fail('Set should throw a missing file exception');334 } catch (ParsingException $e) {335 $this->assertEquals(336 'Failed to include missing file ' .337 '"tests/JsPackager/fixtures/1_broken_js_reference_remote-remote/heeper.js"'.338 ' while trying to parse ' .339 '"tests/JsPackager/fixtures/1_broken_js_reference_remote-remote/main.js"',340 $e->getMessage(),341 'Exception should contain failed file\'s path information'342 );343 $this->assertEquals(344 'tests/JsPackager/fixtures/1_broken_js_reference_remote-remote/heeper.js',345 $e->getErrors(),346 'Exception should contain failed file\'s path information'347 );348 $this->assertEquals(349 ParsingException::ERROR_CODE,350 $e->getCode(),351 'Exception should contain proper error code'352 );353 }354 }355 public function testParseFileMarksIsRemote()356 {357 // Test JavaScript files358 $basePath = self::fixturesBasePath . 'remote_annotation';359 $filePath = $basePath . '/main.js';360 $treeParser = new DependencyTreeParser();361 $treeParser->remoteFolderPath = self::fixturesBasePath . 'remote_annotation-remote';362 $dependencyTree = $treeParser->parseFile( $filePath );363 $this->assertFalse(364 $dependencyTree->isRemote,365 'Main file should not be marked remote'366 );367 $this->assertFalse(368 $dependencyTree->scripts[0]->isRemote,369 'Local file before remotes in main file should not be marked remote'370 );371 $this->assertFalse(372 $dependencyTree->scripts[1]->isRemote,373 'Local file in subfolder before remotes in main file should not be marked remote'374 );375 $this->assertTrue(376 $dependencyTree->scripts[2]->isRemote,377 'Remote script file should be marked remote'378 );379 $this->assertTrue(380 $dependencyTree->scripts[2]->scripts[0]->isRemote,381 'Remote script\'s locally required file should be marked remote'382 );383 $this->assertTrue(384 $dependencyTree->scripts[2]->scripts[1]->isRemote,385 'Remote script\'s remotely required file should be marked remote'386 );387 $this->assertTrue(388 $dependencyTree->scripts[3]->isRemote,389 'Remote package file should be marked remote'390 );391 $this->assertTrue(392 $dependencyTree->scripts[3]->isRemote,393 'Remote package file should be marked remote'394 );395 $this->assertTrue(396 $dependencyTree->scripts[3]->scripts[0]->isRemote,397 'Remote script\'s locally required file should be marked remote'398 );399 $this->assertTrue(400 $dependencyTree->scripts[3]->scripts[1]->isRemote,401 'Remote script\'s remotely required file should be marked remote'402 );403 $this->assertFalse(404 $dependencyTree->scripts[4]->isRemote,405 'Local file in subfolder after remotes in main file should not be marked remote'406 );407 $this->assertFalse(408 $dependencyTree->scripts[5]->isRemote,409 'Local file after remotes in main file should not be marked remote'410 );411 }412 /******************************************************************413 * parseFile > 2 Dependencies, #1 and #2414 * Fixture folder: 2_indep_deps415 *****************************************************************/416 public function testParseFile_2IndepDeps()417 {418 $basePath = self::fixturesBasePath . '2_indep_deps';419 $filePath = $basePath . '/main.js';420 $treeParser = new DependencyTreeParser();421 $dependencyTree = $treeParser->parseFile( $filePath );422 $this->assertEquals( 'main', $dependencyTree->filename );423 $this->assertEquals( 'js', $dependencyTree->filetype );424 $this->assertEquals( $basePath, $dependencyTree->path );425 $this->assertFalse( $dependencyTree->isRoot, 'File should not be marked isRoot' );426 $this->assertNotEmpty( $dependencyTree->scripts );427 $this->assertEmpty( $dependencyTree->stylesheets );428 $this->assertEmpty( $dependencyTree->packages );429 $this->assertCount(2, $dependencyTree->scripts, 'Should have two dependent scripts' );430 $this->assertInstanceOf( 'JsPackager\File', $dependencyTree->scripts[0] );431 $this->assertInstanceOf( 'JsPackager\File', $dependencyTree->scripts[1] );432 $this->assertEquals( 'comp_a', $dependencyTree->scripts[0]->filename );433 $this->assertEquals( 'comp_b', $dependencyTree->scripts[1]->filename );434 $this->assertFalse( $dependencyTree->scripts[0]->isRoot, 'File should not be marked isRoot' );435 $this->assertFalse( $dependencyTree->scripts[1]->isRoot, 'File should not be marked isRoot' );436 }437 /******************************************************************438 * parseFile > 2 Dependencies, #1 and #2, #2 is root439 * Fixture folder: 2_indep_deps_1_root440 *****************************************************************/441 public function testParseFile_2IndepDeps1Root()442 {443 $basePath = self::fixturesBasePath . '2_indep_deps_1_root';444 $filePath = $basePath . '/main.js';445 $treeParser = new DependencyTreeParser();446 $dependencyTree = $treeParser->parseFile( $filePath );447 $this->assertEquals( 'main', $dependencyTree->filename );448 $this->assertEquals( 'js', $dependencyTree->filetype );449 $this->assertEquals( $basePath, $dependencyTree->path );450 $this->assertFalse( $dependencyTree->isRoot, 'File should not be marked isRoot' );451 $this->assertNotEmpty( $dependencyTree->scripts );452 $this->assertEmpty( $dependencyTree->stylesheets );453 $this->assertNotEmpty( $dependencyTree->packages );454 $this->assertCount(2, $dependencyTree->scripts, 'Should have two dependent scripts' );455 $this->assertInstanceOf( 'JsPackager\File', $dependencyTree->scripts[0] );456 $this->assertInstanceOf( 'JsPackager\File', $dependencyTree->scripts[1] );457 $this->assertEquals( 'comp_a', $dependencyTree->scripts[0]->filename );458 $this->assertEquals( 'comp_b', $dependencyTree->scripts[1]->filename );459 $this->assertFalse( $dependencyTree->scripts[0]->isRoot, 'File should not be marked isRoot' );460 $this->assertTrue( $dependencyTree->scripts[1]->isRoot, 'File should be marked isRoot' );461 $this->assertEquals( $basePath . '/ComponentB/comp_b.js', $dependencyTree->packages[0], "Should have comp_b package" );462 }463 /******************************************************************464 * parseFile > 2 Dependencies, #1 and #2465 * #1 with its own dependency (#3)466 * #2 with its own dependency (#4)467 * Fixture folder: 2_indep_deps_individ_deps468 *****************************************************************/469 public function testParseFile_2IndepDepsIndividDeps()470 {471 $basePath = self::fixturesBasePath . '2_indep_deps_individ_deps';472 $filePath = $basePath . '/main.js';473 $treeParser = new DependencyTreeParser();474 $dependencyTree = $treeParser->parseFile( $filePath );475 $this->assertEquals( 'main', $dependencyTree->filename );476 $this->assertEquals( 'js', $dependencyTree->filetype );477 $this->assertEquals( $basePath, $dependencyTree->path );478 $this->assertFalse( $dependencyTree->isRoot, 'File should not be marked isRoot' );479 $this->assertNotEmpty( $dependencyTree->scripts );480 $this->assertEmpty( $dependencyTree->stylesheets );481 $this->assertEmpty( $dependencyTree->packages );482 $this->assertCount(2, $dependencyTree->scripts, 'Should have two dependent scripts' );483 $this->assertInstanceOf( 'JsPackager\File', $dependencyTree->scripts[0] );484 $this->assertInstanceOf( 'JsPackager\File', $dependencyTree->scripts[1] );485 $this->assertEquals( 'dep_1', $dependencyTree->scripts[0]->filename );486 $this->assertEquals( 'dep_2', $dependencyTree->scripts[1]->filename );487 $this->assertFalse( $dependencyTree->scripts[0]->isRoot, 'File should not be marked isRoot' );488 $this->assertFalse( $dependencyTree->scripts[1]->isRoot, 'File should not be marked isRoot' );489 $dep1 = $dependencyTree->scripts[0];490 $dep2 = $dependencyTree->scripts[1];491 $this->assertCount(1, $dep1->scripts, 'Should have one dependent script');492 $this->assertEquals( 'dep_3', $dep1->scripts[0]->filename );493 $this->assertFalse( $dep1->scripts[0]->isRoot, 'File should not be marked isRoot' );494 $this->assertEmpty( $dep1->scripts[0]->packages );495 $this->assertCount(1, $dep2->scripts, 'Should have one dependent script');496 $this->assertEquals( 'dep_4', $dep2->scripts[0]->filename );497 $this->assertFalse( $dep2->scripts[0]->isRoot, 'File should not be marked isRoot' );498 $this->assertEmpty( $dep2->scripts[0]->packages );499 }500 /******************************************************************501 * parseFile > 2 Dependencies, #1 and #2502 * #1 with a dependency (#3)503 * #2 with same dependency (#3)504 * Fixture folder: 2_indep_deps_shared_deps505 *****************************************************************/506 public function testParseFile_2IndepDepsSharedDeps()507 {508 $basePath = self::fixturesBasePath . '2_indep_deps_shared_deps';509 $filePath = $basePath . '/main.js';510 $treeParser = new DependencyTreeParser();511 $dependencyTree = $treeParser->parseFile( $filePath );512 $this->assertEquals( 'main', $dependencyTree->filename );513 $this->assertEquals( 'js', $dependencyTree->filetype );514 $this->assertEquals( $basePath, $dependencyTree->path );515 $this->assertFalse( $dependencyTree->isRoot, 'File should not be marked isRoot' );516 $this->assertNotEmpty( $dependencyTree->scripts );517 $this->assertEmpty( $dependencyTree->stylesheets );518 $this->assertEmpty( $dependencyTree->packages );519 $this->assertCount(2, $dependencyTree->scripts, 'Should have two dependent scripts' );520 $this->assertInstanceOf( 'JsPackager\File', $dependencyTree->scripts[0] );521 $this->assertInstanceOf( 'JsPackager\File', $dependencyTree->scripts[1] );522 $this->assertEquals( 'dep_1', $dependencyTree->scripts[0]->filename );523 $this->assertEquals( 'dep_2', $dependencyTree->scripts[1]->filename );524 $this->assertFalse( $dependencyTree->scripts[0]->isRoot, 'File should not be marked isRoot' );525 $this->assertFalse( $dependencyTree->scripts[1]->isRoot, 'File should not be marked isRoot' );526 $dep1 = $dependencyTree->scripts[0];527 $dep2 = $dependencyTree->scripts[1];528 $this->assertCount(1, $dep1->scripts, 'Should have one dependent script');529 $this->assertEquals( 'dep_3', $dep1->scripts[0]->filename );530 $this->assertFalse( $dep1->scripts[0]->isRoot, 'File should not be marked isRoot' );531 $this->assertEmpty( $dep1->scripts[0]->packages );532 $this->assertCount(1, $dep2->scripts, 'Should have one dependent script');533 $this->assertEquals( 'dep_3', $dep2->scripts[0]->filename );534 $this->assertFalse( $dep2->scripts[0]->isRoot, 'File should not be marked isRoot' );535 $this->assertEmpty( $dep2->scripts[0]->packages );536 $this->assertEquals( $dep1->scripts[0]->filename, $dep2->scripts[0]->filename );537 }538 /******************************************************************539 * parseFile > 2 Dependencies, #1 and #2540 * #1 with a dependency (#3)541 * #2 with same dependency (#3)542 * #3 is a root package543 * Fixture folder: 2_indep_deps_shared_package544 *****************************************************************/545 public function testParseFile_2IndepDepsSharedPackage()546 {547 $basePath = self::fixturesBasePath . '2_indep_deps_shared_package';548 $filePath = $basePath . '/main.js';549 $treeParser = new DependencyTreeParser();550 $dependencyTree = $treeParser->parseFile( $filePath );551 // Ensure root file was scanned properly552 $this->assertEquals( 'main', $dependencyTree->filename );553 $this->assertEquals( 'js', $dependencyTree->filetype );554 $this->assertEquals( $basePath, $dependencyTree->path );555 // Ensure root file (main.js) has #1 and #2 scripts but no packages (should it have a package?)556 $this->assertFalse( $dependencyTree->isRoot, 'Main file should not be marked isRoot' );557 $this->assertNotEmpty( $dependencyTree->scripts );558 $this->assertEmpty( $dependencyTree->stylesheets );559 $this->assertEmpty( $dependencyTree->packages );560 // Ensure it has #1 and #2561 $this->assertCount(2, $dependencyTree->scripts, 'Main file should have two dependent scripts' );562 $this->assertInstanceOf( 'JsPackager\File', $dependencyTree->scripts[0] );563 $this->assertInstanceOf( 'JsPackager\File', $dependencyTree->scripts[1] );564 $this->assertEquals( 'dep_1', $dependencyTree->scripts[0]->filename );565 $this->assertEquals( 'dep_2', $dependencyTree->scripts[1]->filename );566 // Shortcut for easier access and readability567 $dep1 = $dependencyTree->scripts[0];568 $dep2 = $dependencyTree->scripts[1];569 // Ensure #1 and #2 are not root packages themselves570 $this->assertFalse( $dep1->isRoot, 'Dep #1 should not be marked isRoot' );571 $this->assertFalse( $dep2->isRoot, 'Dep #2 should not be marked isRoot' );572 // Ensure dep #1 has #3 as a package573 $this->assertCount(1, $dep1->scripts, 'Dep #1 should have one dependent script');574 $this->assertEquals( 'dep_3', $dep1->scripts[0]->filename );575 $this->assertTrue( $dep1->scripts[0]->isRoot, 'Dep #3 through Dep #1 should be marked isRoot' );576 $this->assertEmpty( $dep1->scripts[0]->packages );577 // Ensure dep #2 has #3 as a package578 $this->assertCount(1, $dep2->scripts, 'Dep #2 should have one dependent script');579 $this->assertEquals( 'dep_3', $dep2->scripts[0]->filename );580 $this->assertTrue( $dep2->scripts[0]->isRoot, 'Dep #3 through Dep #2 should be marked isRoot' );581 $this->assertEmpty( $dep2->scripts[0]->packages );582 // Ensure dep #1's dependency and dep #2's dependency is the same583 $this->assertEquals( $dep1->scripts[0]->filename, $dep2->scripts[0]->filename );584 }585 /******************************************************************586 * parseFile > 3 Dependencies, #1, #2, and #3587 * #1 with no dependency588 * #3 with a dependency on #2589 * #2 with no dependency590 * Fixture folder: 3_deps_1_feedback591 *****************************************************************/592 public function testParseFile_3Deps1Feedback()593 {594 $basePath = self::fixturesBasePath . '3_deps_1_feedback';595 $filePath = $basePath . '/main.js';596 $treeParser = new DependencyTreeParser();597 $dependencyTree = $treeParser->parseFile( $filePath );598 // Ensure root file was scanned properly599 $this->assertEquals( 'main', $dependencyTree->filename );600 $this->assertEquals( 'js', $dependencyTree->filetype );601 $this->assertEquals( $basePath, $dependencyTree->path );602 // Ensure root file (main.js) has #1 and #2 scripts but no packages603 $this->assertFalse( $dependencyTree->isRoot, 'Root file should not be marked isRoot' );604 $this->assertNotEmpty( $dependencyTree->scripts );605 $this->assertEmpty( $dependencyTree->stylesheets );606 $this->assertEmpty( $dependencyTree->packages );607 // Ensure it has #1 and #2 and #3608 $this->assertCount(3, $dependencyTree->scripts, 'Root file should have three dependent scripts' );609 $this->assertInstanceOf( 'JsPackager\File', $dependencyTree->scripts[0] );610 $this->assertInstanceOf( 'JsPackager\File', $dependencyTree->scripts[1] );611 $this->assertInstanceOf( 'JsPackager\File', $dependencyTree->scripts[2] );612 $this->assertEquals( 'dep_1', $dependencyTree->scripts[0]->filename );613 $this->assertEquals( 'dep_3', $dependencyTree->scripts[1]->filename );614 $this->assertEquals( 'dep_2', $dependencyTree->scripts[2]->filename );615 // Shortcut for easier access and readability616 $dep1 = $dependencyTree->scripts[0];617 $dep3 = $dependencyTree->scripts[1];618 $dep2 = $dependencyTree->scripts[2];619 // Ensure dependencies are not root packages themselves620 $this->assertFalse( $dep1->isRoot, 'Dep #1 should not be marked isRoot' );621 $this->assertFalse( $dep2->isRoot, 'Dep #2 should not be marked isRoot' );622 $this->assertFalse( $dep3->isRoot, 'Dep #3 should not be marked isRoot' );623 // Ensure dep #1 and #2 have no dependencies624 $this->assertCount(0, $dep1->scripts, 'Dep #1 should have no dependent script');625 $this->assertCount(0, $dep2->scripts, 'Dep #2 should have no dependent script');626 // Ensure dep #3 has #2 as a dependency627 $this->assertCount(1, $dep3->scripts, 'Dep #3 should have one dependent script');628 $this->assertEquals( 'dep_2', $dep3->scripts[0]->filename );629 $this->assertFalse( $dep3->scripts[0]->isRoot, 'File should not be marked isRoot' );630 $this->assertEmpty( $dep3->scripts[0]->packages );631 // Ensure dep #3's dependency is dependency #2632 $this->assertEquals( $dep3->scripts[0]->filename, $dep2->filename );633 }634 /******************************************************************635 * parseFile > 3 Dependencies, #1, #2, and #3636 * #1 with own dependency (#4)637 * #2 & #3 both share a third dependency (#5)638 * The shared third dependency (#5) has a dependency on #1's dependency (#4)639 * Fixture folder: 3_deps_all_on_one640 *****************************************************************/641 public function testParseFile_3DepsAllOnOne()642 {643 $basePath = self::fixturesBasePath . '3_deps_all_on_one';644 $filePath = $basePath . '/main.js';645 $treeParser = new DependencyTreeParser();646 $dependencyTree = $treeParser->parseFile( $filePath );647 // Ensure root file was scanned properly648 $this->assertEquals( 'main', $dependencyTree->filename );649 $this->assertEquals( 'js', $dependencyTree->filetype );650 $this->assertEquals( $basePath, $dependencyTree->path );651 $this->assertCount( 3, $dependencyTree->scripts );652 $this->assertCount( 0, $dependencyTree->stylesheets );653 $this->assertCount( 3, $dependencyTree->scripts );654 $this->assertFalse( $dependencyTree->isRoot );655 // Shortcut for easier access and readability656 $dep1 = $dependencyTree->scripts[0];657 $dep2 = $dependencyTree->scripts[1];658 $dep3 = $dependencyTree->scripts[2];659 // Ensure dependencies are not root packages themselves660 $this->assertFalse( $dep1->isRoot, 'Dep #1 should not be marked isRoot' );661 $this->assertFalse( $dep2->isRoot, 'Dep #2 should not be marked isRoot' );662 $this->assertFalse( $dep3->isRoot, 'Dep #3 should not be marked isRoot' );663 // #1 & #5 depends on #4664 $this->assertEquals( 'dep_4', $dep1->scripts[0]->filename );665 $dep4 = $dep1->scripts[0];666 $this->assertFalse( $dep4->isRoot, 'Dep #4 should not be marked isRoot' );667 // #2 & #3 depend on #5668 $this->assertEquals( 'dep_5', $dep2->scripts[0]->filename, "Dep #2 should depend on Dep #5" );669 $this->assertEquals( 'dep_5', $dep3->scripts[0]->filename, "Dep #3 should depend on Dep #5" );670 $dep5 = $dep2->scripts[0];671 $this->assertFalse( $dep5->isRoot, 'Dep #5 should not be marked isRoot' );672 // #5 depends on #4673 $this->assertEquals( 'dep_4', $dep5->scripts[0]->filename );674 $orderMapEntry = $dependencyTree->annotationOrderMap[0];675 $this->assertEquals( 'require', $orderMapEntry['action'], "Should reflect appropriate bucket" );676 $this->assertEquals( 0, $orderMapEntry['annotationIndex'], "Should reflect appropriate order" );677 $orderMapEntry = $dependencyTree->annotationOrderMap[1];678 $this->assertEquals( 'require', $orderMapEntry['action'], "Should reflect appropriate bucket" );679 $this->assertEquals( 1, $orderMapEntry['annotationIndex'], "Should reflect appropriate order" );680 $orderMapEntry = $dependencyTree->annotationOrderMap[2];681 $this->assertEquals( 'require', $orderMapEntry['action'], "Should reflect appropriate bucket" );682 $this->assertEquals( 2, $orderMapEntry['annotationIndex'], "Should reflect appropriate order" );683 $orderMapEntry = $dep1->annotationOrderMap[0];684 $this->assertEquals( 'require', $orderMapEntry['action'], "Should reflect appropriate bucket" );685 $this->assertEquals( 0, $orderMapEntry['annotationIndex'], "Should reflect appropriate order" );686 $orderMapEntry = $dep2->annotationOrderMap[0];687 $this->assertEquals( 'require', $orderMapEntry['action'], "Should reflect appropriate bucket" );688 $this->assertEquals( 0, $orderMapEntry['annotationIndex'], "Should reflect appropriate order" );689 $orderMapEntry = $dep3->annotationOrderMap[0];690 $this->assertEquals( 'require', $orderMapEntry['action'], "Should reflect appropriate bucket" );691 $this->assertEquals( 0, $orderMapEntry['annotationIndex'], "Should reflect appropriate order" );692 $this->assertEmpty( $dep4->annotationOrderMap, "Dep #4 has no dependencies" );693 $orderMapEntry = $dep5->annotationOrderMap[0];694 $this->assertEquals( 'require', $orderMapEntry['action'], "Should reflect appropriate bucket" );695 $this->assertEquals( 0, $orderMapEntry['annotationIndex'], "Should reflect appropriate order" );696 }697 /******************************************************************698 * parseFile > 3 Dependencies, #1, #2, and #3699 * #1 with own dependency (#4)700 * #2 & #3 both share a third dependency (#5)701 * The shared third dependency (#5) has a dependency on #1's dependency (#4)702 * Fixture folder: 3_deps_all_on_one_package703 *****************************************************************/704 public function testParseFile_3DepsAllOnOnePackage()705 {706 $basePath = self::fixturesBasePath . '3_deps_all_on_one_package';707 $filePath = $basePath . '/main.js';708 $treeParser = new DependencyTreeParser();709 $dependencyTree = $treeParser->parseFile( $filePath );710 // Ensure root file was scanned properly711 $this->assertEquals( 'main', $dependencyTree->filename, "Root file should be named main" );712 $this->assertEquals( 'js', $dependencyTree->filetype, "Root file should be of js filetype" );713 $this->assertEquals( $basePath, $dependencyTree->path, "Root file should be in the base path" );714 $this->assertCount( 3, $dependencyTree->scripts, "main.js should contain 3 scripts" );715 $this->assertCount( 0, $dependencyTree->packages, "main.js should contain no package" );716 $this->assertCount( 0, $dependencyTree->stylesheets, "main.js should contain no stylesheets" );717 $this->assertFalse( $dependencyTree->isRoot, "main.js should not be marked isRoot" );718 // Shortcut for easier access and readability719 $dep1 = $dependencyTree->scripts[0];720 $dep2 = $dependencyTree->scripts[1];721 $dep3 = $dependencyTree->scripts[2];722 // Ensure dependencies are not root packages themselves723 $this->assertFalse( $dep1->isRoot, 'Dep #1 should not be marked isRoot' );724 $this->assertFalse( $dep2->isRoot, 'Dep #2 should not be marked isRoot' );725 $this->assertFalse( $dep3->isRoot, 'Dep #3 should not be marked isRoot' );726 // #1 & #5 depends on #4727 $this->assertEquals( 'dep_4', $dep1->scripts[0]->filename, "Dep #1 should depend on Dep #4" );728 $dep4 = $dep1->scripts[0];729 $this->assertTrue( $dep4->isRoot, 'Dep #4 should be marked isRoot' );730 // #2 & #3 depend on #5731 $this->assertEquals( 'dep_5', $dep2->scripts[0]->filename, "Dep #2 should depend on Dep #5" );732 $this->assertEquals( 'dep_5', $dep3->scripts[0]->filename, "Dep #3 should depend on Dep #5" );733 $dep5 = $dep2->scripts[0];734 $this->assertFalse( $dep5->isRoot, 'File should not be marked isRoot' );735 $this->assertEquals( $basePath . '/dep_4.js', $dep5->packages[0], 'Dep #5 should contain package entry for Dep #4');736 // #5 depends on #4737 $this->assertEquals( 'dep_4', $dep5->scripts[0]->filename, "Dep #5 should depend on Dep #4" );738 }739 /******************************************************************740 * parseFile > annotation_nocompile741 * Fixture folder: 3annotation_nocompile742 *****************************************************************/743 public function testParseFile_annotation_nocompile()744 {745 $basePath = self::fixturesBasePath . 'annotation_nocompile';746 $filePath = $basePath . '/main.js';747 $treeParser = new DependencyTreeParser();748 $dependencyTree = $treeParser->parseFile( $filePath );749 // Ensure root file was scanned properly750 $this->assertEquals( 'main', $dependencyTree->filename, "Root file should be named main" );751 $this->assertEquals( 'js', $dependencyTree->filetype, "Root file should be of js filetype" );752 $this->assertEquals( $basePath, $dependencyTree->path, "Root file should be in the base path" );753 $this->assertCount( 4, $dependencyTree->scripts, "main.js should contain 4 scripts" );754 $this->assertCount( 2, $dependencyTree->packages, "main.js should contain 2 packages" );755 $this->assertCount( 0, $dependencyTree->stylesheets, "main.js should contain no stylesheets" );756 $this->assertFalse( $dependencyTree->isMarkedNoCompile, "main.js should not be marked no compile" );757 // Shortcut for easier access and readability758 $nocompilePackage = $dependencyTree->scripts[0];759 $nocompileScript = $dependencyTree->scripts[1];760 $normalPackage = $dependencyTree->scripts[2];761 $normalScript = $dependencyTree->scripts[3];762 // Ensure dependencies `root` annotations were handled763 $this->assertTrue( $nocompilePackage->isRoot, 'Dep #1 should be marked isRoot' );764 $this->assertFalse( $nocompileScript->isRoot, 'Dep #2 should not be marked isRoot' );765 $this->assertTrue( $normalPackage->isRoot, 'Dep #3 should be marked isRoot' );766 $this->assertFalse( $normalScript->isRoot, 'Dep #4 should not be marked isRoot' );767 // Ensure dependencies `nocompile` annotations were handled768 $this->assertTrue( $nocompilePackage->isMarkedNoCompile, 'Dep #1 should be marked no compile' );769 $this->assertTrue( $nocompileScript->isMarkedNoCompile, 'Dep #2 should be be marked no compile' );770 $this->assertFalse( $normalPackage->isMarkedNoCompile, 'Dep #3 should not be marked no compile' );771 $this->assertFalse( $normalScript->isMarkedNoCompile, 'Dep #4 should not be marked no compile' );772 // Ensure the packages were detected properly773 $this->assertEquals(774 "tests/JsPackager/fixtures/annotation_nocompile/some/nocompile/package.js",775 $dependencyTree->packages[0]776 );777 $this->assertEquals(778 "tests/JsPackager/fixtures/annotation_nocompile/some/normal/package.js",779 $dependencyTree->packages[1]780 );...

Full Screen

Full Screen

EditorConfigFile.php

Source:EditorConfigFile.php Github

copy

Full Screen

...23 private $path;24 /** @var string */25 private $fileContent = '';26 /** @var bool */27 private $isRoot = \false;28 /** @var array<int, Section> */29 private $sections = [];30 /** @var Factory */31 private $declarationFactory;32 public function __construct(string $path, ?\RectorPrefix20211231\Idiosyncratic\EditorConfig\Declaration\Factory $declarationFactory = null)33 {34 $this->declarationFactory = $declarationFactory ?? new \RectorPrefix20211231\Idiosyncratic\EditorConfig\Declaration\Factory();35 if (\is_file($path) === \false || \is_readable($path) === \false) {36 throw new \RuntimeException(\sprintf('File %s does not exist or is not readable', $path));37 }38 $content = $this->cleanContent($path);39 $this->path = $path;40 $this->parse($content);41 }42 public function __toString() : string43 {44 $preamble = $this->isRoot() === \true ? "root=true\n" : '';45 $sections = [];46 foreach ($this->sections as $section) {47 $sections[] = (string) $section;48 }49 return \sprintf('%s%s', $preamble, \implode("\n", $sections));50 }51 public function isRoot() : bool52 {53 return $this->isRoot;54 }55 public function getPath() : string56 {57 return $this->path;58 }59 /**60 * @return array<string, mixed>61 */62 public function getConfigForPath(string $path) : array63 {64 $configuration = [];65 foreach ($this->sections as $section) {66 if ($section->matches($path) === \false) {67 continue;68 }69 $configuration = \array_merge($configuration, $section->getDeclarations());70 }71 return $configuration;72 }73 private function parse(string $content) : void74 {75 $this->fileContent = $content;76 $content = \preg_replace('/^\\s/m', '', $this->fileContent) ?? $this->fileContent;77 $parsedContent = $this->parseIniString($content);78 if (isset($parsedContent['root']) === \true) {79 $this->setIsRoot($parsedContent['root']);80 }81 foreach ($parsedContent as $glob => $declarations) {82 if (\is_array($declarations) === \false) {83 continue;84 }85 $this->sections[] = new \RectorPrefix20211231\Idiosyncratic\EditorConfig\Section($this->getGlobPrefix($glob), $glob, $declarations, $this->declarationFactory);86 }87 }88 private function setIsRoot(string $isRoot) : void89 {90 if (\in_array($isRoot, ['true', 'false']) === \false) {91 throw new \RectorPrefix20211231\Idiosyncratic\EditorConfig\Exception\InvalidValue('root', $isRoot);92 }93 $this->isRoot = $isRoot === 'true';94 }95 private function getGlobPrefix(string $glob) : string96 {97 return \strpos($glob, '/') === 0 ? \dirname($this->path) : '**/';98 }99 /**100 * @return array<string, mixed>101 */102 private function parseIniString(string $content) : array103 {104 $parsedContent = \parse_ini_string($content, \true, \INI_SCANNER_RAW);105 return \is_array($parsedContent) === \true ? $parsedContent : [];106 }107 private function cleanContent(string $path) : string...

Full Screen

Full Screen

CustomRelativePathImplementation.php

Source:CustomRelativePathImplementation.php Github

copy

Full Screen

...5use Arokettu\Path\RelativePathInterface;6class CustomRelativePathImplementation implements RelativePathInterface7{8 private array $components;9 private bool $isRoot;10 public function __construct(array $components, bool $isRoot)11 {12 $this->components = $components;13 $this->isRoot = $isRoot;14 }15 public function isAbsolute(): bool16 {17 return false;18 }19 public function isRelative(): bool20 {21 return true;22 }23 public function __toString(): string24 {25 return '';26 }27 public function getPrefix(): string28 {29 return '';30 }31 public function getComponents(): array32 {33 return $this->components;34 }35 public function toString(): string36 {37 throw new \BadMethodCallException('Irrelevant');38 }39 public function resolveRelative(RelativePathInterface $path, bool $strict = false): PathInterface40 {41 throw new \BadMethodCallException('Irrelevant');42 }43 public function isRoot(): bool44 {45 return $this->isRoot;46 }47}...

Full Screen

Full Screen

isRoot

Using AI Code Generation

copy

Full Screen

1$path = new Path;2echo $path->isRoot();3$path = new Path;4echo $path->isRoot();5$path = new Path;6echo $path->isRoot();7if(!class_exists('Path')) {8 include_once 'path.php';9}10Your name to display (optional):11Your name to display (optional):12if(!class_exists('Path')) {13 include_once 'path.php';14}15Your name to display (optional):

Full Screen

Full Screen

isRoot

Using AI Code Generation

copy

Full Screen

1$root = new Path('1.php');2$root->isRoot();3$root = new Path('/1.php');4$root->isRoot();5$root = new Path('/1.php');6$root->isRoot();7$root = new Path('1.php');8$root->isRoot();9$root = new Path('/1.php');10$root->isRoot();11$root = new Path('/1.php');12$root->isRoot();13$root = new Path('/1.php');14$root->isRoot();15$root = new Path('/1.php');16$root->isRoot();17$root = new Path('/1.php');18$root->isRoot();19$root = new Path('/1.php');20$root->isRoot();21$root = new Path('/1.php');22$root->isRoot();23$root = new Path('/1.php');24$root->isRoot();25$root = new Path('/1.php');26$root->isRoot();27$root = new Path('/1.php');28$root->isRoot();

Full Screen

Full Screen

isRoot

Using AI Code Generation

copy

Full Screen

1$path = new Path("1.php");2if($path->isRoot())3{4 echo "The path is root";5}6{7 echo "The path is not root";8}9$path = new Path("/1.php");10if($path->isRoot())11{12 echo "The path is root";13}14{15 echo "The path is not root";16}

Full Screen

Full Screen

isRoot

Using AI Code Generation

copy

Full Screen

1$path = new Path();2if ($path->isRoot()) {3 echo 'You are in root directory';4} else {5 echo 'You are in sub directory';6}7$path = new Path();8if ($path->isRoot()) {9 echo 'You are in root directory';10} else {11 echo 'You are in sub directory';12}13$path = new Path();14if ($path->isRoot()) {15 echo 'You are in root directory';16} else {17 echo 'You are in sub directory';18}19$path = new Path();20if ($path->isRoot()) {21 echo 'You are in root directory';22} else {23 echo 'You are in sub directory';24}25$path = new Path();26if ($path->isRoot()) {27 echo 'You are in root directory';28} else {29 echo 'You are in sub directory';30}31$path = new Path();32if ($path->isRoot()) {33 echo 'You are in root directory';34} else {35 echo 'You are in sub directory';36}37$path = new Path();38if ($path->isRoot()) {39 echo 'You are in root directory';40} else {41 echo 'You are in sub directory';42}43$path = new Path();44if ($path->isRoot()) {45 echo 'You are in root directory';46} else {47 echo 'You are in sub directory';48}49$path = new Path();50if ($path->isRoot()) {51 echo 'You are in root directory';52} else {53 echo 'You are in sub directory';54}55$path = new Path();56if ($path->isRoot()) {

Full Screen

Full Screen

isRoot

Using AI Code Generation

copy

Full Screen

1$myPath = new Path('/home/username');2if($myPath->isRoot()) {3 echo 'This is a root path';4}5$myPath = new Path('/home/username');6if($myPath->isAbsolute()) {7 echo 'This is an absolute path';8}9$myPath = new Path('/home/username');10if($myPath->isRelative()) {11 echo 'This is a relative path';12}13$myPath = new Path('/home/username');14if($myPath->isDirectory()) {15 echo 'This is a directory path';16}17$myPath = new Path('/home/username');18if($myPath->isFile()) {19 echo 'This is a file path';20}21$myPath = new Path('/home/username');22if($myPath->isLink()) {23 echo 'This is a link path';24}25$myPath = new Path('/home/username');26if($myPath->isReadable()) {27 echo 'This is a readable path';28}29$myPath = new Path('/home/username');30if($myPath->isWritable()) {31 echo 'This is a writable path';32}33$myPath = new Path('/home/username');34if($myPath->isExecutable()) {35 echo 'This is an executable path';36}37$myPath = new Path('/home/username');38if($myPath->isHidden()) {39 echo 'This is a hidden path';40}41$myPath = new Path('/home/username');42if($myPath->isDot()) {43 echo 'This is a dot path';44}45$myPath = new Path('/home/username');46if($myPath->isDevice()) {47 echo 'This is a device path';48}

Full Screen

Full Screen

isRoot

Using AI Code Generation

copy

Full Screen

1$path = new Path('c:\temp\test');2if($path->isRoot())3{4 echo 'This is a root path';5}6{7 echo 'This is not a root path';8}9$path = new Path('c:\temp\test\');10if($path->isRoot())11{12 echo 'This is a root path';13}14{15 echo 'This is not a root path';16}

Full Screen

Full Screen

isRoot

Using AI Code Generation

copy

Full Screen

1$root = new Path('/home/username');2if ($root->isRoot()) {3";4} else {5";6}7$root = new Path('/usr/local/bin');8if ($root->isRoot()) {9";10} else {11";12}13$root = new Path('/var/www');14if ($root->isRoot()) {15";16} else {17";18}19$root = new Path('/var');20if ($root->isRoot()) {21";22} else {23";24}25$root = new Path('/home');26if ($root->isRoot()) {27";28} else {29";30}31$root = new Path('/home/username/public_html');32if ($root->isRoot()) {33";34} else {35";36}37$root = new Path('/home/username/public_html/htdocs');38if ($root->isRoot()) {39";40} else {41";42}

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful