|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests; |
| 4 | + |
| 5 | +use PHPUnit\Framework\TestCase; |
| 6 | +use ReflectionMethod; |
| 7 | +use Tighten\TLint\Commands\LintCommand; |
| 8 | + |
| 9 | +class ExcludedPathTest extends TestCase |
| 10 | +{ |
| 11 | + private string $root; |
| 12 | + |
| 13 | + protected function setUp(): void |
| 14 | + { |
| 15 | + parent::setUp(); |
| 16 | + |
| 17 | + $this->root = realpath(sys_get_temp_dir()); |
| 18 | + } |
| 19 | + |
| 20 | + private function isOnExcludeList(string $filepath): bool |
| 21 | + { |
| 22 | + $command = new LintCommand(sys_get_temp_dir()); |
| 23 | + |
| 24 | + $method = new ReflectionMethod($command, 'isOnExcludeList'); |
| 25 | + |
| 26 | + return $method->invoke($command, $filepath); |
| 27 | + } |
| 28 | + |
| 29 | + /** @test */ |
| 30 | + public function it_excludes_root_vendor_directory() |
| 31 | + { |
| 32 | + $DS = DIRECTORY_SEPARATOR; |
| 33 | + |
| 34 | + $this->assertTrue($this->isOnExcludeList("{$this->root}{$DS}vendor{$DS}league{$DS}commonmark{$DS}src{$DS}File.php")); |
| 35 | + } |
| 36 | + |
| 37 | + /** @test */ |
| 38 | + public function it_allows_vendor_views_directory() |
| 39 | + { |
| 40 | + $DS = DIRECTORY_SEPARATOR; |
| 41 | + |
| 42 | + $this->assertFalse($this->isOnExcludeList("{$this->root}{$DS}resources{$DS}views{$DS}vendor{$DS}mail{$DS}html{$DS}header.blade.php")); |
| 43 | + } |
| 44 | + |
| 45 | + /** @test */ |
| 46 | + public function it_does_not_exclude_files_containing_vendor_in_name() |
| 47 | + { |
| 48 | + $DS = DIRECTORY_SEPARATOR; |
| 49 | + |
| 50 | + $this->assertFalse($this->isOnExcludeList("{$this->root}{$DS}app{$DS}Http{$DS}Controllers{$DS}VendorController.php")); |
| 51 | + } |
| 52 | + |
| 53 | + /** @test */ |
| 54 | + public function it_excludes_root_node_modules_directory() |
| 55 | + { |
| 56 | + $DS = DIRECTORY_SEPARATOR; |
| 57 | + |
| 58 | + $this->assertTrue($this->isOnExcludeList("{$this->root}{$DS}node_modules{$DS}lodash{$DS}index.js")); |
| 59 | + } |
| 60 | + |
| 61 | + /** @test */ |
| 62 | + public function it_does_not_exclude_files_containing_node_modules_in_name() |
| 63 | + { |
| 64 | + $DS = DIRECTORY_SEPARATOR; |
| 65 | + |
| 66 | + $this->assertFalse($this->isOnExcludeList("{$this->root}{$DS}app{$DS}Http{$DS}Controllers{$DS}NodeModulesController.php")); |
| 67 | + } |
| 68 | + |
| 69 | + /** @test */ |
| 70 | + public function it_excludes_root_bootstrap_directory() |
| 71 | + { |
| 72 | + $DS = DIRECTORY_SEPARATOR; |
| 73 | + |
| 74 | + $this->assertTrue($this->isOnExcludeList("{$this->root}{$DS}bootstrap{$DS}app.php")); |
| 75 | + } |
| 76 | + |
| 77 | + /** @test */ |
| 78 | + public function it_does_not_exclude_files_containing_bootstrap_in_name() |
| 79 | + { |
| 80 | + $DS = DIRECTORY_SEPARATOR; |
| 81 | + |
| 82 | + $this->assertFalse($this->isOnExcludeList("{$this->root}{$DS}app{$DS}Http{$DS}Controllers{$DS}BootstrapController.php")); |
| 83 | + $this->assertFalse($this->isOnExcludeList("{$this->root}{$DS}resources{$DS}views{$DS}bootstrap-layout.blade.php")); |
| 84 | + } |
| 85 | + |
| 86 | + /** @test */ |
| 87 | + public function it_excludes_storage_framework_views_directory() |
| 88 | + { |
| 89 | + $DS = DIRECTORY_SEPARATOR; |
| 90 | + |
| 91 | + $this->assertTrue($this->isOnExcludeList("{$this->root}{$DS}storage{$DS}framework{$DS}views{$DS}cached.php")); |
| 92 | + } |
| 93 | +} |
0 commit comments