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

Move constant tests

This commit is contained in:
Brown 2020-02-07 10:47:42 -05:00
parent 4e36f6caf5
commit cecc5ed798
2 changed files with 89 additions and 89 deletions

View File

@ -568,6 +568,59 @@ class ConstantTest extends TestCase
return (self::LOOKUP[strtoupper($code)] ?? null) === self::SUCCEED; return (self::LOOKUP[strtoupper($code)] ?? null) === self::SUCCEED;
} }
}' }'
],
'keyOf' => [
'<?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(1);
A::foo(2);
A::foo(3);',
],
'valueOf' => [
'<?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("a");
A::bar("b");
A::bar("c");',
],
'valueOfDefault' => [
'<?php
class A {
const C = [
1 => "a",
2 => "b",
3 => "c"
];
/**
* @var value-of<self::C>
*/
public $foo = "a";
}',
], ],
]; ];
} }
@ -701,6 +754,42 @@ class ConstantTest extends TestCase
}', }',
'error_message' => 'CircularReference' 'error_message' => 'CircularReference'
], ],
'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',
],
]; ];
} }
} }

View File

@ -593,59 +593,6 @@ class ValueTest extends TestCase
} }
', ',
], ],
'keyOf' => [
'<?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(1);
A::foo(2);
A::foo(3);',
],
'valueOf' => [
'<?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("a");
A::bar("b");
A::bar("c");',
],
'valueOfDefault' => [
'<?php
class A {
const C = [
1 => "a",
2 => "b",
3 => "c"
];
/**
* @var value-of<self::C>
*/
public $foo = "a";
}',
],
'supportSingleLiteralType' => [ 'supportSingleLiteralType' => [
'<?php '<?php
class A { class A {
@ -874,42 +821,6 @@ class ValueTest extends TestCase
}', }',
'error_message' => 'RedundantCondition', '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',
],
'casedComparison' => [ 'casedComparison' => [
'<?php '<?php
if ("C" === "c") {}', if ("C" === "c") {}',