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 LaravelZero\Framework\Contracts\Providers\ComposerContract; |
||
10 | |||
11 | final class DatabaseInstallTest extends TestCase |
||
12 | { |
||
13 | public function tearDown() |
||
14 | { |
||
15 | File::delete(database_path('database.sqlite')); |
||
16 | File::delete(database_path('migrations')); |
||
17 | File::delete(database_path('seeds'.DIRECTORY_SEPARATOR.'DatabaseSeeder.php')); |
||
18 | File::delete(base_path('.gitignore')); |
||
19 | touch(base_path('.gitignore')); |
||
20 | } |
||
21 | |||
22 | public function testRequiredPackages(): void |
||
23 | { |
||
24 | $composerMock = $this->createMock(ComposerContract::class); |
||
25 | |||
26 | $composerMock->expects($this->once()) |
||
27 | ->method('require') |
||
28 | ->with('illuminate/database "5.7.*"'); |
||
29 | |||
30 | $this->app->instance(ComposerContract::class, $composerMock); |
||
31 | |||
32 | Artisan::call('app:install', ['component' => 'database']); |
||
33 | } |
||
34 | |||
35 | public function testCopyStubs(): void |
||
36 | { |
||
37 | $this->mockComposer(); |
||
38 | |||
39 | Artisan::call('app:install', ['component' => 'database']); |
||
40 | |||
41 | $this->assertTrue(File::exists(config_path('database.php'))); |
||
42 | $this->assertTrue(File::exists(database_path('database.sqlite'))); |
||
43 | $this->assertTrue(File::exists(database_path('migrations'))); |
||
44 | $this->assertTrue(File::exists(database_path('seeds'.DIRECTORY_SEPARATOR.'DatabaseSeeder.php'))); |
||
45 | } |
||
63 |