Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Rector\PHPUnit\Tests\PHPUnit100\Rector\MethodCall\PropertyExistsWithoutAssertRector\Fixture;

use PHPUnit\Framework\TestCase;

final class AssertHasAttribute extends TestCase
{
public function test()
{
$this->assertClassHasAttribute('property', 'stdClass');
}
}

?>
-----
<?php

namespace Rector\PHPUnit\Tests\PHPUnit100\Rector\MethodCall\PropertyExistsWithoutAssertRector\Fixture;

use PHPUnit\Framework\TestCase;

final class AssertHasAttribute extends TestCase
{
public function test()
{
$this->assertTrue(property_exists('stdClass', 'property'));
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Rector\PHPUnit\Tests\PHPUnit100\Rector\MethodCall\PropertyExistsWithoutAssertRector\Fixture;

use PHPUnit\Framework\TestCase;

final class AssertObjectHasAttribute extends TestCase
{
public function test(object $someObject)
{
$this->assertObjectHasAttribute('property', $someObject);
}
}

?>
-----
<?php

namespace Rector\PHPUnit\Tests\PHPUnit100\Rector\MethodCall\PropertyExistsWithoutAssertRector\Fixture;

use PHPUnit\Framework\TestCase;

final class AssertObjectHasAttribute extends TestCase
{
public function test(object $someObject)
{
$this->assertTrue(property_exists($someObject, 'property'));
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,17 @@ final class PropertyExistsWithoutAssertRector extends AbstractRector
* @var array<string, string>
*/
private const RENAME_METHODS_WITH_OBJECT_MAP = [
'assertClassHasAttribute' => 'assertTrue',
'assertObjectHasAttribute' => 'assertTrue',
'assertClassHasStaticAttribute' => 'assertTrue',
'classHasStaticAttribute' => 'assertTrue',
// false
'assertClassNotHasStaticAttribute' => 'assertFalse',
'assertClassNotHasAttribute' => 'assertFalse',
'assertObjectNotHasAttribute' => 'assertFalse',
// no assert
'objectHasAttribute' => 'assertTrue',
'classHasAttribute' => 'assertTrue',
'classHasStaticAttribute' => 'assertTrue',
];

public function __construct(
Expand All @@ -41,19 +49,17 @@ public function __construct(
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
'Replace deleted PHPUnit methods: assertClassHasStaticAttribute, classHasStaticAttribute and assertClassNotHasStaticAttribute by property_exists()',
'Replace removed assertClassHas*Attribute() with property_exists()',
[
new CodeSample(
<<<'CODE_SAMPLE'
$this->assertClassHasAttribute("Class", "property");
$this->assertClassHasStaticAttribute("Class", "property");
$this->classHasStaticAttribute("Class", "property");
$this->assertClassNotHasStaticAttribute("Class", "property");
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
$this->assertTrue(property_exists("Class", "property"));
$this->assertTrue(property_exists("Class", "property"));
$this->assertFalse(property_exists("Class", "property"));
CODE_SAMPLE
),
]
Expand Down