1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00
psalm/tests/ExtensionRequirementTest.php

73 lines
1.8 KiB
PHP
Raw Normal View History

<?php
2023-10-19 13:12:06 +02:00
declare(strict_types=1);
namespace Psalm\Tests;
2021-12-04 21:55:53 +01:00
use Psalm\Tests\Traits\InvalidCodeAnalysisTestTrait;
use Psalm\Tests\Traits\ValidCodeAnalysisTestTrait;
class ExtensionRequirementTest extends TestCase
{
2021-12-04 21:55:53 +01:00
use ValidCodeAnalysisTestTrait;
use InvalidCodeAnalysisTestTrait;
public function setUp(): void
{
parent::setUp();
$this->addFile(
'base.php',
'<?php
namespace ExtensionRequirements\Base;
class MyBaseClass { }
2022-12-18 17:15:15 +01:00
',
);
$this->addFile(
'trait.php',
'<?php
namespace ExtensionRequirements\Trait;
use ExtensionRequirements\Base\MyBaseClass as MyAliasedBaseClass;
/** @psalm-require-extends MyAliasedBaseClass */
trait ImposesExtensionRequirements { }
2022-12-18 17:15:15 +01:00
',
);
}
public function providerValidCodeParse(): iterable
{
return [
'extendsBaseClass' => [
'code' => '<?php
use ExtensionRequirements\Base\MyBaseClass;
use ExtensionRequirements\Trait\ImposesExtensionRequirements;
class Valid extends MyBaseClass {
use ImposesExtensionRequirements;
}
2022-12-18 17:15:15 +01:00
',
],
];
}
public function providerInvalidCodeParse(): iterable
{
return [
'extendsBaseClass' => [
'code' => '<?php
use ExtensionRequirements\Trait\ImposesExtensionRequirements;
class Invalid {
use ImposesExtensionRequirements;
}
',
2022-12-18 17:15:15 +01:00
'error_message' => 'requires using class to extend',
],
];
}
}