@@ -94,6 +94,22 @@ public function testGetRepository(): void
9494 }
9595 }
9696
97+ public function testListRepositoryContentsNonExistingPath (): void
98+ {
99+ $ repositoryName = 'test-list-repository-contents-invalid- ' . \uniqid ();
100+ $ this ->vcsAdapter ->createRepository (static ::$ owner , $ repositoryName , false );
101+ $ this ->vcsAdapter ->createFile (static ::$ owner , $ repositoryName , 'README.md ' , '# Test ' );
102+
103+ try {
104+ $ contents = $ this ->vcsAdapter ->listRepositoryContents (static ::$ owner , $ repositoryName , 'non-existing-path ' );
105+
106+ $ this ->assertIsArray ($ contents );
107+ $ this ->assertEmpty ($ contents );
108+ } finally {
109+ $ this ->vcsAdapter ->deleteRepository (static ::$ owner , $ repositoryName );
110+ }
111+ }
112+
97113 public function testDeleteRepository (): void
98114 {
99115 $ repositoryName = 'test-delete-repository- ' . \uniqid ();
@@ -386,7 +402,101 @@ public function testGetPullRequestWithInvalidNumber(): void
386402
387403 public function testGetRepositoryTree (): void
388404 {
389- $ this ->markTestSkipped ('Not implemented for GitLab yet ' );
405+ $ repositoryName = 'test-get-repository-tree- ' . \uniqid ();
406+ $ this ->vcsAdapter ->createRepository (static ::$ owner , $ repositoryName , false );
407+
408+ try {
409+ $ this ->vcsAdapter ->createFile (static ::$ owner , $ repositoryName , 'README.md ' , '# Test ' );
410+ $ this ->vcsAdapter ->createFile (static ::$ owner , $ repositoryName , 'src/main.php ' , '<?php echo "hello"; ' );
411+ $ this ->vcsAdapter ->createFile (static ::$ owner , $ repositoryName , 'src/lib.php ' , '<?php // lib ' );
412+
413+ // Non recursive — root level only
414+ $ tree = $ this ->vcsAdapter ->getRepositoryTree (static ::$ owner , $ repositoryName , static ::$ defaultBranch , false );
415+
416+ $ this ->assertIsArray ($ tree );
417+ $ this ->assertContains ('README.md ' , $ tree );
418+ $ this ->assertContains ('src ' , $ tree );
419+ $ this ->assertCount (2 , $ tree );
420+
421+ // Recursive — all files
422+ $ treeRecursive = $ this ->vcsAdapter ->getRepositoryTree (static ::$ owner , $ repositoryName , static ::$ defaultBranch , true );
423+
424+ $ this ->assertIsArray ($ treeRecursive );
425+ $ this ->assertContains ('README.md ' , $ treeRecursive );
426+ $ this ->assertContains ('src/main.php ' , $ treeRecursive );
427+ $ this ->assertContains ('src/lib.php ' , $ treeRecursive );
428+ } finally {
429+ $ this ->vcsAdapter ->deleteRepository (static ::$ owner , $ repositoryName );
430+ }
431+ }
432+
433+ public function testGetRepositoryTreeWithInvalidBranch (): void
434+ {
435+ $ repositoryName = 'test-get-repository-tree-invalid- ' . \uniqid ();
436+ $ this ->vcsAdapter ->createRepository (static ::$ owner , $ repositoryName , false );
437+ $ this ->vcsAdapter ->createFile (static ::$ owner , $ repositoryName , 'README.md ' , '# Test ' );
438+
439+ try {
440+ $ tree = $ this ->vcsAdapter ->getRepositoryTree (static ::$ owner , $ repositoryName , 'non-existing-branch ' , false );
441+
442+ $ this ->assertIsArray ($ tree );
443+ $ this ->assertEmpty ($ tree );
444+ } finally {
445+ $ this ->vcsAdapter ->deleteRepository (static ::$ owner , $ repositoryName );
446+ }
447+ }
448+
449+ public function testGetRepositoryContent (): void
450+ {
451+ $ repositoryName = 'test-get-repository-content- ' . \uniqid ();
452+ $ this ->vcsAdapter ->createRepository (static ::$ owner , $ repositoryName , false );
453+
454+ try {
455+ $ fileContent = '# Hello World ' ;
456+ $ this ->vcsAdapter ->createFile (static ::$ owner , $ repositoryName , 'README.md ' , $ fileContent );
457+
458+ $ result = $ this ->vcsAdapter ->getRepositoryContent (static ::$ owner , $ repositoryName , 'README.md ' );
459+
460+ $ this ->assertIsArray ($ result );
461+ $ this ->assertArrayHasKey ('content ' , $ result );
462+ $ this ->assertArrayHasKey ('sha ' , $ result );
463+ $ this ->assertArrayHasKey ('size ' , $ result );
464+ $ this ->assertSame ($ fileContent , $ result ['content ' ]);
465+ $ this ->assertGreaterThan (0 , $ result ['size ' ]);
466+ } finally {
467+ $ this ->vcsAdapter ->deleteRepository (static ::$ owner , $ repositoryName );
468+ }
469+ }
470+
471+ public function testGetRepositoryContentWithRef (): void
472+ {
473+ $ repositoryName = 'test-get-repository-content-ref- ' . \uniqid ();
474+ $ this ->vcsAdapter ->createRepository (static ::$ owner , $ repositoryName , false );
475+
476+ try {
477+ $ this ->vcsAdapter ->createFile (static ::$ owner , $ repositoryName , 'test.txt ' , 'main branch content ' );
478+
479+ $ result = $ this ->vcsAdapter ->getRepositoryContent (static ::$ owner , $ repositoryName , 'test.txt ' , static ::$ defaultBranch );
480+
481+ $ this ->assertIsArray ($ result );
482+ $ this ->assertSame ('main branch content ' , $ result ['content ' ]);
483+ } finally {
484+ $ this ->vcsAdapter ->deleteRepository (static ::$ owner , $ repositoryName );
485+ }
486+ }
487+
488+ public function testGetRepositoryContentFileNotFound (): void
489+ {
490+ $ repositoryName = 'test-get-repository-content-not-found- ' . \uniqid ();
491+ $ this ->vcsAdapter ->createRepository (static ::$ owner , $ repositoryName , false );
492+ $ this ->vcsAdapter ->createFile (static ::$ owner , $ repositoryName , 'README.md ' , '# Test ' );
493+
494+ try {
495+ $ this ->expectException (\Utopia \VCS \Exception \FileNotFound::class);
496+ $ this ->vcsAdapter ->getRepositoryContent (static ::$ owner , $ repositoryName , 'non-existing.txt ' );
497+ } finally {
498+ $ this ->vcsAdapter ->deleteRepository (static ::$ owner , $ repositoryName );
499+ }
390500 }
391501
392502 public function testListBranches (): void
@@ -396,11 +506,67 @@ public function testListBranches(): void
396506
397507 public function testListRepositoryLanguages (): void
398508 {
399- $ this ->markTestSkipped ('Not implemented for GitLab yet ' );
509+ $ repositoryName = 'test-list-repository-languages- ' . \uniqid ();
510+ $ this ->vcsAdapter ->createRepository (static ::$ owner , $ repositoryName , false );
511+
512+ try {
513+ $ this ->vcsAdapter ->createFile (static ::$ owner , $ repositoryName , 'main.php ' , '<?php echo "test"; ' );
514+ $ this ->vcsAdapter ->createFile (static ::$ owner , $ repositoryName , 'script.js ' , 'console.log("test"); ' );
515+
516+ sleep (5 ); // ← increase from 2 to 5
517+
518+ $ languages = $ this ->vcsAdapter ->listRepositoryLanguages (static ::$ owner , $ repositoryName );
519+
520+ $ this ->assertIsArray ($ languages );
521+ $ this ->assertNotEmpty ($ languages );
522+ $ this ->assertContains ('PHP ' , $ languages );
523+ } finally {
524+ $ this ->vcsAdapter ->deleteRepository (static ::$ owner , $ repositoryName );
525+ }
526+ }
527+
528+ public function testListRepositoryLanguagesEmptyRepo (): void
529+ {
530+ $ repositoryName = 'test-list-repository-languages-empty- ' . \uniqid ();
531+ $ this ->vcsAdapter ->createRepository (static ::$ owner , $ repositoryName , false );
532+
533+ try {
534+ $ languages = $ this ->vcsAdapter ->listRepositoryLanguages (static ::$ owner , $ repositoryName );
535+
536+ $ this ->assertIsArray ($ languages );
537+ $ this ->assertEmpty ($ languages );
538+ } finally {
539+ $ this ->vcsAdapter ->deleteRepository (static ::$ owner , $ repositoryName );
540+ }
400541 }
401542
402543 public function testListRepositoryContents (): void
403544 {
404- $ this ->markTestSkipped ('Not implemented for GitLab yet ' );
545+ $ repositoryName = 'test-list-repository-contents- ' . \uniqid ();
546+ $ this ->vcsAdapter ->createRepository (static ::$ owner , $ repositoryName , false );
547+
548+ try {
549+ $ this ->vcsAdapter ->createFile (static ::$ owner , $ repositoryName , 'README.md ' , '# Test ' );
550+ $ this ->vcsAdapter ->createFile (static ::$ owner , $ repositoryName , 'file1.txt ' , 'content1 ' );
551+ $ this ->vcsAdapter ->createFile (static ::$ owner , $ repositoryName , 'src/main.php ' , '<?php ' );
552+
553+ $ contents = $ this ->vcsAdapter ->listRepositoryContents (static ::$ owner , $ repositoryName );
554+
555+ $ this ->assertIsArray ($ contents );
556+ $ this ->assertCount (3 , $ contents );
557+
558+ $ names = array_column ($ contents , 'name ' );
559+ $ this ->assertContains ('README.md ' , $ names );
560+ $ this ->assertContains ('file1.txt ' , $ names );
561+ $ this ->assertContains ('src ' , $ names );
562+
563+ foreach ($ contents as $ item ) {
564+ $ this ->assertArrayHasKey ('name ' , $ item );
565+ $ this ->assertArrayHasKey ('type ' , $ item );
566+ $ this ->assertArrayHasKey ('size ' , $ item );
567+ }
568+ } finally {
569+ $ this ->vcsAdapter ->deleteRepository (static ::$ owner , $ repositoryName );
570+ }
405571 }
406572}
0 commit comments