From 9947de3b89cc53167893e73f62fdebc7e9f35983 Mon Sep 17 00:00:00 2001 From: oleibman Date: Sun, 24 May 2020 03:54:59 -0700 Subject: [PATCH] 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. --- .../Writer/Html/ImagesRootTest.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/PhpSpreadsheetTests/Writer/Html/ImagesRootTest.php b/tests/PhpSpreadsheetTests/Writer/Html/ImagesRootTest.php index 5c887d53..6cc7f18f 100644 --- a/tests/PhpSpreadsheetTests/Writer/Html/ImagesRootTest.php +++ b/tests/PhpSpreadsheetTests/Writer/Html/ImagesRootTest.php @@ -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];