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,37 @@
<?php

namespace Rector\PHPUnit\Tests\AnnotationsToAttributes\Rector\ClassMethod\TestWithAnnotationToAttributeRector\Fixture;

use PHPUnit\Framework\TestCase;

final class SomeFixtureWithTestAttribute extends TestCase
{
/**
* @testWith ["foo"]
* ["bar"]
*/
#[\PHPUnit\Framework\Attributes\Test]
public function shouldDoSomething(): void
{
}
}

?>
-----
<?php

namespace Rector\PHPUnit\Tests\AnnotationsToAttributes\Rector\ClassMethod\TestWithAnnotationToAttributeRector\Fixture;

use PHPUnit\Framework\TestCase;

final class SomeFixtureWithTestAttribute extends TestCase
{
#[\PHPUnit\Framework\Attributes\Test]
#[\PHPUnit\Framework\Attributes\TestWith(['foo'])]
#[\PHPUnit\Framework\Attributes\TestWith(['bar'])]
public function shouldDoSomething(): void
{
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Rector\PHPUnit\Tests\PHPUnit60\Rector\ClassMethod\AddDoesNotPerformAssertionToNonAssertingTestRector\Fixture;

class TestInAnnotatoin extends \PHPUnit\Framework\TestCase
class TestInAnnotation extends \PHPUnit\Framework\TestCase
{
/**
* @test
Expand All @@ -19,7 +19,7 @@ class TestInAnnotatoin extends \PHPUnit\Framework\TestCase

namespace Rector\PHPUnit\Tests\PHPUnit60\Rector\ClassMethod\AddDoesNotPerformAssertionToNonAssertingTestRector\Fixture;

class TestInAnnotatoin extends \PHPUnit\Framework\TestCase
class TestInAnnotation extends \PHPUnit\Framework\TestCase
{
/**
* @test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Rector\PHPUnit\Tests\PHPUnit60\Rector\ClassMethod\AddDoesNotPerformAssertionToNonAssertingTestRector\Fixture;

class TestInAnnotationWithTestAttribute extends \PHPUnit\Framework\TestCase
{
#[\PHPUnit\Framework\Attributes\Test]
public function thisIsTest()
{
$nothing = 5;
}
}

?>
-----
<?php

namespace Rector\PHPUnit\Tests\PHPUnit60\Rector\ClassMethod\AddDoesNotPerformAssertionToNonAssertingTestRector\Fixture;

class TestInAnnotationWithTestAttribute extends \PHPUnit\Framework\TestCase
{
/**
* @doesNotPerformAssertions
*/
#[\PHPUnit\Framework\Attributes\Test]
public function thisIsTest()
{
$nothing = 5;
}
}

?>
8 changes: 8 additions & 0 deletions src/NodeAnalyzer/TestsNodeAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ public function isTestClassMethod(ClassMethod $classMethod): bool
return true;
}

foreach ($classMethod->getAttrGroups() as $attributeGroup) {
foreach ($attributeGroup->attrs as $attribute) {
if ($attribute->name->toString() === 'PHPUnit\\Framework\\Attributes\\Test') {
return true;
}
}
}

$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($classMethod);
return $phpDocInfo->hasByName('test');
}
Expand Down
Loading