Skip to content

Commit 999b8a7

Browse files
committed
add assertClassHasAttribute() to PropertyExistsWithoutAssertRector
1 parent ba04936 commit 999b8a7

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Rector\PHPUnit\Tests\PHPUnit100\Rector\MethodCall\PropertyExistsWithoutAssertRector\Fixture;
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
final class AssertHasAttribute extends TestCase
8+
{
9+
public function test()
10+
{
11+
$this->assertClassHasAttribute('property', 'stdClass');
12+
}
13+
}
14+
15+
?>
16+
-----
17+
<?php
18+
19+
namespace Rector\PHPUnit\Tests\PHPUnit100\Rector\MethodCall\PropertyExistsWithoutAssertRector\Fixture;
20+
21+
use PHPUnit\Framework\TestCase;
22+
23+
final class AssertHasAttribute extends TestCase
24+
{
25+
public function test()
26+
{
27+
$this->assertTrue(property_exists('stdClass', 'property'));
28+
}
29+
}
30+
31+
?>

rules/PHPUnit100/Rector/MethodCall/PropertyExistsWithoutAssertRector.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ final class PropertyExistsWithoutAssertRector extends AbstractRector
2727
* @var array<string, string>
2828
*/
2929
private const RENAME_METHODS_WITH_OBJECT_MAP = [
30+
'assertClassHasAttribute' => 'assertTrue',
3031
'assertClassHasStaticAttribute' => 'assertTrue',
3132
'classHasStaticAttribute' => 'assertTrue',
3233
'assertClassNotHasStaticAttribute' => 'assertFalse',
34+
'assertClassNotHasAttribute' => 'assertFalse',
3335
];
3436

3537
public function __construct(
@@ -41,7 +43,7 @@ public function __construct(
4143
public function getRuleDefinition(): RuleDefinition
4244
{
4345
return new RuleDefinition(
44-
'Replace deleted PHPUnit methods: assertClassHasStaticAttribute, classHasStaticAttribute and assertClassNotHasStaticAttribute by property_exists()',
46+
'Replace removed assertClassHasStaticAttribute, classHasStaticAttribute and assertClassNotHasStaticAttribute with property_exists()',
4547
[
4648
new CodeSample(
4749
<<<'CODE_SAMPLE'

0 commit comments

Comments
 (0)