Restore working directory if test fails (#1490)
This test changes directory then performs an assertion. No problem if the assertion succeeds. I was a little concerned about what would happen if the assertion fails, leaving us in the new directory. So I have changed test to use setUp/tearDown to ensure that we end up where we started.
This commit is contained in:
parent
84e03da5c7
commit
9947de3b89
|
@ -9,6 +9,18 @@ use PhpOffice\PhpSpreadsheetTests\Functional;
|
|||
|
||||
class ImagesRootTest extends Functional\AbstractFunctional
|
||||
{
|
||||
private $curdir;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->curdir = getcwd();
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
chdir($this->curdir);
|
||||
}
|
||||
|
||||
public function testImagesRoot(): void
|
||||
{
|
||||
$spreadsheet = new Spreadsheet();
|
||||
|
@ -20,7 +32,6 @@ class ImagesRootTest extends Functional\AbstractFunctional
|
|||
$newdir = __DIR__ . '/../../../data/Reader/HTML';
|
||||
$stub = 'image.jpg';
|
||||
$imagePath = "./$stub";
|
||||
$curdir = getcwd();
|
||||
chdir($newdir);
|
||||
self::assertFileExists($imagePath);
|
||||
$drawing->setPath($imagePath);
|
||||
|
@ -34,7 +45,6 @@ class ImagesRootTest extends Functional\AbstractFunctional
|
|||
$writer = new Html($spreadsheet);
|
||||
$writer->setImagesRoot($root);
|
||||
$html = $writer->generateHTMLAll();
|
||||
chdir($curdir);
|
||||
$dom = new DOMDocument();
|
||||
$dom->loadHTML($html);
|
||||
$body = $dom->getElementsByTagName('body')[0];
|
||||
|
|
Loading…
Reference in New Issue