Skip to content

Commit d7073f1

Browse files
test: migrate to PHPUnit 9 (#532)
Co-authored-by: Christopher Georg <christopher.georg@sr-travel.de>
1 parent eadcbb4 commit d7073f1

3 files changed

Lines changed: 6 additions & 27 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"psr/log": "^2.0||^3.0"
2222
},
2323
"require-dev": {
24-
"phpunit/phpunit": "^8.5",
24+
"phpunit/phpunit": "^9.6.29",
2525
"phpstan/phpstan": "^1.0.0",
2626
"phpstan/phpstan-phpunit": "^1.0.0",
2727
"friendsofphp/php-cs-fixer": "^3.0",

tests/Knp/Snappy/AbstractGeneratorTest.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public function testAddOption(): void
2020
$this->assertEquals([], $media->getOptions());
2121

2222
$r = new ReflectionMethod($media, 'addOption');
23-
$r->setAccessible(true);
2423
$r->invokeArgs($media, ['foo', 'bar']);
2524

2625
$this->assertEquals(['foo' => 'bar'], $media->getOptions(), '->addOption() adds an option');
@@ -54,7 +53,6 @@ public function testAddOptions(): void
5453
$this->assertEquals([], $media->getOptions());
5554

5655
$r = new ReflectionMethod($media, 'addOptions');
57-
$r->setAccessible(true);
5856
$r->invokeArgs($media, [['foo' => 'bar', 'baz' => 'bat']]);
5957

6058
$this->assertEquals(
@@ -106,7 +104,6 @@ public function testSetOption(): void
106104
$logger->expects($this->once())->method('debug');
107105

108106
$r = new ReflectionMethod($media, 'addOption');
109-
$r->setAccessible(true);
110107
$r->invokeArgs($media, ['foo', 'bar']);
111108

112109
$media->setOption('foo', 'abc');
@@ -145,7 +142,6 @@ public function testSetOptions(): void
145142
$logger->expects($this->exactly(4))->method('debug');
146143

147144
$r = new ReflectionMethod($media, 'addOptions');
148-
$r->setAccessible(true);
149145
$r->invokeArgs($media, [['foo' => 'bar', 'baz' => 'bat']]);
150146

151147
$media->setOptions(['foo' => 'abc', 'baz' => 'def']);
@@ -506,11 +502,9 @@ public function testMergeOptions(): void
506502
$originalOptions = ['foo' => 'bar', 'baz' => 'bat'];
507503

508504
$addOptions = new ReflectionMethod($media, 'addOptions');
509-
$addOptions->setAccessible(true);
510505
$addOptions->invokeArgs($media, [$originalOptions]);
511506

512507
$r = new ReflectionMethod($media, 'mergeOptions');
513-
$r->setAccessible(true);
514508

515509
$mergedOptions = $r->invokeArgs($media, [['foo' => 'ban']]);
516510

@@ -559,7 +553,6 @@ public function testBuildCommand(string $binary, string $url, string $path, arra
559553
$media = $this->getMockForAbstractClass(AbstractGenerator::class, [], '', false);
560554

561555
$r = new ReflectionMethod($media, 'buildCommand');
562-
$r->setAccessible(true);
563556

564557
$this->assertEquals($expected, $r->invokeArgs($media, [$binary, $url, $path, $options]));
565558
}
@@ -656,7 +649,6 @@ public function testCheckOutput(): void
656649
;
657650

658651
$r = new ReflectionMethod($media, 'checkOutput');
659-
$r->setAccessible(true);
660652

661653
$message = '->checkOutput() checks both file existence and size';
662654

@@ -687,7 +679,6 @@ public function testCheckOutputWhenTheFileDoesNotExist(): void
687679
;
688680

689681
$r = new ReflectionMethod($media, 'checkOutput');
690-
$r->setAccessible(true);
691682

692683
$message = '->checkOutput() throws an InvalidArgumentException when the file does not exist';
693684

@@ -725,7 +716,6 @@ public function testCheckOutputWhenTheFileIsEmpty(): void
725716
;
726717

727718
$r = new ReflectionMethod($media, 'checkOutput');
728-
$r->setAccessible(true);
729719

730720
$message = '->checkOutput() throws an InvalidArgumentException when the file is empty';
731721

@@ -746,7 +736,6 @@ public function testCheckProcessStatus(): void
746736
;
747737

748738
$r = new ReflectionMethod($media, 'checkProcessStatus');
749-
$r->setAccessible(true);
750739

751740
try {
752741
$r->invokeArgs($media, [0, '', '', 'the command']);
@@ -778,7 +767,6 @@ public function testIsAssociativeArray(array $array, bool $isAssociativeArray):
778767
$generator = $this->getMockForAbstractClass(AbstractGenerator::class, [], '', false);
779768

780769
$r = new ReflectionMethod($generator, 'isAssociativeArray');
781-
$r->setAccessible(true);
782770
$this->assertEquals($isAssociativeArray, $r->invokeArgs($generator, [$array]));
783771
}
784772

@@ -807,7 +795,6 @@ public function testItThrowsTheProperExceptionWhenFileExistsAndNotOverwritting()
807795
->will($this->returnValue(true))
808796
;
809797
$r = new ReflectionMethod($media, 'prepareOutput');
810-
$r->setAccessible(true);
811798

812799
$r->invokeArgs($media, ['', false]);
813800
}
@@ -867,15 +854,12 @@ public function testCleanupEmptyTemporaryFiles(): void
867854
;
868855

869856
$create = new ReflectionMethod($generator, 'createTemporaryFile');
870-
$create->setAccessible(true);
871857
$create->invoke($generator, null, null);
872858

873859
$files = new ReflectionProperty($generator, 'temporaryFiles');
874-
$files->setAccessible(true);
875860
$this->assertCount(1, $files->getValue($generator));
876861

877862
$remove = new ReflectionMethod($generator, 'removeTemporaryFiles');
878-
$remove->setAccessible(true);
879863
$remove->invoke($generator);
880864
}
881865

@@ -896,15 +880,12 @@ public function testleanupTemporaryFiles(): void
896880
;
897881

898882
$create = new ReflectionMethod($generator, 'createTemporaryFile');
899-
$create->setAccessible(true);
900883
$create->invoke($generator, '<html/>', 'html');
901884

902885
$files = new ReflectionProperty($generator, 'temporaryFiles');
903-
$files->setAccessible(true);
904886
$this->assertCount(1, $files->getValue($generator));
905887

906888
$remove = new ReflectionMethod($generator, 'removeTemporaryFiles');
907-
$remove->setAccessible(true);
908889
$remove->invoke($generator);
909890
}
910891

tests/Knp/Snappy/PdfTest.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function testThatSomethingUsingTmpFolder(): void
5757
$testObject->setTemporaryFolder(__DIR__);
5858

5959
$testObject->getOutputFromHtml('<html></html>', ['footer-html' => 'footer']);
60-
$this->assertRegExp('/emptyBinary --lowquality --footer-html ' . $q . '.*' . $q . ' ' . $q . '.*' . $q . ' ' . $q . '.*' . $q . '/', $testObject->getLastCommand());
60+
$this->assertMatchesRegularExpression('/emptyBinary --lowquality --footer-html ' . $q . '.*' . $q . ' ' . $q . '.*' . $q . ' ' . $q . '.*' . $q . '/', $testObject->getLastCommand());
6161
}
6262

6363
public function testThatSomethingUsingNonexistentTmpFolder(): void
@@ -76,14 +76,13 @@ public function testRemovesLocalFilesOnError(): void
7676
{
7777
$pdf = new PdfSpy();
7878
$method = new ReflectionMethod($pdf, 'createTemporaryFile');
79-
$method->setAccessible(true);
8079
$method->invoke($pdf, 'test', $pdf->getDefaultExtension());
8180
$this->assertEquals(1, \count($pdf->temporaryFiles));
8281
$this->expectException(RuntimeException::class);
8382

8483
throw new RuntimeException('test error.');
8584
// @phpstan-ignore-next-line See https://github.com/phpstan/phpstan/issues/7799
86-
$this->assertFileNotExists(\reset($pdf->temporaryFiles));
85+
$this->assertFileDoesNotExist(\reset($pdf->temporaryFiles));
8786
}
8887

8988
/**
@@ -93,7 +92,7 @@ public function testOptions(array $options, string $expectedRegex): void
9392
{
9493
$testObject = new PdfSpy();
9594
$testObject->getOutputFromHtml('<html></html>', $options);
96-
$this->assertRegExp($expectedRegex, $testObject->getLastCommand());
95+
$this->assertMatchesRegularExpression($expectedRegex, $testObject->getLastCommand());
9796
}
9897

9998
public function dataOptions(): array
@@ -142,12 +141,11 @@ public function testRemovesLocalFilesOnDestruct(): void
142141
{
143142
$pdf = new PdfSpy();
144143
$method = new ReflectionMethod($pdf, 'createTemporaryFile');
145-
$method->setAccessible(true);
146144
$method->invoke($pdf, 'test', $pdf->getDefaultExtension());
147-
$this->assertEquals(1, \count($pdf->temporaryFiles));
145+
$this->assertCount(1, $pdf->temporaryFiles);
148146
$this->assertFileExists(\reset($pdf->temporaryFiles));
149147
$pdf->__destruct();
150-
$this->assertFileNotExists(\reset($pdf->temporaryFiles));
148+
$this->assertFileDoesNotExist(\reset($pdf->temporaryFiles));
151149
}
152150
}
153151

0 commit comments

Comments
 (0)