Skip to content

Commit fd1ceee

Browse files
committed
RuleInclusionTest: work round removal of assertObjectHasAttribute()
The `assertObjectHasAttribute()` method was deprecated in PHPUnit 9.6.x and removed in PHPUnit 10.0.0 without replacement. Note: PHPUnit 10.1.0 adds the assertion back again, but under a different name `assertObjectHasProperty()`. While only a deprecation warning is shown on PHPUnit 9.6.x and the tests will still pass, I'm electing to replace the assertion anyway with code which emulates what PHPUnit would assert.
1 parent fc6dce5 commit fd1ceee

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

tests/Core/Ruleset/RuleInclusionTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use PHP_CodeSniffer\Config;
1313
use PHP_CodeSniffer\Ruleset;
1414
use PHPUnit\Framework\TestCase;
15+
use ReflectionObject;
1516

1617
class RuleInclusionTest extends TestCase
1718
{
@@ -222,7 +223,10 @@ public function dataRegisteredSniffCodes()
222223
public function testSettingProperties($sniffClass, $propertyName, $expectedValue)
223224
{
224225
$this->assertArrayHasKey($sniffClass, self::$ruleset->sniffs);
225-
$this->assertObjectHasAttribute($propertyName, self::$ruleset->sniffs[$sniffClass]);
226+
227+
$hasProperty = (new ReflectionObject(self::$ruleset->sniffs[$sniffClass]))->hasProperty($propertyName);
228+
$errorMsg = sprintf('Property %s does not exist on sniff class %s', $propertyName, $sniffClass);
229+
$this->assertTrue($hasProperty, $errorMsg);
226230

227231
$actualValue = self::$ruleset->sniffs[$sniffClass]->$propertyName;
228232
$this->assertSame($expectedValue, $actualValue);

0 commit comments

Comments
 (0)