|
| 1 | +<?php |
| 2 | + |
| 3 | +it('will remove laravel.log by default before building', function () { |
| 4 | + $logPath = 'resources/app/storage/logs'; |
| 5 | + $laravelLog = $logPath.'/laravel.log'; |
| 6 | + |
| 7 | + // Create a dummy copy of the file |
| 8 | + if (! file_exists($logPath)) { |
| 9 | + mkdir($logPath, 0755, true); |
| 10 | + } |
| 11 | + file_put_contents($laravelLog, 'TEST'); |
| 12 | + |
| 13 | + // Run the test |
| 14 | + $this->artisan('native:minify resources/app'); |
| 15 | + $this->assertFalse(file_exists($laravelLog)); |
| 16 | + |
| 17 | + // Clean up after ourselves |
| 18 | + if (file_exists($laravelLog)) { |
| 19 | + unlink($laravelLog); |
| 20 | + } |
| 21 | + if (file_exists('resources/app/storage/logs')) { |
| 22 | + rmdir('resources/app/storage/logs'); |
| 23 | + } |
| 24 | + if (file_exists('resources/app/storage')) { |
| 25 | + rmdir('resources/app/storage'); |
| 26 | + } |
| 27 | + removeAppFolder(); |
| 28 | +}); |
| 29 | + |
| 30 | +it('will remove the content folder by default before building', function () { |
| 31 | + $contentPath = 'resources/app/content'; |
| 32 | + |
| 33 | + // Create a dummy copy of the folder |
| 34 | + if (! file_exists($contentPath)) { |
| 35 | + mkdir($contentPath, 0755, true); |
| 36 | + } |
| 37 | + |
| 38 | + // Run the test |
| 39 | + $this->artisan('native:minify resources/app'); |
| 40 | + $this->assertFalse(file_exists($contentPath)); |
| 41 | + |
| 42 | + // Clean up after ourselves |
| 43 | + if (file_exists($contentPath)) { |
| 44 | + unlink($contentPath); |
| 45 | + } |
| 46 | + removeAppFolder(); |
| 47 | +}); |
| 48 | + |
| 49 | +it('will remove only files that match a globbed path', function () { |
| 50 | + $wildcardPath = 'resources/app/wildcardPath'; |
| 51 | + $yes1DeletePath = $wildcardPath.'/YES1.txt'; |
| 52 | + $yes2DeletePath = $wildcardPath.'/YES2.txt'; |
| 53 | + $noDeletePath = $wildcardPath.'/NO.txt'; |
| 54 | + |
| 55 | + config()->set('nativephp.cleanup_exclude_files', [$wildcardPath.'/YES*']); |
| 56 | + |
| 57 | + // Create some dummy files |
| 58 | + if (! file_exists($wildcardPath)) { |
| 59 | + mkdir($wildcardPath, 0755, true); |
| 60 | + } |
| 61 | + file_put_contents($yes1DeletePath, 'PLEASE DELETE ME'); |
| 62 | + file_put_contents($yes2DeletePath, 'PLEASE DELETE ME TOO'); |
| 63 | + file_put_contents($noDeletePath, 'DO NOT DELETE ME'); |
| 64 | + |
| 65 | + // Run the test |
| 66 | + $this->artisan('native:minify resources/app'); |
| 67 | + $this->assertFalse(file_exists($yes1DeletePath)); |
| 68 | + $this->assertFalse(file_exists($yes2DeletePath)); |
| 69 | + $this->assertTrue(file_exists($noDeletePath)); |
| 70 | + |
| 71 | + // Clean up after ourselves |
| 72 | + foreach ([$yes1DeletePath, $yes2DeletePath, $noDeletePath] as $remove) { |
| 73 | + if (file_exists($remove)) { |
| 74 | + unlink($remove); |
| 75 | + } |
| 76 | + } |
| 77 | + if (file_exists($wildcardPath)) { |
| 78 | + rmdir($wildcardPath); |
| 79 | + } |
| 80 | + removeAppFolder(); |
| 81 | +}); |
| 82 | + |
| 83 | +function removeAppFolder() |
| 84 | +{ |
| 85 | + if (file_exists('resources/app')) { |
| 86 | + rmdir('resources/app'); |
| 87 | + } |
| 88 | +} |
0 commit comments