-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[prevent-non-class-exceptions] add new test cases for skipping union …
…types
- Loading branch information
1 parent
bf4666b
commit 7037383
Showing
2 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
...s/Rule/CurrencyAvailableWithinToCurrenciesContainsRector/Fixture/skip_union_types.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Rector\Money\Tests\Rule\CurrencyAvailableWithinToCurrenciesContainsRector\Fixture; | ||
|
||
use Money\Currencies\CurrencyList; | ||
use Money\Currency; | ||
use function mt_rand; | ||
|
||
/** | ||
* @return Currency|array|false | ||
*/ | ||
function willReturnCurrencyOrSomethingDifferent() { | ||
$random = mt_rand(0, 10); | ||
if ($random % 3 === 0) { | ||
return new Currency('EUR'); | ||
} | ||
if ($random === 5) { | ||
return ['some' => 'other', 'data']; | ||
} | ||
return false; | ||
} | ||
|
||
$collection = new CurrencyList([new Currency('PLN')]); | ||
willReturnCurrencyOrSomethingDifferent() | ||
->isAvailableWithin($collection); | ||
|
||
?> | ||
|
45 changes: 45 additions & 0 deletions
45
tests/Rule/MultiplyAndDivideByStringRector/Fixture/skip_union_types.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace Rector\Money\Tests\Rule\MultiplyAndDivideByStringRector\Fixture; | ||
|
||
use Money\Currency; | ||
use Money\Money; | ||
use function mt_rand; | ||
|
||
function returnInt(): int | ||
{ | ||
return 1; | ||
} | ||
|
||
class UnionReturning | ||
{ | ||
/** | ||
* @return Money|array|false | ||
*/ | ||
public static function foo() | ||
{ | ||
$random = mt_rand(0, 10); | ||
if ($random % 3 === 0) { | ||
return new Money($random, new Currency('EUR')); | ||
} | ||
if ($random === 5) { | ||
return ['some' => 'other', 'data']; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* @return Money|array|false | ||
*/ | ||
public function bar() | ||
{ | ||
return self::foo(); | ||
} | ||
} | ||
|
||
$unionReturning = new UnionReturning(); | ||
$unionReturning->bar()->divide(1); | ||
$unionReturning->bar()->multiply(2); | ||
|
||
UnionReturning::foo()->divide(3); | ||
UnionReturning::foo()->multiply(4); |