Skip to content

Commit c7f6a80

Browse files
committed
Start to Eliminate Most Tests in Separate Processes
Writer/Html/FontTest was already bad, testing for the wrong default font values because a prior test had overlaid those; a full unit test would succeed, but just testing the Writer/Html directory would not. Better test planning eliminates that possibility, without the need to resort to resource-intensive separate processes.
1 parent 9ee3349 commit c7f6a80

File tree

15 files changed

+93
-312
lines changed

15 files changed

+93
-312
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,61 +1275,6 @@ parameters:
12751275
count: 2
12761276
path: tests/PhpWordTests/Reader/Word2007/StyleTest.php
12771277

1278-
-
1279-
message: "#^Parameter \\#2 \\$libraryBaseDir of static method PhpOffice\\\\PhpWord\\\\Settings\\:\\:setPdfRenderer\\(\\) expects string, string\\|false given\\.$#"
1280-
count: 1
1281-
path: tests/PhpWordTests/SettingsTest.php
1282-
1283-
-
1284-
message: "#^Property PhpOffice\\\\PhpWordTests\\\\SettingsTest\\:\\:\\$compatibility has no type specified\\.$#"
1285-
count: 1
1286-
path: tests/PhpWordTests/SettingsTest.php
1287-
1288-
-
1289-
message: "#^Property PhpOffice\\\\PhpWordTests\\\\SettingsTest\\:\\:\\$defaultFontName has no type specified\\.$#"
1290-
count: 1
1291-
path: tests/PhpWordTests/SettingsTest.php
1292-
1293-
-
1294-
message: "#^Property PhpOffice\\\\PhpWordTests\\\\SettingsTest\\:\\:\\$defaultFontSize has no type specified\\.$#"
1295-
count: 1
1296-
path: tests/PhpWordTests/SettingsTest.php
1297-
1298-
-
1299-
message: "#^Property PhpOffice\\\\PhpWordTests\\\\SettingsTest\\:\\:\\$defaultPaper has no type specified\\.$#"
1300-
count: 1
1301-
path: tests/PhpWordTests/SettingsTest.php
1302-
1303-
-
1304-
message: "#^Property PhpOffice\\\\PhpWordTests\\\\SettingsTest\\:\\:\\$measurementUnit has no type specified\\.$#"
1305-
count: 1
1306-
path: tests/PhpWordTests/SettingsTest.php
1307-
1308-
-
1309-
message: "#^Property PhpOffice\\\\PhpWordTests\\\\SettingsTest\\:\\:\\$outputEscapingEnabled has no type specified\\.$#"
1310-
count: 1
1311-
path: tests/PhpWordTests/SettingsTest.php
1312-
1313-
-
1314-
message: "#^Property PhpOffice\\\\PhpWordTests\\\\SettingsTest\\:\\:\\$pdfRendererName has no type specified\\.$#"
1315-
count: 1
1316-
path: tests/PhpWordTests/SettingsTest.php
1317-
1318-
-
1319-
message: "#^Property PhpOffice\\\\PhpWordTests\\\\SettingsTest\\:\\:\\$pdfRendererPath has no type specified\\.$#"
1320-
count: 1
1321-
path: tests/PhpWordTests/SettingsTest.php
1322-
1323-
-
1324-
message: "#^Property PhpOffice\\\\PhpWordTests\\\\SettingsTest\\:\\:\\$tempDir has no type specified\\.$#"
1325-
count: 1
1326-
path: tests/PhpWordTests/SettingsTest.php
1327-
1328-
-
1329-
message: "#^Property PhpOffice\\\\PhpWordTests\\\\SettingsTest\\:\\:\\$zipClass has no type specified\\.$#"
1330-
count: 1
1331-
path: tests/PhpWordTests/SettingsTest.php
1332-
13331278
-
13341279
message: "#^Cannot call method getStyleName\\(\\) on PhpOffice\\\\PhpWord\\\\Style\\\\Table\\|string\\.$#"
13351280
count: 1

phpstan-baseline.php7.neon

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,61 +1250,6 @@ parameters:
12501250
count: 2
12511251
path: tests/PhpWordTests/Reader/Word2007/StyleTest.php
12521252

1253-
-
1254-
message: "#^Parameter \\#2 \\$libraryBaseDir of static method PhpOffice\\\\PhpWord\\\\Settings\\:\\:setPdfRenderer\\(\\) expects string, string\\|false given\\.$#"
1255-
count: 1
1256-
path: tests/PhpWordTests/SettingsTest.php
1257-
1258-
-
1259-
message: "#^Property PhpOffice\\\\PhpWordTests\\\\SettingsTest\\:\\:\\$compatibility has no type specified\\.$#"
1260-
count: 1
1261-
path: tests/PhpWordTests/SettingsTest.php
1262-
1263-
-
1264-
message: "#^Property PhpOffice\\\\PhpWordTests\\\\SettingsTest\\:\\:\\$defaultFontName has no type specified\\.$#"
1265-
count: 1
1266-
path: tests/PhpWordTests/SettingsTest.php
1267-
1268-
-
1269-
message: "#^Property PhpOffice\\\\PhpWordTests\\\\SettingsTest\\:\\:\\$defaultFontSize has no type specified\\.$#"
1270-
count: 1
1271-
path: tests/PhpWordTests/SettingsTest.php
1272-
1273-
-
1274-
message: "#^Property PhpOffice\\\\PhpWordTests\\\\SettingsTest\\:\\:\\$defaultPaper has no type specified\\.$#"
1275-
count: 1
1276-
path: tests/PhpWordTests/SettingsTest.php
1277-
1278-
-
1279-
message: "#^Property PhpOffice\\\\PhpWordTests\\\\SettingsTest\\:\\:\\$measurementUnit has no type specified\\.$#"
1280-
count: 1
1281-
path: tests/PhpWordTests/SettingsTest.php
1282-
1283-
-
1284-
message: "#^Property PhpOffice\\\\PhpWordTests\\\\SettingsTest\\:\\:\\$outputEscapingEnabled has no type specified\\.$#"
1285-
count: 1
1286-
path: tests/PhpWordTests/SettingsTest.php
1287-
1288-
-
1289-
message: "#^Property PhpOffice\\\\PhpWordTests\\\\SettingsTest\\:\\:\\$pdfRendererName has no type specified\\.$#"
1290-
count: 1
1291-
path: tests/PhpWordTests/SettingsTest.php
1292-
1293-
-
1294-
message: "#^Property PhpOffice\\\\PhpWordTests\\\\SettingsTest\\:\\:\\$pdfRendererPath has no type specified\\.$#"
1295-
count: 1
1296-
path: tests/PhpWordTests/SettingsTest.php
1297-
1298-
-
1299-
message: "#^Property PhpOffice\\\\PhpWordTests\\\\SettingsTest\\:\\:\\$tempDir has no type specified\\.$#"
1300-
count: 1
1301-
path: tests/PhpWordTests/SettingsTest.php
1302-
1303-
-
1304-
message: "#^Property PhpOffice\\\\PhpWordTests\\\\SettingsTest\\:\\:\\$zipClass has no type specified\\.$#"
1305-
count: 1
1306-
path: tests/PhpWordTests/SettingsTest.php
1307-
13081253
-
13091254
message: "#^Cannot call method getStyleName\\(\\) on PhpOffice\\\\PhpWord\\\\Style\\\\Table\\|string\\.$#"
13101255
count: 1

phpstan-baseline.php73.neon

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,61 +1250,6 @@ parameters:
12501250
count: 2
12511251
path: tests/PhpWordTests/Reader/Word2007/StyleTest.php
12521252

1253-
-
1254-
message: "#^Parameter \\#2 \\$libraryBaseDir of static method PhpOffice\\\\PhpWord\\\\Settings\\:\\:setPdfRenderer\\(\\) expects string, string\\|false given\\.$#"
1255-
count: 1
1256-
path: tests/PhpWordTests/SettingsTest.php
1257-
1258-
-
1259-
message: "#^Property PhpOffice\\\\PhpWordTests\\\\SettingsTest\\:\\:\\$compatibility has no type specified\\.$#"
1260-
count: 1
1261-
path: tests/PhpWordTests/SettingsTest.php
1262-
1263-
-
1264-
message: "#^Property PhpOffice\\\\PhpWordTests\\\\SettingsTest\\:\\:\\$defaultFontName has no type specified\\.$#"
1265-
count: 1
1266-
path: tests/PhpWordTests/SettingsTest.php
1267-
1268-
-
1269-
message: "#^Property PhpOffice\\\\PhpWordTests\\\\SettingsTest\\:\\:\\$defaultFontSize has no type specified\\.$#"
1270-
count: 1
1271-
path: tests/PhpWordTests/SettingsTest.php
1272-
1273-
-
1274-
message: "#^Property PhpOffice\\\\PhpWordTests\\\\SettingsTest\\:\\:\\$defaultPaper has no type specified\\.$#"
1275-
count: 1
1276-
path: tests/PhpWordTests/SettingsTest.php
1277-
1278-
-
1279-
message: "#^Property PhpOffice\\\\PhpWordTests\\\\SettingsTest\\:\\:\\$measurementUnit has no type specified\\.$#"
1280-
count: 1
1281-
path: tests/PhpWordTests/SettingsTest.php
1282-
1283-
-
1284-
message: "#^Property PhpOffice\\\\PhpWordTests\\\\SettingsTest\\:\\:\\$outputEscapingEnabled has no type specified\\.$#"
1285-
count: 1
1286-
path: tests/PhpWordTests/SettingsTest.php
1287-
1288-
-
1289-
message: "#^Property PhpOffice\\\\PhpWordTests\\\\SettingsTest\\:\\:\\$pdfRendererName has no type specified\\.$#"
1290-
count: 1
1291-
path: tests/PhpWordTests/SettingsTest.php
1292-
1293-
-
1294-
message: "#^Property PhpOffice\\\\PhpWordTests\\\\SettingsTest\\:\\:\\$pdfRendererPath has no type specified\\.$#"
1295-
count: 1
1296-
path: tests/PhpWordTests/SettingsTest.php
1297-
1298-
-
1299-
message: "#^Property PhpOffice\\\\PhpWordTests\\\\SettingsTest\\:\\:\\$tempDir has no type specified\\.$#"
1300-
count: 1
1301-
path: tests/PhpWordTests/SettingsTest.php
1302-
1303-
-
1304-
message: "#^Property PhpOffice\\\\PhpWordTests\\\\SettingsTest\\:\\:\\$zipClass has no type specified\\.$#"
1305-
count: 1
1306-
path: tests/PhpWordTests/SettingsTest.php
1307-
13081253
-
13091254
message: "#^Cannot call method getStyleName\\(\\) on PhpOffice\\\\PhpWord\\\\Style\\\\Table\\|string\\.$#"
13101255
count: 1

src/PhpWord/Settings.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,4 +529,21 @@ public static function setDefaultPaper(string $value): bool
529529

530530
return false;
531531
}
532+
533+
public static function restoreDefaults(): void
534+
{
535+
self::$defaultAsianFontName = self::DEFAULT_FONT_NAME;
536+
self::$defaultFontColor = self::DEFAULT_FONT_COLOR;
537+
self::$defaultFontName = self::DEFAULT_FONT_NAME;
538+
self::$defaultFontSize = self::DEFAULT_FONT_SIZE;
539+
self::$defaultPaper = self::DEFAULT_PAPER;
540+
self::$measurementUnit = self::UNIT_TWIP;
541+
self::$outputEscapingEnabled = false;
542+
self::$pdfRendererName = null;
543+
self::$pdfRendererOptions = [];
544+
self::$pdfRendererPath = null;
545+
self::$tempDir = '';
546+
self::$xmlWriterCompatibility = true;
547+
self::$zipClass = self::ZIPARCHIVE;
548+
}
532549
}

tests/PhpWordTests/PhpWordTest.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,23 @@
2727

2828
/**
2929
* Test class for PhpOffice\PhpWord\PhpWord.
30-
*
31-
* @runTestsInSeparateProcesses
3230
*/
3331
class PhpWordTest extends \PHPUnit\Framework\TestCase
3432
{
33+
/**
34+
* Executed after each method of the class.
35+
*/
36+
protected function tearDown(): void
37+
{
38+
Settings::restoreDefaults();
39+
}
40+
3541
/**
3642
* Test object creation.
3743
*/
3844
public function testConstruct(): void
3945
{
46+
Settings::restoreDefaults();
4047
do {
4148
$dtStart = new DateTimeImmutable();
4249
$startSecond = $dtStart->format('s');

tests/PhpWordTests/SettingsTest.php

Lines changed: 3 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -24,76 +24,20 @@
2424
* Test class for PhpOffice\PhpWord\Settings.
2525
*
2626
* @coversDefaultClass \PhpOffice\PhpWord\Settings
27-
*
28-
* @runTestsInSeparateProcesses
2927
*/
3028
class SettingsTest extends TestCase
3129
{
32-
private $compatibility;
33-
34-
/** @var string */
35-
private $defaultFontColor;
36-
37-
private $defaultFontSize;
38-
39-
private $defaultFontName;
40-
41-
private $defaultPaper;
42-
43-
private $measurementUnit;
44-
45-
private $outputEscapingEnabled;
46-
47-
private $pdfRendererName;
48-
49-
/**
50-
* @var array
51-
*/
52-
private $pdfRendererOptions;
53-
54-
private $pdfRendererPath;
55-
56-
private $tempDir;
57-
58-
private $zipClass;
59-
60-
protected function setUp(): void
61-
{
62-
$this->compatibility = Settings::hasCompatibility();
63-
$this->defaultFontColor = Settings::getDefaultFontColor();
64-
$this->defaultFontSize = Settings::getDefaultFontSize();
65-
$this->defaultFontName = Settings::getDefaultFontName();
66-
$this->defaultPaper = Settings::getDefaultPaper();
67-
$this->measurementUnit = Settings::getMeasurementUnit();
68-
$this->outputEscapingEnabled = Settings::isOutputEscapingEnabled();
69-
$this->pdfRendererName = Settings::getPdfRendererName();
70-
$this->pdfRendererOptions = Settings::getPdfRendererOptions();
71-
$this->pdfRendererPath = Settings::getPdfRendererPath();
72-
$this->tempDir = Settings::getTempDir();
73-
$this->zipClass = Settings::getZipClass();
74-
}
75-
7630
protected function tearDown(): void
7731
{
78-
Settings::setCompatibility($this->compatibility);
79-
Settings::setDefaultFontColor($this->defaultFontColor);
80-
Settings::setDefaultFontSize($this->defaultFontSize);
81-
Settings::setDefaultFontName($this->defaultFontName);
82-
Settings::setDefaultPaper($this->defaultPaper);
83-
Settings::setMeasurementUnit($this->measurementUnit);
84-
Settings::setOutputEscapingEnabled($this->outputEscapingEnabled);
85-
Settings::setPdfRendererName($this->pdfRendererName);
86-
Settings::setPdfRendererOptions($this->pdfRendererOptions);
87-
Settings::setPdfRendererPath($this->pdfRendererPath);
88-
Settings::setTempDir($this->tempDir);
89-
Settings::setZipClass($this->zipClass);
32+
Settings::restoreDefaults();
9033
}
9134

9235
/**
9336
* Test set/get compatibity option.
9437
*/
9538
public function testSetGetCompatibility(): void
9639
{
40+
Settings::restoreDefaults();
9741
self::assertTrue(Settings::hasCompatibility());
9842
self::assertTrue(Settings::setCompatibility(false));
9943
self::assertFalse(Settings::hasCompatibility());
@@ -129,6 +73,7 @@ public function testSetGetZipClass(): void
12973
public function testSetGetPdfRenderer(): void
13074
{
13175
$domPdfPath = realpath(PHPWORD_TESTS_BASE_DIR . '/../vendor/dompdf/dompdf');
76+
self::assertNotFalse($domPdfPath);
13277

13378
self::assertFalse(Settings::setPdfRenderer('FOO', 'dummy/path'));
13479
self::assertTrue(Settings::setPdfRenderer(Settings::PDF_RENDERER_DOMPDF, $domPdfPath));

tests/PhpWordTests/WriteReadback/Word2007Test.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,25 @@
2121
use PhpOffice\PhpWord\Element\TextRun;
2222
use PhpOffice\PhpWord\IOFactory;
2323
use PhpOffice\PhpWord\PhpWord;
24+
use PhpOffice\PhpWord\Settings;
2425
use PhpOffice\PhpWord\Style\Font;
2526
use PhpOffice\PhpWord\Writer\Word2007;
2627

2728
/**
2829
* Test class for PhpOffice\PhpWord\Reader\Word2007 and PhpOffice\PhpWord\Writer\Word2007.
2930
*
3031
* @coversDefaultClass \PhpOffice\PhpWord\Reader\Word2007
31-
*
32-
* @runTestsInSeparateProcesses
3332
*/
3433
class Word2007Test extends \PHPUnit\Framework\TestCase
3534
{
35+
/**
36+
* Executed after each method of the class.
37+
*/
38+
protected function tearDown(): void
39+
{
40+
Settings::restoreDefaults();
41+
}
42+
3643
/**
3744
* Test default font name.
3845
*/

0 commit comments

Comments
 (0)