Skip to content

Commit 1995bf6

Browse files
jakejackson1claude
andcommitted
Write PdfX4Test's profiles and documents to a directory of each test's own
The test wrote its ICC profiles and output files to fixed names in the system temp directory, and its tear_down() deleted every mpdf-test-*.icc there. Two runs side by side removed each other's profiles mid-test and failed with unlink() and missing-file errors. Each test now works in a directory of its own under the temp directory and removes only that. The file names are kept, as the titles the tests check are taken from them. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 9770898 commit 1995bf6

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

‎tests/Mpdf/PdfX4Test.php‎

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ class PdfX4Test extends \Yoast\PHPUnitPolyfills\TestCases\TestCase
2626
*/
2727
const PDFX1A = ['PDFX' => true, 'PDFXversion' => '1a'];
2828

29+
/**
30+
* @var string A directory of this test's own, so that runs side by side cannot remove each other's files
31+
*/
32+
private $dir;
33+
2934
/**
3035
* @var string The path a CMYK profile is written to, for a CMYK output intent
3136
*/
@@ -50,19 +55,23 @@ class PdfX4Test extends \Yoast\PHPUnitPolyfills\TestCases\TestCase
5055
*/
5156
public function set_up()
5257
{
58+
$this->dir = sys_get_temp_dir() . '/mpdf-pdfx4-' . uniqid('', true);
59+
mkdir($this->dir);
60+
5361
$this->cmykProfile = $this->writeProfile('cmyk', 'CMYK');
5462
$this->grayProfile = $this->writeProfile('gray', 'GRAY');
5563
$this->rgbProfile = $this->writeProfile('rgb', 'RGB ');
5664
}
5765

5866
/**
59-
* Leaves no profile behind
67+
* Leaves no profile or document behind
6068
*/
6169
public function tear_down()
6270
{
63-
foreach (glob(sys_get_temp_dir() . '/mpdf-test-*.icc') as $profile) {
64-
unlink($profile);
71+
foreach (glob($this->dir . '/*') as $file) {
72+
unlink($file);
6573
}
74+
rmdir($this->dir);
6675
}
6776

6877
/**
@@ -74,7 +83,7 @@ public function tear_down()
7483
*/
7584
private function writeProfile($name, $space, $class = 'prtr')
7685
{
77-
$path = sys_get_temp_dir() . '/mpdf-test-' . $name . '.icc';
86+
$path = $this->dir . '/mpdf-test-' . $name . '.icc';
7887

7988
$header = str_repeat("\0", 128);
8089
$header = substr_replace($header, pack('N', 0x02100000), 8, 4); // ICC version 2.1
@@ -1269,7 +1278,7 @@ public function testEncryptionIsRefused()
12691278
*/
12701279
public function testAnUntitledPdfxDocumentIsRefused(array $pdfx)
12711280
{
1272-
$file = sys_get_temp_dir() . '/mpdf-test-untitled.pdf';
1281+
$file = $this->dir . '/mpdf-test-untitled.pdf';
12731282

12741283
$mpdf = $this->untitled($pdfx + ['PDFXauto' => false]);
12751284
$mpdf->WriteHTML('<p>Text</p>');
@@ -1311,7 +1320,7 @@ public function pdfxVersions()
13111320
*/
13121321
public function testAnUntitledPdfxDocumentIsTitledAfterItsFile()
13131322
{
1314-
$file = sys_get_temp_dir() . '/Quarterly Report.pdf';
1323+
$file = $this->dir . '/Quarterly Report.pdf';
13151324

13161325
$mpdf = $this->untitled(['PDFX' => true]);
13171326
$mpdf->WriteHTML('<p>Text</p>');
@@ -1379,7 +1388,7 @@ public function testAMissingTitleIsWarnedOfOnce()
13791388
*/
13801389
public function testASetTitleIsKept()
13811390
{
1382-
$file = sys_get_temp_dir() . '/mpdf-test-titled.pdf';
1391+
$file = $this->dir . '/mpdf-test-titled.pdf';
13831392

13841393
$mpdf = $this->untitled(['PDFX' => true]);
13851394
$mpdf->SetTitle('Annual Accounts');
@@ -1398,7 +1407,7 @@ public function testASetTitleIsKept()
13981407
*/
13991408
public function testANonPdfxDocumentIsNotTitled()
14001409
{
1401-
$file = sys_get_temp_dir() . '/mpdf-test-plain.pdf';
1410+
$file = $this->dir . '/mpdf-test-plain.pdf';
14021411

14031412
$mpdf = $this->untitled([]);
14041413
$mpdf->WriteHTML('<p>Text</p>');

0 commit comments

Comments
 (0)