Skip to content

Commit

Permalink
Update to use PHPUnit 10 syntax (#1163)
Browse files Browse the repository at this point in the history
* Update to use PHPUnit 10 syntax

* Fix SessionTest

* Fix session test

* skip ArrayAccess transform on SessionTest

* try fix psalm

* fix rector notice
  • Loading branch information
samsonasik authored Nov 8, 2024
1 parent ce3e921 commit ce22a28
Show file tree
Hide file tree
Showing 20 changed files with 45 additions and 53 deletions.
19 changes: 18 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPromotedPropertyRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPublicMethodParameterRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector;
use Rector\DeadCode\Rector\Expression\RemoveDeadStmtRector;
use Rector\DeadCode\Rector\If_\RemoveAlwaysTrueIfConditionRector;
use Rector\DeadCode\Rector\Property\RemoveUselessVarTagRector;
Expand Down Expand Up @@ -104,9 +106,24 @@
// used by Configurator
__DIR__ . '/src/Scaffolder/src/Command',
],

\Rector\PHPUnit\PHPUnit100\Rector\MethodCall\AssertIssetToAssertObjectHasPropertyRector::class => [
// ArrayAccess usage
__DIR__ . '/src/Session/tests/SessionTest.php',
],

// nullable @template usage, see https://github.com/rectorphp/rector-src/pull/6409
// can be re-enabled on next rector release
RemoveUselessParamTagRector::class => [
__DIR__ . '/src/Interceptors/src/Context/Target.php',
],

RemoveUselessReturnTagRector::class => [
__DIR__ . '/src/Interceptors/src/Context/TargetInterface.php',
],
])
->withPhpSets(php81: true)
->withPreparedSets(deadCode: true)
->withPreparedSets(deadCode: true, phpunit: true)
->withConfiguredRule(ClassPropertyAssignToConstructorPromotionRector::class, [
ClassPropertyAssignToConstructorPromotionRector::RENAME_PROPERTY => false,
]);
4 changes: 1 addition & 3 deletions src/Core/tests/InjectableConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Spiral\Tests\Core\Fixtures\IntKeysConfig;
use Spiral\Tests\Core\Fixtures\TestConfig;

#[\PHPUnit\Framework\Attributes\CoversClass(\Spiral\Core\InjectableConfig::class)]
class InjectableConfigTest extends TestCase
{
use AliasTrait;
Expand Down Expand Up @@ -101,9 +102,6 @@ public function testGetError(): void
$config['keyC'];
}

/**
* @covers \Spiral\Core\InjectableConfig::__set_state()
*/
public function testSerialize(): void
{
$config = new TestConfig([
Expand Down
4 changes: 1 addition & 3 deletions src/Distribution/tests/ManagerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
use Spiral\Distribution\Manager;
use Spiral\Distribution\Resolver\StaticResolver;

/**
* @group unit
*/
#[\PHPUnit\Framework\Attributes\Group('unit')]
class ManagerTestCase extends TestCase
{
/**
Expand Down
4 changes: 1 addition & 3 deletions src/Distribution/tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
use PHPUnit\Framework\TestCase as BaseTestCase;
use Psr\Http\Message\UriInterface;

/**
* @group unit
*/
#[\PHPUnit\Framework\Attributes\Group('unit')]
abstract class TestCase extends BaseTestCase
{
protected function uri(string $uri): UriInterface
Expand Down
4 changes: 1 addition & 3 deletions src/Encrypter/tests/EncrypterFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Spiral\Encrypter\EncryptionInterface;
use Spiral\Encrypter\Exception\EncrypterException;

#[\PHPUnit\Framework\Attributes\CoversClass(\Spiral\Encrypter\EncrypterFactory::class)]
class EncrypterFactoryTest extends TestCase
{
public function testInjection(): void
Expand Down Expand Up @@ -79,9 +80,6 @@ public function testExceptionKey(): void
echo $factory->getKey();
}

/**
* @covers \Spiral\Encrypter\EncrypterFactory::generateKey
*/
public function testGenerateKey(): void
{
$key = Key::CreateNewRandomKey()->saveToAsciiSafeString();
Expand Down
4 changes: 1 addition & 3 deletions src/Encrypter/tests/EncrypterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Spiral\Encrypter\Exception\DecryptException;
use Spiral\Encrypter\Exception\EncrypterException;

#[\PHPUnit\Framework\Attributes\CoversClass(\Spiral\Encrypter\Encrypter::class)]
class EncrypterTest extends TestCase
{
public function testImmutable(): void
Expand All @@ -23,9 +24,6 @@ public function testImmutable(): void
$this->assertEquals($keyB, $new->getKey());
}

/**
* @covers \Spiral\Encrypter\Encrypter::encrypt
*/
public function testEncryption(): void
{
$encrypter = new Encrypter(Key::CreateNewRandomKey()->saveToAsciiSafeString());
Expand Down
8 changes: 2 additions & 6 deletions src/Scaffolder/tests/Config/ScaffolderConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,15 @@ public function testPartialOverrideDefaultDeclaration(): void
$this->assertSame(BootloaderDeclaration::class, $ref->invoke($config, BootloaderDeclaration::TYPE, 'class'));
}

/**
* @dataProvider declarationDirectoryDataProvider
*/
#[\PHPUnit\Framework\Attributes\DataProvider('declarationDirectoryDataProvider')]
public function testDeclarationDirectory(array $config, string $expected): void
{
$config = new ScaffolderConfig($config);

$this->assertSame($expected, $config->declarationDirectory('some'));
}

/**
* @dataProvider classFilenameDataProvider
*/
#[\PHPUnit\Framework\Attributes\DataProvider('classFilenameDataProvider')]
public function testClassFilename(array $config, string $expected, string $namespace): void
{
$config = new ScaffolderConfig($config);
Expand Down
4 changes: 2 additions & 2 deletions src/Security/tests/GuardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ class GuardTest extends TestCase
public const CONTEXT = [];

/**
* @var \PHPUnit_Framework_MockObject_MockObject|PermissionsInterface
* @var \PHPUnit\Framework\MockObject\MockObject|PermissionsInterface
*/
private $permission;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|ActorInterface
* @var \PHPUnit\Framework\MockObject\MockObject|ActorInterface
*/
private $actor;

Expand Down
6 changes: 3 additions & 3 deletions src/Security/tests/RuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ class RuleTest extends TestCase
public const CONTEXT = [];

/**
* @var \PHPUnit_Framework_MockObject_MockObject|ActorInterface
* @var \PHPUnit\Framework\MockObject\MockObject|ActorInterface
*/
private $actor;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|ResolverInterface
* @var \PHPUnit\Framework\MockObject\MockObject|ResolverInterface
*/
private $resolver;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|Rule
* @var \PHPUnit\Framework\MockObject\MockObject|Rule
*/
private $rule;

Expand Down
2 changes: 1 addition & 1 deletion src/Security/tests/Rules/CallableRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function testAllow(): void
$actor = $this->createMock(ActorInterface::class);
$context = [];

/** @var \PHPUnit_Framework_MockObject_MockObject|callable $callable */
/** @var \PHPUnit\Framework\MockObject\MockObject|callable $callable */
$callable = $this->getMockBuilder(\stdClass::class)
->addMethods(['__invoke'])
->getMock();
Expand Down
4 changes: 2 additions & 2 deletions src/Security/tests/Rules/CompositeRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CompositeRuleTest extends TestCase
public const CONTEXT = [];

/**
* @var \PHPUnit_Framework_MockObject_MockObject|ActorInterface $callable
* @var \PHPUnit\Framework\MockObject\MockObject|ActorInterface $callable
*/
private $actor;

Expand Down Expand Up @@ -56,7 +56,7 @@ public static function allowsProvider(): \Traversable

private function createRepository(array $rules): RulesInterface
{
/** @var \PHPUnit_Framework_MockObject_MockObject|RulesInterface $repository */
/** @var \PHPUnit\Framework\MockObject\MockObject|RulesInterface $repository */
$repository = $this->createMock(RulesInterface::class);

$repository->method('get')
Expand Down
6 changes: 3 additions & 3 deletions src/Security/tests/Traits/GuardedTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ class GuardedTraitTest extends TestCase
public const CONTEXT = [];

/**
* @var \PHPUnit_Framework_MockObject_MockObject|GuardedTrait
* @var \PHPUnit\Framework\MockObject\MockObject|GuardedTrait
*/
private $trait;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|GuardInterface
* @var \PHPUnit\Framework\MockObject\MockObject|GuardInterface
*/
private $guard;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|ContainerInterface
* @var \PHPUnit\Framework\MockObject\MockObject|ContainerInterface
*/
private $container;

Expand Down
1 change: 1 addition & 0 deletions src/Stempler/tests/TraverserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public function leaveNode(mixed $node, VisitorContext $ctx): mixed
);
}

#[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions]
public function testVisitorContext(): void
{
$doc = $this->parse('<a href="url"><b>hello</b></a>');
Expand Down
4 changes: 1 addition & 3 deletions src/Storage/tests/FileTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

use Spiral\Storage\Visibility;

/**
* @group unit
*/
#[\PHPUnit\Framework\Attributes\Group('unit')]
class FileTestCase extends TestCase
{
public function testPathname(): void
Expand Down
4 changes: 1 addition & 3 deletions src/Storage/tests/ManagerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
use Spiral\Storage\Bucket;
use Spiral\Storage\Visibility;

/**
* @group unit
*/
#[\PHPUnit\Framework\Attributes\Group('unit')]
class ManagerTestCase extends TestCase
{
/**
Expand Down
4 changes: 1 addition & 3 deletions src/Storage/tests/StorageTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
use Spiral\Storage\Bucket;
use Spiral\Storage\Visibility;

/**
* @group unit
*/
#[\PHPUnit\Framework\Attributes\Group('unit')]
class StorageTestCase extends TestCase
{
public function testCreate(): void
Expand Down
2 changes: 1 addition & 1 deletion src/Translator/tests/TraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class TraitTest extends TestCase
use TranslatorTrait;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|ContainerInterface
* @var \PHPUnit\Framework\MockObject\MockObject|ContainerInterface
*/
private $container;

Expand Down
4 changes: 1 addition & 3 deletions tests/Framework/Command/CleanCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\OutputInterface;

/**
* @covers \Spiral\Command\CleanCommand
*/
#[\PHPUnit\Framework\Attributes\CoversClass(\Spiral\Command\CleanCommand::class)]
final class CleanCommandTest extends ConsoleTestCase
{
public int $defaultVerbosityLevel = OutputInterface::VERBOSITY_DEBUG;
Expand Down
6 changes: 2 additions & 4 deletions tests/Framework/Command/Views/CompileCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
use Spiral\Tests\Framework\ConsoleTestCase;
use Symfony\Component\Console\Output\OutputInterface;

/**
* @covers \Spiral\Command\Views\ResetCommand
* @covers \Spiral\Command\Views\CompileCommand
*/
#[\PHPUnit\Framework\Attributes\CoversClass(\Spiral\Command\Views\ResetCommand::class)]
#[\PHPUnit\Framework\Attributes\CoversClass(\Spiral\Command\Views\CompileCommand::class)]
final class CompileCommandTest extends ConsoleTestCase
{
public int $defaultVerbosityLevel = OutputInterface::VERBOSITY_DEBUG;
Expand Down
4 changes: 1 addition & 3 deletions tests/Framework/Http/ErrorHandler/PlainRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
use Psr\Http\Message\ResponseFactoryInterface;
use Spiral\Http\ErrorHandler\PlainRenderer;

/**
* @coversDefaultClass \Spiral\Http\ErrorHandler\PlainRenderer
*/
#[\PHPUnit\Framework\Attributes\CoversClass(\Spiral\Http\ErrorHandler\PlainRenderer::class)]
final class PlainRendererTest extends TestCase
{
public function testContentTypeApplicationJson(): void
Expand Down

0 comments on commit ce22a28

Please sign in to comment.