Skip to content

Commit 5bbaf2d

Browse files
hms5232shaunthegeek
authored andcommitted
feat: publish xml when config not exists
otherwise, the exists config will be overridden.
1 parent 9901d66 commit 5bbaf2d

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

src/LintPublishCommand.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@ public function handle()
3030
{
3131
$basePath = $this->laravel->basePath();
3232

33-
File::copy(__DIR__ . '/stubs/phpcs.xml', $basePath . '/phpcs.xml');
34-
File::copy(__DIR__ . '/stubs/phpmd.xml', $basePath . '/phpmd.xml');
33+
if (!File::exists($basePath . '/phpcs.xml')) {
34+
File::copy(__DIR__ . '/stubs/phpcs.xml', $basePath . '/phpcs.xml');
35+
}
36+
if (!File::exists($basePath . '/phpmd.xml')) {
37+
File::copy(__DIR__ . '/stubs/phpmd.xml', $basePath . '/phpmd.xml');
38+
}
3539
if (File::exists($basePath . '/.git/hooks')) {
3640
File::copy(__DIR__ . '/stubs/git-pre-commit', $basePath . '/.git/hooks/pre-commit');
3741
File::chmod($basePath . '/.git/hooks/pre-commit', 0755);

tests/LintPublishCommandTest.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,53 @@ public function testGitExists()
2525
$this->assertFileExists($laravelPath . '/phpmd.xml');
2626
$this->assertFileExists($laravelPath . '/.git/hooks/pre-commit');
2727
}
28+
29+
public function testPhpcsExists()
30+
{
31+
$laravelPath = __DIR__ . '/../vendor/orchestra/testbench-core/laravel';
32+
File::delete($laravelPath . '/phpcs.xml');
33+
$this->assertFileDoesNotExist($laravelPath . '/phpcs.xml');
34+
File::append($laravelPath . '/phpcs.xml', 'phpcs');
35+
$this->assertFileExists($laravelPath . '/phpcs.xml');
36+
$this->artisan('lint:publish')->run();
37+
$this->assertEquals('phpcs', File::get($laravelPath . '/phpcs.xml'));
38+
$this->assertFileExists($laravelPath . '/phpmd.xml');
39+
$this->assertFileExists($laravelPath . '/.git/hooks/pre-commit');
40+
}
41+
42+
public function testPhpcsNotExists()
43+
{
44+
$laravelPath = __DIR__ . '/../vendor/orchestra/testbench-core/laravel';
45+
File::delete($laravelPath . '/phpcs.xml');
46+
$this->assertFileDoesNotExist($laravelPath . '/phpcs.xml');
47+
$this->artisan('lint:publish')->run();
48+
$this->assertFileExists($laravelPath . '/phpcs.xml');
49+
$this->assertXmlFileEqualsXmlFile(__DIR__ . '/../src/stubs/phpcs.xml', $laravelPath . '/phpcs.xml');
50+
$this->assertFileExists($laravelPath . '/phpmd.xml');
51+
$this->assertFileExists($laravelPath . '/.git/hooks/pre-commit');
52+
}
53+
54+
public function testPhpmdExists()
55+
{
56+
$laravelPath = __DIR__ . '/../vendor/orchestra/testbench-core/laravel';
57+
File::delete($laravelPath . '/phpmd.xml');
58+
$this->assertFileDoesNotExist($laravelPath . '/phpmd.xml');
59+
File::append($laravelPath . '/phpmd.xml', 'phpmd');
60+
$this->assertFileExists($laravelPath . '/phpmd.xml');
61+
$this->artisan('lint:publish')->run();
62+
$this->assertEquals('phpmd', File::get($laravelPath . '/phpmd.xml'));
63+
$this->assertFileExists($laravelPath . '/phpcs.xml');
64+
$this->assertFileExists($laravelPath . '/.git/hooks/pre-commit');
65+
}
66+
public function testPhpmdNotExists()
67+
{
68+
$laravelPath = __DIR__ . '/../vendor/orchestra/testbench-core/laravel';
69+
File::delete($laravelPath . '/phpmd.xml');
70+
$this->assertFileDoesNotExist($laravelPath . '/phpmd.xml');
71+
$this->artisan('lint:publish')->run();
72+
$this->assertFileExists($laravelPath . '/phpmd.xml');
73+
$this->assertXmlFileEqualsXmlFile(__DIR__ . '/../src/stubs/phpmd.xml', $laravelPath . '/phpmd.xml');
74+
$this->assertFileExists($laravelPath . '/phpcs.xml');
75+
$this->assertFileExists($laravelPath . '/.git/hooks/pre-commit');
76+
}
2877
}

0 commit comments

Comments
 (0)