1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BeyondCode\VisualDiff; |
4
|
|
|
|
5
|
|
|
use Laravel\Dusk\Browser; |
6
|
|
|
use Illuminate\Support\ServiceProvider; |
7
|
|
|
use Illuminate\Foundation\Testing\TestResponse; |
8
|
|
|
|
9
|
|
|
class VisualDiffServiceProvider extends ServiceProvider |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Bootstrap the application services. |
13
|
|
|
*/ |
14
|
|
|
public function boot() |
15
|
|
|
{ |
16
|
|
|
if ($this->app->runningInConsole()) { |
17
|
|
|
$this->publishes([ |
18
|
|
|
__DIR__ . '/../config/config.php' => config_path('visualdiff.php'), |
19
|
|
|
], 'config'); |
20
|
|
|
} |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Register the application services. |
25
|
|
|
*/ |
26
|
|
|
public function register() |
27
|
|
|
{ |
28
|
|
|
$this->mergeConfigFrom(__DIR__ . '/../config/config.php', 'visualdiff'); |
29
|
|
|
|
30
|
|
View Code Duplication |
TestResponse::macro('visualDiff', function ($name = null, $resolutions = null) { |
|
|
|
|
31
|
|
|
|
32
|
|
|
if (is_null($name)) { |
33
|
|
|
// Guess the test name from the backtrace |
34
|
|
|
$name = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 5)[4]['function']; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
$testResolutions = config('visualdiff.resolutions'); |
38
|
|
|
|
39
|
|
|
if (! is_null($resolutions)) { |
40
|
|
|
$testResolutions = $resolutions; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$tester = new VisualDiffTester($this->content(), $name, $testResolutions); |
44
|
|
|
|
45
|
|
|
$tester->setScreenshotOutputPath(config('visualdiff.screenshot_path')); |
46
|
|
|
$tester->setDiffOutputPath(config('visualdiff.diff_path')); |
47
|
|
|
|
48
|
|
|
$tester->createDiffs(); |
49
|
|
|
|
50
|
|
|
return $this; |
51
|
|
|
}); |
52
|
|
|
|
53
|
|
View Code Duplication |
TestResponse::macro('visualDiffForResolutions', function (array $resolutions, $name = null) { |
|
|
|
|
54
|
|
|
if (is_null($name)) { |
55
|
|
|
// Guess the test name from the backtrace |
56
|
|
|
$name = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 5)[4]['function']; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return $this->visualDiff($name, $resolutions); |
60
|
|
|
}); |
61
|
|
|
|
62
|
|
|
if (class_exists(Browser::class)) { |
63
|
|
View Code Duplication |
Browser::macro('visualDiff', function ($name = null, $resolutions = null) { |
|
|
|
|
64
|
|
|
|
65
|
|
|
if (is_null($name)) { |
66
|
|
|
// Guess the test name from the backtrace |
67
|
|
|
$name = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 7)[6]['function']; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$testResolutions = config('visualdiff.resolutions'); |
71
|
|
|
|
72
|
|
|
if (! is_null($resolutions)) { |
73
|
|
|
$testResolutions = $resolutions; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
$tester = new DuskVisualDiffTester('', $name, $testResolutions); |
77
|
|
|
$tester->setBrowser($this); |
78
|
|
|
|
79
|
|
|
$tester->setScreenshotOutputPath(config('visualdiff.screenshot_path')); |
80
|
|
|
$tester->setDiffOutputPath(config('visualdiff.diff_path')); |
81
|
|
|
|
82
|
|
|
$tester->createDiffs(); |
83
|
|
|
|
84
|
|
|
return $this; |
85
|
|
|
}); |
86
|
|
|
|
87
|
|
View Code Duplication |
Browser::macro('visualDiffForResolutions', function (array $resolutions, $name = null) { |
|
|
|
|
88
|
|
|
if (is_null($name)) { |
89
|
|
|
// Guess the test name from the backtrace |
90
|
|
|
$name = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 7)[6]['function']; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
return $this->visualDiff($name, $resolutions); |
94
|
|
|
}); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.