1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Check for arrayAccess erroneous vars

This commit is contained in:
Matthew Brown 2016-09-22 13:45:47 -04:00
parent 478ef9b551
commit 9f37dc8626

View File

@ -284,6 +284,22 @@ class ArrayAssignmentTest extends PHPUnit_Framework_TestCase
$context->vars_in_scope['b'] = \Psalm\Type::getBool();
$context->vars_in_scope['foo'] = \Psalm\Type::getArray();
$file_checker->check(true, true, $context);
$this->assertEquals(false, isset($context->vars_in_scope['foo[\'a\']']));
$this->assertFalse(isset($context->vars_in_scope['foo[\'a\']']));
}
public function testImplementsArrayAccess()
{
$stmts = self::$_parser->parse('<?php
class A implements \ArrayAccess { }
$a = new A();
$a["bar"] = "cool";
');
$file_checker = new \Psalm\Checker\FileChecker('somefile.php', $stmts);
$context = new Context('somefile.php');
$file_checker->check(true, true, $context);
$this->assertEquals('A', (string) $context->vars_in_scope['a']);
$this->assertFalse(isset($context->vars_in_scope['a[\'bar\']']));
}
}