Skip to content

Commit 1bc7de3

Browse files
jasnyNaktibalda
authored andcommitted
Improved detection of content-type for .fail files (#5711)
* Fix for file extension of .fail files. The `Content-Type` header may contain a charset, which cause XML and JSON .fail files to have a .html extension. * If a REST API outputs text/plain content, the .fail file should have the .txt extension.
1 parent 90ea7e7 commit 1bc7de3

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/Codeception/Lib/InnerBrowser.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,19 @@ public function _failed(TestInterface $test, $fail)
6767
}
6868
$filename = preg_replace('~\W~', '.', Descriptor::getTestSignatureUnique($test));
6969

70-
$extensions = ['application/json' => 'json', 'text/xml' => 'xml', 'application/xml' => 'xml'];
70+
$extensions = [
71+
'application/json' => 'json',
72+
'text/xml' => 'xml',
73+
'application/xml' => 'xml',
74+
'text/plain' => 'txt'
75+
];
7176

7277
$internalResponse = $this->client->getInternalResponse();
7378

74-
$responseContentType = $internalResponse ? $internalResponse->getHeader('content-type') : null;
79+
$responseContentType = $internalResponse ? $internalResponse->getHeader('content-type') : '';
80+
list($responseMimeType) = explode(';', $responseContentType);
7581

76-
$extension = isset($extensions[$responseContentType]) ? $extensions[$responseContentType] : 'html';
82+
$extension = isset($extensions[$responseMimeType]) ? $extensions[$responseMimeType] : 'html';
7783

7884
$filename = mb_strcut($filename, 0, 244, 'utf-8') . '.fail.' . $extension;
7985
$this->_savePageSource($report = codecept_output_dir() . $filename);

0 commit comments

Comments
 (0)