1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Add more tests for key-of/value-of

This commit is contained in:
Brown 2019-05-28 10:47:54 -04:00
parent 7df88197ef
commit f062f9bb75

View File

@ -606,7 +606,11 @@ class ValueTest extends TestCase
* @param key-of<A::C> $i
*/
public static function foo(int $i) : void {}
}'
}
A::foo(1);
A::foo(2);
A::foo(3);'
],
'valueOf' => [
'<?php
@ -621,7 +625,11 @@ class ValueTest extends TestCase
* @param value-of<A::C> $j
*/
public static function bar(string $j) : void {}
}'
}
A::bar("a");
A::bar("b");
A::bar("c");'
],
];
}
@ -798,6 +806,42 @@ class ValueTest extends TestCase
}',
'error_message' => 'RedundantCondition',
],
'keyOfBadValue' => [
'<?php
class A {
const C = [
1 => "a",
2 => "b",
3 => "c"
];
/**
* @param key-of<A::C> $i
*/
public static function foo(int $i) : void {}
}
A::foo(4);',
'error_message' => 'InvalidArgument'
],
'valueOfBadValue' => [
'<?php
class A {
const C = [
1 => "a",
2 => "b",
3 => "c"
];
/**
* @param value-of<A::C> $j
*/
public static function bar(string $j) : void {}
}
A::bar("d");',
'error_message' => 'InvalidArgument'
],
];
}
}