2020-10-19 21:08:18 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Psalm\Tests;
|
|
|
|
|
2021-12-04 21:55:53 +01:00
|
|
|
use Psalm\Tests\Traits\InvalidCodeAnalysisTestTrait;
|
|
|
|
use Psalm\Tests\Traits\ValidCodeAnalysisTestTrait;
|
|
|
|
|
2020-10-19 21:08:18 +02:00
|
|
|
class ImplementationRequirementTest extends TestCase
|
|
|
|
{
|
2021-12-04 21:55:53 +01:00
|
|
|
use ValidCodeAnalysisTestTrait;
|
|
|
|
use InvalidCodeAnalysisTestTrait;
|
2020-10-19 21:08:18 +02:00
|
|
|
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->addFile(
|
|
|
|
'base.php',
|
|
|
|
'<?php
|
|
|
|
namespace ImplementationRequirements\Base;
|
|
|
|
|
|
|
|
interface A { }
|
|
|
|
interface B { }
|
|
|
|
'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->addFile(
|
|
|
|
'trait.php',
|
|
|
|
'<?php
|
|
|
|
namespace ImplementationRequirements\Trait;
|
|
|
|
|
|
|
|
use ImplementationRequirements\Base\A as MyAliasedInterfaceA;
|
|
|
|
use ImplementationRequirements\Base\B as MyAliasedInterfaceB;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @psalm-require-implements MyAliasedInterfaceA
|
|
|
|
* @psalm-require-implements MyAliasedInterfaceB
|
|
|
|
*/
|
|
|
|
trait ImposesImplementationRequirements { }
|
|
|
|
'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function providerValidCodeParse(): iterable
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'implementsAllRequirements' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-10-19 21:08:18 +02:00
|
|
|
use ImplementationRequirements\Base\A;
|
|
|
|
use ImplementationRequirements\Base\B;
|
|
|
|
use ImplementationRequirements\Trait\ImposesImplementationRequirements;
|
|
|
|
|
|
|
|
class Valid implements A, B {
|
|
|
|
use ImposesImplementationRequirements;
|
|
|
|
}
|
|
|
|
'
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function providerInvalidCodeParse(): iterable
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'doesNotImplementAnything' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-10-19 21:08:18 +02:00
|
|
|
use ImplementationRequirements\Trait\ImposesImplementationRequirements;
|
|
|
|
|
|
|
|
class Invalid {
|
|
|
|
use ImposesImplementationRequirements;
|
|
|
|
}
|
|
|
|
',
|
|
|
|
'error_message' => 'requires using class to implement'
|
|
|
|
],
|
|
|
|
'onlyImplementsOneRequirement' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2020-10-19 21:08:18 +02:00
|
|
|
use ImplementationRequirements\Trait\ImposesImplementationRequirements;
|
|
|
|
use ImplementationRequirements\Base\A;
|
|
|
|
|
|
|
|
class Invalid implements A {
|
|
|
|
use ImposesImplementationRequirements;
|
|
|
|
}
|
|
|
|
',
|
|
|
|
'error_message' => 'requires using class to implement'
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|