1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00
psalm/tests/BinaryOperationTest.php
Jon Ursenbach 11bc153deb Rewriting and streamlining every unit test with data providers. (#147)
* Rewriting and streamlining every unit test with data providers.

All unit tests have been rewritten into PHPUnit data providers
to reduce the amount of unnecessary code-reuse through out the
test suite.
2017-04-24 23:45:02 -04:00

77 lines
2.0 KiB
PHP

<?php
namespace Psalm\Tests;
class BinaryOperationTest extends TestCase
{
use Traits\FileCheckerInvalidCodeParseTestTrait;
use Traits\FileCheckerValidCodeParseTestTrait;
/**
* @return array
*/
public function providerFileCheckerValidCodeParse()
{
return [
'regularAddition' => [
'<?php
$a = 5 + 4;'
],
'differingNumericTypesAdditionInWeakMode' => [
'<?php
$a = 5 + 4.1;'
],
'numericAddition' => [
'<?php
$a = "5";
if (is_numeric($a)) {
$b = $a + 4;
}'
],
'concatenation' => [
'<?php
$a = "Hey " . "Jude,";'
],
'concatenationWithNumberInWeakMode' => [
'<?php
$a = "hi" . 5;'
]
];
}
/**
* @return array
*/
public function providerFileCheckerInvalidCodeParse()
{
return [
'badAddition' => [
'<?php
$a = "b" + 5;',
'error_message' => 'InvalidOperand'
],
'differingNumericTypesAdditionInStrictMode' => [
'<?php
$a = 5 + 4.1;',
'error_message' => 'InvalidOperand',
'error_levels' => [],
'strict_mode' => true
],
'concatenationWithNumberInStrictMode' => [
'<?php
$a = "hi" . 5;',
'error_message' => 'InvalidOperand',
'error_levels' => [],
'strict_mode' => true
],
'addArrayToNumber' => [
'<?php
$a = [1] + 1;',
'error_message' => 'InvalidOperand',
'error_levels' => [],
'strict_mode' => true
]
];
}
}