Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 9 | use Illuminate\Support\Facades\Artisan; |
||
| 10 | use LaravelZero\Framework\Contracts\Providers\ComposerContract; |
||
| 11 | |||
| 12 | final class DotenvInstallTest extends TestCase |
||
| 13 | { |
||
| 14 | public function tearDown() |
||
| 15 | { |
||
| 16 | File::delete(base_path('.env')); |
||
| 17 | File::delete(base_path('.env.example')); |
||
| 18 | File::delete(base_path('.gitignore')); |
||
| 19 | touch(base_path('.gitignore')); |
||
| 20 | } |
||
| 21 | |||
| 22 | public function testRequiredPackages(): void |
||
| 23 | { |
||
| 24 | $this->mockComposer(); |
||
| 25 | |||
| 26 | Artisan::call('app:install', ['component' => 'dotenv']); |
||
| 27 | } |
||
| 28 | |||
| 29 | public function testCopyStubs(): void |
||
| 30 | { |
||
| 31 | $this->mockComposer(); |
||
| 32 | |||
| 33 | Artisan::call('app:install', ['component' => 'dotenv']); |
||
| 34 | |||
| 35 | $this->assertTrue(File::exists(base_path('.env'))); |
||
| 36 | $this->assertTrue(File::exists(base_path('.env.example'))); |
||
| 37 | } |
||
| 38 | |||
| 39 | public function testNewGitIgnoreLines(): void |
||
| 40 | { |
||
| 57 |