@@ -118,6 +118,16 @@ protected function createScreenshot()
118118 $ browsershot ->windowSize ($ this ->currentResolution ['width ' ], $ this ->currentResolution ['height ' ])
119119 ->save ($ this ->screenshotOutputPath . DIRECTORY_SEPARATOR . $ filename );
120120 }
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+ }
121131
122132 protected function createDiff ()
123133 {
@@ -139,12 +149,6 @@ protected function createDiff()
139149
140150 $ result = $ diff ->save ($ this ->diffOutputPath . DIRECTORY_SEPARATOR . $ this ->getDiffFilename ());
141151
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-
148152 if (! is_null ($ result )) {
149153 try {
150154 Assert::assertLessThanOrEqual (
@@ -154,11 +158,27 @@ protected function createDiff()
154158 "See: " . $ this ->diffOutputPath . $ this ->getDiffFilename ()
155159 );
156160 } 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+ }
160169 }
161170 }
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+ );
162182 }
163183
164184}
0 commit comments