Skip to content

Commit 7fd8056

Browse files
committed
add assertObjectHasAttribute() support to PropertyExistsWithoutAssertRector
1 parent 97e14f0 commit 7fd8056

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-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 AssertObjectHasAttribute extends TestCase
8+
{
9+
public function test(object $someObject)
10+
{
11+
$this->assertObjectHasAttribute('property', $someObject);
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 AssertObjectHasAttribute extends TestCase
24+
{
25+
public function test(object $someObject)
26+
{
27+
$this->assertTrue(property_exists($someObject, 'property'));
28+
}
29+
}
30+
31+
?>

rules/PHPUnit100/Rector/MethodCall/PropertyExistsWithoutAssertRector.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,16 @@ final class PropertyExistsWithoutAssertRector extends AbstractRector
2828
*/
2929
private const RENAME_METHODS_WITH_OBJECT_MAP = [
3030
'assertClassHasAttribute' => 'assertTrue',
31+
'assertObjectHasAttribute' => 'assertTrue',
3132
'assertClassHasStaticAttribute' => 'assertTrue',
32-
'classHasStaticAttribute' => 'assertTrue',
33+
// false
3334
'assertClassNotHasStaticAttribute' => 'assertFalse',
3435
'assertClassNotHasAttribute' => 'assertFalse',
36+
'assertObjectNotHasAttribute' => 'assertFalse',
37+
// no assert
38+
'objectHasAttribute' => 'assertTrue',
39+
'classHasAttribute' => 'assertTrue',
40+
'classHasStaticAttribute' => 'assertTrue',
3541
];
3642

3743
public function __construct(

0 commit comments

Comments
 (0)