2016-12-24 00:52:34 +01:00
|
|
|
<?php
|
|
|
|
namespace Psalm\Tests;
|
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
class BinaryOperationTest extends TestCase
|
2016-12-24 00:52:34 +01:00
|
|
|
{
|
2017-04-25 05:45:02 +02:00
|
|
|
use Traits\FileCheckerInvalidCodeParseTestTrait;
|
|
|
|
use Traits\FileCheckerValidCodeParseTestTrait;
|
2016-12-24 00:52:34 +01:00
|
|
|
|
|
|
|
/**
|
2017-04-25 05:45:02 +02:00
|
|
|
* @return array
|
2016-12-24 00:52:34 +01:00
|
|
|
*/
|
2017-04-25 05:45:02 +02:00
|
|
|
public function providerFileCheckerValidCodeParse()
|
2016-12-24 00:52:34 +01:00
|
|
|
{
|
2017-04-25 05:45:02 +02:00
|
|
|
return [
|
|
|
|
'regularAddition' => [
|
|
|
|
'<?php
|
2017-05-27 02:05:57 +02:00
|
|
|
$a = 5 + 4;',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'differingNumericTypesAdditionInWeakMode' => [
|
|
|
|
'<?php
|
2017-05-27 02:05:57 +02:00
|
|
|
$a = 5 + 4.1;',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'numericAddition' => [
|
|
|
|
'<?php
|
|
|
|
$a = "5";
|
|
|
|
|
|
|
|
if (is_numeric($a)) {
|
|
|
|
$b = $a + 4;
|
2017-05-27 02:05:57 +02:00
|
|
|
}',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'concatenation' => [
|
|
|
|
'<?php
|
2017-05-27 02:05:57 +02:00
|
|
|
$a = "Hey " . "Jude,";',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'concatenationWithNumberInWeakMode' => [
|
|
|
|
'<?php
|
2017-05-27 02:05:57 +02:00
|
|
|
$a = "hi" . 5;',
|
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
];
|
2016-12-24 00:52:34 +01:00
|
|
|
}
|
|
|
|
|
2017-01-13 20:07:23 +01:00
|
|
|
/**
|
2017-04-25 05:45:02 +02:00
|
|
|
* @return array
|
2017-01-13 20:07:23 +01:00
|
|
|
*/
|
2017-04-25 05:45:02 +02:00
|
|
|
public function providerFileCheckerInvalidCodeParse()
|
2016-12-24 00:52:34 +01:00
|
|
|
{
|
2017-04-25 05:45:02 +02:00
|
|
|
return [
|
|
|
|
'badAddition' => [
|
|
|
|
'<?php
|
|
|
|
$a = "b" + 5;',
|
2017-05-27 02:05:57 +02:00
|
|
|
'error_message' => 'InvalidOperand',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'differingNumericTypesAdditionInStrictMode' => [
|
|
|
|
'<?php
|
|
|
|
$a = 5 + 4.1;',
|
|
|
|
'error_message' => 'InvalidOperand',
|
|
|
|
'error_levels' => [],
|
2017-05-27 02:05:57 +02:00
|
|
|
'strict_mode' => true,
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'concatenationWithNumberInStrictMode' => [
|
|
|
|
'<?php
|
|
|
|
$a = "hi" . 5;',
|
|
|
|
'error_message' => 'InvalidOperand',
|
|
|
|
'error_levels' => [],
|
2017-05-27 02:05:57 +02:00
|
|
|
'strict_mode' => true,
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'addArrayToNumber' => [
|
|
|
|
'<?php
|
|
|
|
$a = [1] + 1;',
|
|
|
|
'error_message' => 'InvalidOperand',
|
|
|
|
'error_levels' => [],
|
2017-05-27 02:05:57 +02:00
|
|
|
'strict_mode' => true,
|
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
];
|
2016-12-24 00:52:34 +01:00
|
|
|
}
|
|
|
|
}
|