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

Test coolness

This commit is contained in:
Matthew Brown 2016-07-25 18:31:03 -04:00
parent c32179f1a1
commit 7b20c032b3
2 changed files with 71 additions and 9 deletions

View File

@ -123,21 +123,82 @@ class ArrayReturnTypeTest extends PHPUnit_Framework_TestCase
$file_checker->check();
}
public function testGenericArrayCreationWithObjectAddedInSwitch()
public function testGenericArrayCreationWithElementAddedInSwitch()
{
$stmts = self::$_parser->parse('<?php
class B {
/**
* @return array<B>
* @return array<int>
*/
public function bar(array $in) {
$out = [];
if (rand(0,10) === 10) {
switch (rand(0,10)) {
case 5:
$out[4] = new B();
}
switch (rand(0,10)) {
case 5:
$out[] = 4;
break;
case 6:
// do nothing
}
return $out;
}
}');
$file_checker = new \CodeInspector\FileChecker('somefile.php', $stmts);
$file_checker->check();
}
public function testGenericArrayCreationWithElementsAddedInSwitch()
{
$stmts = self::$_parser->parse('<?php
class B {
/**
* @return array<int|string>
*/
public function bar(array $in) {
$out = [];
switch (rand(0,10)) {
case 5:
$out[] = 4;
break;
case 6:
$out[] = "hello";
break;
}
return $out;
}
}');
$file_checker = new \CodeInspector\FileChecker('somefile.php', $stmts);
$file_checker->check();
}
public function testGenericArrayCreationWithElementsAddedInSwitchWithNothing()
{
$stmts = self::$_parser->parse('<?php
class B {
/**
* @return array<int|string>
*/
public function bar(array $in) {
$out = [];
switch (rand(0,10)) {
case 5:
$out[] = 4;
break;
case 6:
$out[] = "hello";
break;
case 7:
// do nothing
}
return $out;

View File

@ -53,12 +53,13 @@ class TypeReconciliationTest extends PHPUnit_Framework_TestCase
(string) TypeChecker::reconcileTypes('!empty', Type::parseString('mixed'))
);
$this->markTestIncomplete('This should work in the future');
// @todo in the future this should also work
/*
$this->assertEquals(
'MyObject|true',
(string) TypeChecker::reconcileTypes('!empty', Type::parseString('MyObject|bool'))
);
*/
}
public function testNull()