2016-10-25 01:20:28 +02:00
|
|
|
<?php
|
|
|
|
namespace Psalm\Tests;
|
|
|
|
|
|
|
|
use PhpParser\ParserFactory;
|
|
|
|
use PHPUnit_Framework_TestCase;
|
2016-11-02 07:29:00 +01:00
|
|
|
use Psalm\Checker\FileChecker;
|
|
|
|
use Psalm\Config;
|
2016-10-25 01:20:28 +02:00
|
|
|
use Psalm\Context;
|
|
|
|
|
|
|
|
class InterfaceTest extends PHPUnit_Framework_TestCase
|
|
|
|
{
|
2016-12-14 18:55:23 +01:00
|
|
|
/** @var \PhpParser\Parser */
|
2016-11-02 07:29:00 +01:00
|
|
|
protected static $parser;
|
2016-10-25 01:20:28 +02:00
|
|
|
|
2017-01-02 21:31:18 +01:00
|
|
|
/** @var \Psalm\Checker\ProjectChecker */
|
|
|
|
protected $project_checker;
|
|
|
|
|
2017-01-13 20:07:23 +01:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-10-25 01:20:28 +02:00
|
|
|
public static function setUpBeforeClass()
|
|
|
|
{
|
2016-11-02 07:29:00 +01:00
|
|
|
self::$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
|
2016-10-25 01:20:28 +02:00
|
|
|
|
2016-12-14 18:28:38 +01:00
|
|
|
$config = new TestConfig();
|
2016-10-25 01:20:28 +02:00
|
|
|
}
|
|
|
|
|
2017-01-13 20:07:23 +01:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-10-25 01:20:28 +02:00
|
|
|
public function setUp()
|
|
|
|
{
|
2016-11-02 07:29:00 +01:00
|
|
|
FileChecker::clearCache();
|
2017-01-02 21:31:18 +01:00
|
|
|
$this->project_checker = new \Psalm\Checker\ProjectChecker();
|
2016-10-25 01:20:28 +02:00
|
|
|
}
|
|
|
|
|
2017-01-13 20:07:23 +01:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-11-20 17:51:19 +01:00
|
|
|
public function testExtendsAndImplements()
|
2016-10-25 01:20:28 +02:00
|
|
|
{
|
2016-11-02 07:29:00 +01:00
|
|
|
$stmts = self::$parser->parse('<?php
|
2016-11-02 17:14:21 +01:00
|
|
|
interface A
|
2016-10-25 01:20:28 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2016-12-30 19:09:00 +01:00
|
|
|
public function fooFoo();
|
2016-10-25 01:20:28 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 17:14:21 +01:00
|
|
|
interface B
|
2016-10-25 01:20:28 +02:00
|
|
|
{
|
2016-12-07 20:13:39 +01:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2016-12-30 19:09:00 +01:00
|
|
|
public function barBar();
|
2016-10-25 01:20:28 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 17:14:21 +01:00
|
|
|
interface C extends A, B
|
2016-10-25 01:20:28 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2016-11-20 17:51:19 +01:00
|
|
|
public function baz();
|
2016-10-25 01:20:28 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 17:14:21 +01:00
|
|
|
class D implements C
|
2016-10-25 01:20:28 +02:00
|
|
|
{
|
2016-12-30 19:09:00 +01:00
|
|
|
public function fooFoo()
|
2016-10-25 01:20:28 +02:00
|
|
|
{
|
2016-12-07 20:13:39 +01:00
|
|
|
return "hello";
|
2016-10-25 01:20:28 +02:00
|
|
|
}
|
|
|
|
|
2016-12-30 19:09:00 +01:00
|
|
|
public function barBar()
|
2016-10-25 01:20:28 +02:00
|
|
|
{
|
2016-12-07 20:13:39 +01:00
|
|
|
return "goodbye";
|
2016-10-25 01:20:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function baz()
|
|
|
|
{
|
2016-12-07 20:13:39 +01:00
|
|
|
return "hello again";
|
2016-10-25 01:20:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-02 17:14:21 +01:00
|
|
|
$cee = (new D())->baz();
|
2016-12-30 19:09:00 +01:00
|
|
|
$dee = (new D())->fooFoo();
|
2016-10-25 01:20:28 +02:00
|
|
|
?>
|
|
|
|
');
|
|
|
|
|
2017-01-02 21:31:18 +01:00
|
|
|
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
2016-10-25 01:20:28 +02:00
|
|
|
$context = new Context('somefile.php');
|
2017-01-07 21:09:47 +01:00
|
|
|
$file_checker->visitAndAnalyzeMethods($context);
|
2016-10-25 01:20:28 +02:00
|
|
|
$this->assertEquals('string', (string) $context->vars_in_scope['$cee']);
|
|
|
|
$this->assertEquals('string', (string) $context->vars_in_scope['$dee']);
|
|
|
|
}
|
2016-11-20 17:51:19 +01:00
|
|
|
|
2017-01-13 20:07:23 +01:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-11-20 17:51:19 +01:00
|
|
|
public function testIsExtendedInterface()
|
|
|
|
{
|
|
|
|
$stmts = self::$parser->parse('<?php
|
|
|
|
interface A
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2016-12-30 19:09:00 +01:00
|
|
|
public function fooFoo();
|
2016-11-20 17:51:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
interface B extends A
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function baz();
|
|
|
|
}
|
|
|
|
|
|
|
|
class C implements B
|
|
|
|
{
|
2016-12-30 19:09:00 +01:00
|
|
|
public function fooFoo()
|
2016-11-20 17:51:19 +01:00
|
|
|
{
|
2016-12-07 20:13:39 +01:00
|
|
|
return "hello";
|
2016-11-20 17:51:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function baz()
|
|
|
|
{
|
2016-12-07 20:13:39 +01:00
|
|
|
return "goodbye";
|
2016-11-20 17:51:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-07 20:13:39 +01:00
|
|
|
/**
|
|
|
|
* @param A $a
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-11-20 17:51:19 +01:00
|
|
|
function qux(A $a) {
|
|
|
|
}
|
|
|
|
|
|
|
|
qux(new C());
|
|
|
|
?>
|
|
|
|
');
|
|
|
|
|
2017-01-02 21:31:18 +01:00
|
|
|
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
2016-11-20 17:51:19 +01:00
|
|
|
$context = new Context('somefile.php');
|
2017-01-07 21:09:47 +01:00
|
|
|
$file_checker->visitAndAnalyzeMethods($context);
|
2016-11-20 17:51:19 +01:00
|
|
|
}
|
|
|
|
|
2017-01-13 20:07:23 +01:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-11-20 17:51:19 +01:00
|
|
|
public function testExtendsWithMethod()
|
|
|
|
{
|
|
|
|
$stmts = self::$parser->parse('<?php
|
|
|
|
interface A
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2016-12-30 19:09:00 +01:00
|
|
|
public function fooFoo();
|
2016-11-20 17:51:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
interface B extends A
|
|
|
|
{
|
2016-12-30 19:09:00 +01:00
|
|
|
public function barBar();
|
2016-11-20 17:51:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @return void */
|
|
|
|
function mux(B $b) {
|
2016-12-30 19:09:00 +01:00
|
|
|
$b->fooFoo();
|
2016-11-20 17:51:19 +01:00
|
|
|
}
|
|
|
|
?>
|
|
|
|
');
|
|
|
|
|
2017-01-02 21:31:18 +01:00
|
|
|
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
2016-11-20 17:51:19 +01:00
|
|
|
$context = new Context('somefile.php');
|
2017-01-07 21:09:47 +01:00
|
|
|
$file_checker->visitAndAnalyzeMethods($context);
|
2016-11-20 17:51:19 +01:00
|
|
|
}
|
2016-12-17 04:15:31 +01:00
|
|
|
|
|
|
|
/**
|
2017-01-13 20:07:23 +01:00
|
|
|
* @expectedException \Psalm\Exception\CodeException
|
2016-12-17 04:15:31 +01:00
|
|
|
* @expectedExceptionMessage NoInterfaceProperties
|
2017-01-13 20:07:23 +01:00
|
|
|
* @return void
|
2016-12-17 04:15:31 +01:00
|
|
|
*/
|
|
|
|
public function testNoInterfaceProperties()
|
|
|
|
{
|
|
|
|
$stmts = self::$parser->parse('<?php
|
|
|
|
interface A { }
|
|
|
|
|
2016-12-30 19:09:00 +01:00
|
|
|
function fooFoo(A $a) : void {
|
2016-12-17 04:15:31 +01:00
|
|
|
if ($a->bar) {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
');
|
|
|
|
|
2017-01-02 21:31:18 +01:00
|
|
|
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
2016-12-17 04:15:31 +01:00
|
|
|
$context = new Context('somefile.php');
|
2017-01-07 21:09:47 +01:00
|
|
|
$file_checker->visitAndAnalyzeMethods($context);
|
2016-12-17 04:15:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-13 20:07:23 +01:00
|
|
|
* @expectedException \Psalm\Exception\CodeException
|
2016-12-17 04:15:31 +01:00
|
|
|
* @expectedExceptionMessage UnimplementedInterfaceMethod
|
2017-01-13 20:07:23 +01:00
|
|
|
* @return void
|
2016-12-17 04:15:31 +01:00
|
|
|
*/
|
|
|
|
public function testUnimplementedInterfaceMethod()
|
|
|
|
{
|
|
|
|
$stmts = self::$parser->parse('<?php
|
|
|
|
interface A {
|
2016-12-30 19:09:00 +01:00
|
|
|
public function fooFoo();
|
2016-12-17 04:15:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class B implements A { }
|
|
|
|
?>
|
|
|
|
');
|
|
|
|
|
2017-01-02 21:31:18 +01:00
|
|
|
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
2016-12-17 04:15:31 +01:00
|
|
|
$context = new Context('somefile.php');
|
2017-01-07 21:09:47 +01:00
|
|
|
$file_checker->visitAndAnalyzeMethods($context);
|
2016-12-17 04:15:31 +01:00
|
|
|
}
|
2016-12-29 02:33:26 +01:00
|
|
|
|
|
|
|
/**
|
2017-01-13 20:07:23 +01:00
|
|
|
* @expectedException \Psalm\Exception\CodeException
|
2016-12-29 02:33:26 +01:00
|
|
|
* @expectedExceptionMessage MethodSignatureMismatch
|
2017-01-13 20:07:23 +01:00
|
|
|
* @return void
|
2016-12-29 02:33:26 +01:00
|
|
|
*/
|
|
|
|
public function testMismatchingInterfaceMethodSignature()
|
|
|
|
{
|
|
|
|
$stmts = self::$parser->parse('<?php
|
|
|
|
interface A {
|
2016-12-30 21:53:35 +01:00
|
|
|
public function fooFoo(int $a) : void;
|
2016-12-29 02:33:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class B implements A {
|
2016-12-30 21:53:35 +01:00
|
|
|
public function fooFoo(string $a) : void {
|
2016-12-29 02:33:26 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
');
|
|
|
|
|
2017-01-02 21:31:18 +01:00
|
|
|
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
2016-12-30 05:37:09 +01:00
|
|
|
$context = new Context('somefile.php');
|
2017-01-07 21:09:47 +01:00
|
|
|
$file_checker->visitAndAnalyzeMethods($context);
|
2016-12-30 05:37:09 +01:00
|
|
|
}
|
|
|
|
|
2017-01-13 20:07:23 +01:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-12-30 05:37:09 +01:00
|
|
|
public function testCorrectInterfaceMethodSignature()
|
|
|
|
{
|
|
|
|
$stmts = self::$parser->parse('<?php
|
|
|
|
interface A {
|
2016-12-30 19:09:00 +01:00
|
|
|
public function fooFoo(int $a) : void;
|
2016-12-30 05:37:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class B implements A {
|
2016-12-30 19:09:00 +01:00
|
|
|
public function fooFoo(int $a) : void {
|
2016-12-30 05:37:09 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
');
|
|
|
|
|
2017-01-02 21:31:18 +01:00
|
|
|
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
2016-12-30 05:37:09 +01:00
|
|
|
$context = new Context('somefile.php');
|
2017-01-07 21:09:47 +01:00
|
|
|
$file_checker->visitAndAnalyzeMethods($context);
|
2016-12-30 05:37:09 +01:00
|
|
|
}
|
|
|
|
|
2017-01-13 20:07:23 +01:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
2017-01-02 01:09:17 +01:00
|
|
|
public function testInterfaceMethodImplementedInParent()
|
2016-12-30 05:37:09 +01:00
|
|
|
{
|
|
|
|
$stmts = self::$parser->parse('<?php
|
|
|
|
interface MyInterface {
|
2016-12-30 19:09:00 +01:00
|
|
|
public function fooFoo(int $a) : void;
|
2016-12-30 05:37:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class B {
|
2016-12-30 19:09:00 +01:00
|
|
|
public function fooFoo(int $a) : void {
|
2016-12-30 05:37:09 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-02 01:09:17 +01:00
|
|
|
class C extends B implements MyInterface { }
|
2016-12-30 05:37:09 +01:00
|
|
|
?>
|
|
|
|
');
|
|
|
|
|
2017-01-02 21:31:18 +01:00
|
|
|
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
2016-12-29 02:33:26 +01:00
|
|
|
$context = new Context('somefile.php');
|
2017-01-07 21:09:47 +01:00
|
|
|
$file_checker->visitAndAnalyzeMethods($context);
|
2016-12-29 02:33:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-13 20:07:23 +01:00
|
|
|
* @expectedException \Psalm\Exception\CodeException
|
2016-12-29 02:33:26 +01:00
|
|
|
* @expectedExceptionMessage MethodSignatureMismatch
|
2017-01-13 20:07:23 +01:00
|
|
|
* @return void
|
2016-12-29 02:33:26 +01:00
|
|
|
*/
|
|
|
|
public function testMismatchingInterfaceMethodSignatureInTrait()
|
|
|
|
{
|
|
|
|
$stmts = self::$parser->parse('<?php
|
|
|
|
interface A {
|
2016-12-30 19:09:00 +01:00
|
|
|
public function fooFoo(int $a, int $b) : void;
|
2016-12-29 02:33:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
trait T {
|
2016-12-30 19:09:00 +01:00
|
|
|
public function fooFoo(int $a) : void {
|
2016-12-29 02:33:26 +01:00
|
|
|
}
|
|
|
|
}
|
2016-12-29 04:11:50 +01:00
|
|
|
|
|
|
|
class B implements A {
|
|
|
|
use T;
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
');
|
|
|
|
|
2017-01-02 21:31:18 +01:00
|
|
|
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
2016-12-29 04:11:50 +01:00
|
|
|
$context = new Context('somefile.php');
|
2017-01-07 21:09:47 +01:00
|
|
|
$file_checker->visitAndAnalyzeMethods($context);
|
2016-12-29 04:11:50 +01:00
|
|
|
}
|
|
|
|
|
2017-01-13 20:07:23 +01:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-12-29 04:11:50 +01:00
|
|
|
public function testInterfaceMethodSignatureInTrait()
|
|
|
|
{
|
|
|
|
$stmts = self::$parser->parse('<?php
|
|
|
|
interface A {
|
2016-12-30 19:09:00 +01:00
|
|
|
public function fooFoo(int $a, int $b) : void;
|
2016-12-29 04:11:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
trait T {
|
2016-12-30 19:09:00 +01:00
|
|
|
public function fooFoo(int $a, int $b) : void {
|
2016-12-29 04:11:50 +01:00
|
|
|
}
|
|
|
|
}
|
2016-12-29 02:33:26 +01:00
|
|
|
|
|
|
|
class B implements A {
|
|
|
|
use T;
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
');
|
|
|
|
|
2017-01-02 21:31:18 +01:00
|
|
|
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
2016-12-29 02:33:26 +01:00
|
|
|
$context = new Context('somefile.php');
|
2017-01-07 21:09:47 +01:00
|
|
|
$file_checker->visitAndAnalyzeMethods($context);
|
2016-12-29 02:33:26 +01:00
|
|
|
}
|
2016-12-29 03:37:24 +01:00
|
|
|
|
|
|
|
/**
|
2017-01-13 20:07:23 +01:00
|
|
|
* @expectedException \Psalm\Exception\CodeException
|
2016-12-29 03:37:24 +01:00
|
|
|
* @expectedExceptionMessage MethodSignatureMismatch
|
2017-01-13 20:07:23 +01:00
|
|
|
* @return void
|
2016-12-29 03:37:24 +01:00
|
|
|
*/
|
|
|
|
public function testMismatchingInterfaceMethodSignatureInImplementer()
|
|
|
|
{
|
|
|
|
$stmts = self::$parser->parse('<?php
|
|
|
|
interface A {
|
2016-12-30 19:09:00 +01:00
|
|
|
public function fooFoo(int $a, int $b) : void;
|
2016-12-29 03:37:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
trait T {
|
2016-12-30 19:09:00 +01:00
|
|
|
public function fooFoo(int $a, int $b) : void {
|
2016-12-29 03:37:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class B implements A {
|
|
|
|
use T;
|
|
|
|
|
2016-12-30 19:09:00 +01:00
|
|
|
public function fooFoo(int $a) : void {
|
2016-12-29 03:37:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
');
|
|
|
|
|
2017-01-02 21:31:18 +01:00
|
|
|
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
|
|
|
$context = new Context('somefile.php');
|
2017-01-07 21:09:47 +01:00
|
|
|
$file_checker->visitAndAnalyzeMethods($context);
|
2017-01-02 21:31:18 +01:00
|
|
|
}
|
|
|
|
|
2017-01-13 20:07:23 +01:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
2017-01-02 21:31:18 +01:00
|
|
|
public function testDelayedInterface()
|
|
|
|
{
|
|
|
|
$stmts = self::$parser->parse('<?php
|
|
|
|
// fails in PHP, whatcha gonna do
|
|
|
|
$c = new C;
|
|
|
|
|
|
|
|
class A { }
|
|
|
|
|
|
|
|
interface B { }
|
|
|
|
|
|
|
|
class C extends A implements B { }
|
|
|
|
');
|
|
|
|
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
2016-12-29 03:37:24 +01:00
|
|
|
$context = new Context('somefile.php');
|
2017-01-07 21:09:47 +01:00
|
|
|
$file_checker->visitAndAnalyzeMethods($context);
|
2016-12-29 03:37:24 +01:00
|
|
|
}
|
2017-01-12 17:16:00 +01:00
|
|
|
|
|
|
|
/**
|
2017-01-13 20:07:23 +01:00
|
|
|
* @expectedException \Psalm\Exception\CodeException
|
2017-01-12 17:16:00 +01:00
|
|
|
* @expectedExceptionMessage UndefinedClass
|
2017-01-13 20:07:23 +01:00
|
|
|
* @return void
|
2017-01-12 17:16:00 +01:00
|
|
|
*/
|
|
|
|
public function testInvalidImplements()
|
|
|
|
{
|
|
|
|
$this->project_checker->registerFile(
|
|
|
|
getcwd() . '/somefile.php',
|
|
|
|
'<?php
|
|
|
|
class C2 implements A {
|
|
|
|
}
|
|
|
|
');
|
|
|
|
$file_checker = new FileChecker(getcwd() . '/somefile.php', $this->project_checker);
|
|
|
|
$context = new Context('somefile.php');
|
|
|
|
$file_checker->visitAndAnalyzeMethods($context);
|
|
|
|
}
|
2017-01-13 18:52:32 +01:00
|
|
|
|
2017-01-13 20:07:23 +01:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
2017-01-13 18:52:32 +01:00
|
|
|
public function testTypeDoesNotContainType()
|
|
|
|
{
|
|
|
|
$stmts = self::$parser->parse('<?php
|
|
|
|
interface A { }
|
|
|
|
interface B {
|
|
|
|
function foo();
|
|
|
|
}
|
|
|
|
function bar(A $a) : void {
|
|
|
|
if ($a instanceof B) {
|
|
|
|
$a->foo();
|
|
|
|
}
|
|
|
|
}');
|
|
|
|
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
|
|
|
$context = new Context('somefile.php');
|
|
|
|
$file_checker->visitAndAnalyzeMethods($context);
|
|
|
|
}
|
2017-01-16 01:02:36 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testAbstractInterfaceImplements()
|
|
|
|
{
|
|
|
|
$stmts = self::$parser->parse('<?php
|
|
|
|
interface I {
|
|
|
|
public function fnc();
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract class A implements I {}
|
|
|
|
');
|
|
|
|
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
|
|
|
$context = new Context('somefile.php');
|
|
|
|
$file_checker->visitAndAnalyzeMethods($context);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \Psalm\Exception\CodeException
|
|
|
|
* @expectedExceptionMessage UnimplementedInterfaceMethod
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testAbstractInterfaceImplementsWithSubclass()
|
|
|
|
{
|
|
|
|
$stmts = self::$parser->parse('<?php
|
|
|
|
interface I {
|
|
|
|
public function fnc();
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract class A implements I {}
|
|
|
|
|
|
|
|
class B extends A {}
|
|
|
|
');
|
|
|
|
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
|
|
|
$context = new Context('somefile.php');
|
|
|
|
$file_checker->visitAndAnalyzeMethods($context);
|
|
|
|
}
|
2016-10-25 01:20:28 +02:00
|
|
|
}
|