Skip to content

Commit 615c0cb

Browse files
committed
Only use assertion when diff returns something
1 parent bd46ba9 commit 615c0cb

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/VisualDiffTester.php

+13-11
Original file line numberDiff line numberDiff line change
@@ -145,17 +145,19 @@ protected function createDiff()
145145
$this->screenshotOutputPath . DIRECTORY_SEPARATOR . $this->getComparisonFilename()
146146
);
147147

148-
try {
149-
Assert::assertLessThanOrEqual(
150-
config('visualdiff.maximum_error_percentage'),
151-
$result->error_percentage,
152-
"The visual diff for " . $this->name . " has a higher pixel diff than the allowed maximum." . PHP_EOL .
153-
"See: " . $this->diffOutputPath . $this->getDiffFilename()
154-
);
155-
} catch (ExpectationFailedException $e) {
156-
echo exec(__DIR__ . '/../bin/imgcat ' . escapeshellarg($this->diffOutputPath . DIRECTORY_SEPARATOR . $this->getDiffFilename()));
157-
158-
throw $e;
148+
if (! is_null($result)) {
149+
try {
150+
Assert::assertLessThanOrEqual(
151+
config('visualdiff.maximum_error_percentage'),
152+
$result->error_percentage,
153+
"The visual diff for " . $this->name . " has a higher pixel diff than the allowed maximum." . PHP_EOL .
154+
"See: " . $this->diffOutputPath . $this->getDiffFilename()
155+
);
156+
} catch (ExpectationFailedException $e) {
157+
echo exec(__DIR__ . '/../bin/imgcat ' . escapeshellarg($this->diffOutputPath . DIRECTORY_SEPARATOR . $this->getDiffFilename()));
158+
159+
throw $e;
160+
}
159161
}
160162
}
161163

0 commit comments

Comments
 (0)