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

90 lines
1.8 KiB
PHP
Raw Normal View History

2016-10-25 01:20:28 +02:00
<?php
namespace Psalm\Tests;
use PhpParser;
use PhpParser\ParserFactory;
use PHPUnit_Framework_TestCase;
use Psalm\Context;
use Psalm\Checker\TypeChecker;
use Psalm\Type;
class InterfaceTest extends PHPUnit_Framework_TestCase
{
protected static $_parser;
public static function setUpBeforeClass()
{
self::$_parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
$config = \Psalm\Config::getInstance();
$config->throw_exception = true;
$config->use_docblock_types = true;
}
public function setUp()
{
\Psalm\Checker\FileChecker::clearCache();
}
public function testExtends()
{
$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
*/
public function foo();
}
2016-11-02 17:14:21 +01:00
interface B
2016-10-25 01:20:28 +02:00
{
public function bar() {
}
}
2016-11-02 17:14:21 +01:00
interface C extends A, B
2016-10-25 01:20:28 +02:00
{
/**
* @return string
*/
public function baz() {
}
}
2016-11-02 17:14:21 +01:00
class D implements C
2016-10-25 01:20:28 +02:00
{
public function foo()
{
}
public function bar()
{
}
public function baz()
{
}
}
2016-11-02 17:14:21 +01:00
function qux(A $a) {
}
$cee = (new D())->baz();
$dee = (new D())->foo();
qux(new D());
2016-10-25 01:20:28 +02:00
?>
');
$file_checker = new \Psalm\Checker\FileChecker('somefile.php', $stmts);
$context = new Context('somefile.php');
$file_checker->check(true, true, $context);
$this->assertEquals('string', (string) $context->vars_in_scope['$cee']);
$this->assertEquals('string', (string) $context->vars_in_scope['$dee']);
}
}