1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00
psalm/tests/SwitchTypeTest.php

127 lines
3.4 KiB
PHP
Raw Normal View History

2016-12-06 19:49:57 +01:00
<?php
namespace Psalm\Tests;
class SwitchTypeTest extends TestCase
2016-12-06 19:49:57 +01:00
{
use Traits\FileCheckerInvalidCodeParseTestTrait;
use Traits\FileCheckerValidCodeParseTestTrait;
2016-12-06 19:49:57 +01:00
/**
* @return array
2016-12-06 19:49:57 +01:00
*/
public function providerFileCheckerValidCodeParse()
2016-12-06 19:49:57 +01:00
{
return [
'getClassArg' => [
'<?php
class A {
/**
* @return void
*/
public function fooFoo() {
}
}
class B {
/**
* @return void
*/
public function barBar() {
}
}
$a = rand(0, 10) ? new A() : new B();
switch (get_class($a)) {
case "A":
$a->fooFoo();
break;
case "B":
$a->barBar();
break;
}'
],
'getTypeArg' => [
'<?php
function testInt(int $var) : void {
}
function testString(string $var) : void {
}
$a = rand(0, 10) ? 1 : "two";
switch (gettype($a)) {
case "string":
testString($a);
break;
case "int":
testInt($a);
break;
}'
]
];
2016-12-06 19:49:57 +01:00
}
2017-01-13 20:07:23 +01:00
/**
* @return array
2017-01-13 20:07:23 +01:00
*/
public function providerFileCheckerInvalidCodeParse()
2016-12-06 19:49:57 +01:00
{
return [
'getClassArgWrongClass' => [
'<?php
class A {
/** @return void */
public function fooFoo() {
}
}
class B {
/** @return void */
public function barBar() {
}
}
$a = rand(0, 10) ? new A() : new B();
switch (get_class($a)) {
case "A":
$a->barBar();
break;
}',
'error_message' => 'UndefinedMethod'
],
'getTypeArgWrongArgs' => [
'<?php
function testInt(int $var) : void {
}
function testString(string $var) : void {
}
$a = rand(0, 10) ? 1 : "two";
switch (gettype($a)) {
case "string":
testInt($a);
case "int":
testString($a);
}',
'error_message' => 'InvalidScalarArgument'
]
];
2016-12-06 19:49:57 +01:00
}
}