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

282 lines
8.6 KiB
PHP
Raw Normal View History

<?php
namespace Psalm\Tests;
use Psalm\Config;
use Psalm\Context;
class InternalAnnotationTest extends TestCase
{
use Traits\InvalidCodeAnalysisTestTrait;
use Traits\ValidCodeAnalysisTestTrait;
/**
* @return array
*/
public function providerValidCodeParse()
{
return [
'internalMethodWithCall' => [
'<?php
namespace A {
class Foo {
/**
* @internal
*/
public static function barBar(): void {
}
}
}
namespace A\B {
class Bat {
public function batBat() : void {
\A\Foo::barBar();
}
}
}',
],
'internalClassWithStaticCall' => [
'<?php
namespace A {
/**
* @internal
*/
class Foo {
public static function barBar(): void {
}
}
}
namespace A\B {
class Bat {
public function batBat() : void {
\A\Foo::barBar();
}
}
}',
],
'internalClassExtendingNamespaceWithStaticCall' => [
'<?php
namespace A {
/**
* @internal
*/
class Foo extends \B\Foo {
public function __construct() {
parent::__construct();
}
public static function barBar(): void {
}
}
}
namespace B {
class Foo {
public function __construct() {
static::barBar();
}
public static function barBar(): void {
}
}
}',
],
'internalClassWithNew' => [
'<?php
namespace A {
/**
* @internal
*/
class Foo { }
}
namespace A\B {
class Bat {
public function batBat() : void {
$a = new \A\Foo();
}
}
}',
],
'internalClassWithExtends' => [
'<?php
namespace A {
/**
* @internal
*/
class Foo { }
}
namespace A\B {
class Bar extends \A\Foo {}
}',
],
'internalPropertyGet' => [
'<?php
namespace A {
class Foo {
/**
* @internal
* @var ?int
*/
public $foo;
}
}
namespace A\B {
class Bat {
public function batBat() : void {
echo (new \A\Foo)->foo;
}
}
}',
],
'internalPropertySet' => [
'<?php
namespace A {
class Foo {
/**
* @internal
* @var ?int
*/
public $foo;
}
}
namespace A\B {
class Bat {
public function batBat() : void {
$a = new \A\Foo;
$a->foo = 5;
}
}
}',
],
];
}
/**
* @return array
*/
public function providerInvalidCodeParse()
{
return [
'internalMethodWithCall' => [
'<?php
namespace A {
class Foo {
/**
* @internal
*/
public static function barBar(): void {
}
}
}
namespace B {
class Bat {
public function batBat() {
\A\Foo::barBar();
}
}
}',
'error_message' => 'InternalMethod',
],
'internalClassWithStaticCall' => [
'<?php
namespace A {
/**
* @internal
*/
class Foo {
public static function barBar(): void {
}
}
}
namespace B {
class Bat {
public function batBat() {
\A\Foo::barBar();
}
}
}',
'error_message' => 'InternalClass',
],
'internalClassWithNew' => [
'<?php
namespace A {
/**
* @internal
*/
class Foo { }
}
namespace B {
class Bat {
public function batBat() {
$a = new \A\Foo();
}
}
}',
'error_message' => 'InternalClass',
],
'internalClassWithExtends' => [
'<?php
namespace A {
/**
* @internal
*/
class Foo { }
}
namespace B {
class Bar extends \A\Foo {}
}',
'error_message' => 'InternalClass',
],
'internalPropertyGet' => [
'<?php
namespace A {
class Foo {
/**
* @internal
* @var ?int
*/
public $foo;
}
}
namespace B {
class Bat {
public function batBat() : void {
echo (new \A\Foo)->foo;
}
}
}',
'error_message' => 'InternalProperty',
],
'internalPropertySet' => [
'<?php
namespace A {
class Foo {
/**
* @internal
* @var ?int
*/
public $foo;
}
}
namespace B {
class Bat {
public function batBat() : void {
$a = new \A\Foo;
$a->foo = 5;
}
}
}',
'error_message' => 'InternalProperty',
],
];
}
}