Skip to content

Commit ed5accf

Browse files
committed
fix tests
1 parent fb15789 commit ed5accf

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

phpunit.xml.dist

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,4 @@
88
<directory>tests/Unit</directory>
99
</testsuite>
1010
</testsuites>
11-
<logging>
12-
<junit outputFile="build/report.junit.xml"/>
13-
</logging>
1411
</phpunit>

tests/Integration/MatchesSnapshotTest.php

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PHPUnit\Framework\ExpectationFailedException;
88
use PHPUnit\Framework\MockObject\MockObject;
99
use PHPUnit\Framework\TestCase;
10+
use ReflectionClass;
1011
use Spatie\Snapshots\MatchesSnapshots;
1112

1213
class MatchesSnapshotTest extends TestCase
@@ -462,30 +463,46 @@ private function expectFailedMatchesSnapshotTest()
462463
$this->expectException(ExpectationFailedException::class);
463464
}
464465

465-
/**
466-
* @return \PHPUnit\Framework\MockObject\MockObject|\Spatie\Snapshots\MatchesSnapshots
467-
*/
468466
private function getMatchesSnapshotMock(bool $mockGetSnapshotId = true): MockObject
469467
{
470-
$mockMethods = [
468+
// Define a class name for our temporary trait user
469+
$className = 'TemporaryTraitClass' . md5(microtime());
470+
471+
// Create the class definition with the methods we need to mock
472+
$classDefinition = 'class ' . $className . ' {
473+
use \\Spatie\\Snapshots\\MatchesSnapshots;
474+
475+
public function markTestIncomplete($message = "") {}
476+
public function getSnapshotId() { return ""; }
477+
public function getSnapshotDirectory() { return ""; }
478+
public function getFileSnapshotDirectory() { return ""; }
479+
public function fail($message = "") {}
480+
public function assertTrue($condition, $message = "") {}
481+
}';
482+
483+
// Evaluate the class definition
484+
eval($classDefinition);
485+
486+
// Create the mock builder
487+
$mockBuilder = $this->getMockBuilder($className);
488+
489+
// Disable original constructor to avoid issues
490+
$mockBuilder->disableOriginalConstructor();
491+
492+
// For PHPUnit 9.x, use onlyMethods instead of setMethods
493+
$mockBuilder->onlyMethods([
471494
'markTestIncomplete',
472495
'getSnapshotId',
473496
'getSnapshotDirectory',
474497
'getFileSnapshotDirectory',
475498
'fail',
476499
'assertTrue',
477-
];
478-
479-
$matchesSnapshotMock = $this->getMockForTrait(
480-
MatchesSnapshots::class,
481-
[],
482-
'',
483-
true,
484-
true,
485-
true,
486-
$mockMethods
487-
);
500+
]);
501+
502+
// Get the mock object
503+
$matchesSnapshotMock = $mockBuilder->getMock();
488504

505+
// Configure expected method calls
489506
if ($mockGetSnapshotId) {
490507
$matchesSnapshotMock
491508
->expects($this->any())

0 commit comments

Comments
 (0)