@@ -118,6 +118,16 @@ protected function createScreenshot()
118
118
$ browsershot ->windowSize ($ this ->currentResolution ['width ' ], $ this ->currentResolution ['height ' ])
119
119
->save ($ this ->screenshotOutputPath . DIRECTORY_SEPARATOR . $ filename );
120
120
}
121
+ /**
122
+ * Determines whether or not the screenshots should be updated instead of
123
+ * matched.
124
+ *
125
+ * @return bool
126
+ */
127
+ protected function shouldUpdateScreenshots (): bool
128
+ {
129
+ return in_array ('--update-screenshots ' , $ _SERVER ['argv ' ], true );
130
+ }
121
131
122
132
protected function createDiff ()
123
133
{
@@ -139,12 +149,6 @@ protected function createDiff()
139
149
140
150
$ result = $ diff ->save ($ this ->diffOutputPath . DIRECTORY_SEPARATOR . $ this ->getDiffFilename ());
141
151
142
- // Rename new image for next comparison
143
- rename (
144
- $ this ->screenshotOutputPath . DIRECTORY_SEPARATOR . $ this ->getNewFilename (),
145
- $ this ->screenshotOutputPath . DIRECTORY_SEPARATOR . $ this ->getComparisonFilename ()
146
- );
147
-
148
152
if (! is_null ($ result )) {
149
153
try {
150
154
Assert::assertLessThanOrEqual (
@@ -154,11 +158,27 @@ protected function createDiff()
154
158
"See: " . $ this ->diffOutputPath . $ this ->getDiffFilename ()
155
159
);
156
160
} catch (ExpectationFailedException $ e ) {
157
- echo exec (__DIR__ . '/../bin/imgcat ' . escapeshellarg ($ this ->diffOutputPath . DIRECTORY_SEPARATOR . $ this ->getDiffFilename ()));
158
-
159
- throw $ e ;
161
+ if ($ this ->shouldUpdateScreenshots ()) {
162
+ $ this ->renameScreenshots ();
163
+ return ;
164
+ } else {
165
+ echo exec (__DIR__ . '/../bin/imgcat ' . escapeshellarg ($ this ->diffOutputPath . DIRECTORY_SEPARATOR . $ this ->getDiffFilename ()));
166
+
167
+ throw $ e ;
168
+ }
160
169
}
161
170
}
171
+
172
+ // Rename new image for next comparison
173
+ $ this ->renameScreenshots ();
174
+ }
175
+
176
+ protected function renameScreenshots ()
177
+ {
178
+ rename (
179
+ $ this ->screenshotOutputPath . DIRECTORY_SEPARATOR . $ this ->getNewFilename (),
180
+ $ this ->screenshotOutputPath . DIRECTORY_SEPARATOR . $ this ->getComparisonFilename ()
181
+ );
162
182
}
163
183
164
184
}
0 commit comments