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

Add failing array addition tests

This commit is contained in:
Matthew Brown 2016-11-13 14:36:29 -05:00
parent 31f2f95140
commit 2a9e138a14

View File

@ -428,4 +428,36 @@ class ArrayAssignmentTest extends PHPUnit_Framework_TestCase
$file_checker->check(true, true, $context);
$this->assertEquals('array<string, array<string, string>>', (string) $context->vars_in_scope['$a']);
}
public function testAdditionWithEmpty()
{
$stmts = self::$parser->parse('<?php
$a = [];
$a += ["bar"];
$b = [] + ["bar"];
');
$file_checker = new \Psalm\Checker\FileChecker('somefile.php', $stmts);
$context = new Context('somefile.php');
$file_checker->check(true, true, $context);
$this->assertEquals('array<int, string>', (string) $context->vars_in_scope['$a']);
$this->assertEquals('array<int, string>', (string) $context->vars_in_scope['$b']);
}
public function testAdditionDifferentType()
{
$stmts = self::$parser->parse('<?php
$a = ["bar"];
$a += [1];
$b = ["bar"] + [1];
');
$file_checker = new \Psalm\Checker\FileChecker('somefile.php', $stmts);
$context = new Context('somefile.php');
$file_checker->check(true, true, $context);
$this->assertEquals('array<int, string|int>', (string) $context->vars_in_scope['$a']);
$this->assertEquals('array<int, string|int>', (string) $context->vars_in_scope['$b']);
}
}