Skip to content

Commit 56d5cb0

Browse files
authored
Register PropertyExistsWithoutAssertRector in the composer-based set (#761)
1 parent 4050e43 commit 56d5cb0

4 files changed

Lines changed: 23 additions & 33 deletions

File tree

config/sets/composer-based.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Rector\PHPUnit\PHPUnit100\Rector\Class_\ParentTestClassConstructorRector;
2424
use Rector\PHPUnit\PHPUnit100\Rector\Class_\PublicDataProviderClassMethodRector;
2525
use Rector\PHPUnit\PHPUnit100\Rector\Class_\StaticDataProviderClassMethodRector;
26+
use Rector\PHPUnit\PHPUnit100\Rector\MethodCall\PropertyExistsWithoutAssertRector;
2627
use Rector\PHPUnit\PHPUnit100\Rector\MethodCall\RemoveSetMethodsMethodCallRector;
2728
use Rector\PHPUnit\PHPUnit100\Rector\StmtsAwareInterface\WithConsecutiveRector;
2829
use Rector\PHPUnit\PHPUnit110\Rector\CallLike\AssertContainsOnlyMethodCallRector;
@@ -148,6 +149,7 @@
148149
AddProphecyTraitRector::class,
149150
WithConsecutiveRector::class,
150151
RemoveSetMethodsMethodCallRector::class,
152+
PropertyExistsWithoutAssertRector::class,
151153
ParentTestClassConstructorRector::class,
152154

153155
// PHPUnit 11.0

rules-tests/PHPUnit100/Rector/MethodCall/PropertyExistsWithoutAssertRector/Fixture/assert_object_has_attribute.php.inc

Lines changed: 0 additions & 31 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Rector\PHPUnit\Tests\PHPUnit100\Rector\MethodCall\PropertyExistsWithoutAssertRector\Fixture;
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
final class SkipAssertObjectHasAttribute extends TestCase
8+
{
9+
public function test(object $someObject)
10+
{
11+
// has a direct replacement in assertObjectHasProperty(), renamed by the composer-based set
12+
$this->assertObjectHasAttribute('property', $someObject);
13+
$this->assertObjectNotHasAttribute('property', $someObject);
14+
}
15+
}
16+
17+
?>

rules/PHPUnit100/Rector/MethodCall/PropertyExistsWithoutAssertRector.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,18 @@ public function provideComposerPackageConstraint(): ComposerPackageConstraint
3434
}
3535

3636
/**
37+
* The assertObjectHasAttribute() and assertObjectNotHasAttribute() methods are left out on purpose,
38+
* as they have a direct replacement in assertObjectHasProperty() and assertObjectNotHasProperty().
39+
* Those renames are handled by RenameMethodRector in the composer-based set.
40+
*
3741
* @var array<string, string>
3842
*/
3943
private const array RENAME_METHODS_WITH_OBJECT_MAP = [
4044
'assertClassHasAttribute' => 'assertTrue',
41-
'assertObjectHasAttribute' => 'assertTrue',
4245
'assertClassHasStaticAttribute' => 'assertTrue',
4346
// false
4447
'assertClassNotHasStaticAttribute' => 'assertFalse',
4548
'assertClassNotHasAttribute' => 'assertFalse',
46-
'assertObjectNotHasAttribute' => 'assertFalse',
4749
// no assert
4850
'objectHasAttribute' => 'assertTrue',
4951
'classHasAttribute' => 'assertTrue',

0 commit comments

Comments
 (0)