Skip to content

Commit 7f9dbf2

Browse files
committed
test more const array variants
1 parent a1e5a19 commit 7f9dbf2

File tree

2 files changed

+118
-0
lines changed

2 files changed

+118
-0
lines changed

tests/Rules/PHPUnit/DataProviderDataRuleTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,22 @@ public function testRule(): void
171171
'Parameter #2 $input of method DataProviderDataTest\AbstractBaseTest::testWithAttribute() expects string, false given.',
172172
461,
173173
],
174+
[
175+
'Parameter #2 $input of method DataProviderDataTest\ConstantArrayUnionTypeReturnTest::testFoo() expects string, int given.',
176+
505,
177+
],
178+
[
179+
'Method DataProviderDataTest\ConstantArrayDifferentLengthUnionTypeReturnTest::testFoo() invoked with 3 parameters, 2 required.',
180+
543,
181+
],
182+
[
183+
'Parameter #2 $input of method DataProviderDataTest\ConstantArrayDifferentLengthUnionTypeReturnTest::testFoo() expects string, int given.',
184+
543,
185+
],
186+
[
187+
'Parameter #2 $input of method DataProviderDataTest\ConstantArrayUnionWithDifferentValueTypeReturnTest::testFoo() expects string, int|string given.',
188+
576,
189+
],
174190
]);
175191
}
176192

tests/Rules/PHPUnit/data/data-provider-data.php

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,3 +474,105 @@ static public function aProvider(): array
474474
];
475475
}
476476
}
477+
478+
479+
class ConstantArrayUnionTypeReturnTest extends TestCase
480+
{
481+
482+
/** @dataProvider aProvider */
483+
public function testFoo(string $expectedResult, string $input): void
484+
{
485+
}
486+
487+
public function aProvider(): array
488+
{
489+
if (rand(0,1)) {
490+
$arr = [
491+
[
492+
'Hello World',
493+
123
494+
]
495+
];
496+
} else {
497+
$arr = [
498+
[
499+
'Hello World',
500+
" Hello World \n"
501+
]
502+
];
503+
}
504+
505+
return $arr;
506+
}
507+
}
508+
509+
class ConstantArrayDifferentLengthUnionTypeReturnTest extends TestCase
510+
{
511+
512+
/** @dataProvider aProvider */
513+
public function testFoo(string $expectedResult, string $input): void
514+
{
515+
}
516+
517+
public function aProvider(): array
518+
{
519+
if (rand(0,1)) {
520+
$arr = [
521+
[
522+
'Hello World',
523+
123
524+
]
525+
];
526+
} elseif (rand(0,1)) {
527+
$arr = [
528+
[
529+
'Hello World',
530+
'Hello World',
531+
]
532+
];
533+
} else {
534+
$arr = [
535+
[
536+
'Hello World',
537+
" Hello World \n",
538+
" Too much \n",
539+
]
540+
];
541+
}
542+
543+
return $arr;
544+
}
545+
}
546+
547+
class ConstantArrayUnionWithDifferentValueTypeReturnTest extends TestCase
548+
{
549+
550+
/** @dataProvider aProvider */
551+
public function testFoo(string $expectedResult, string $input): void
552+
{
553+
}
554+
555+
public function aProvider(): array
556+
{
557+
if (rand(0,1)) {
558+
$arr = [
559+
[
560+
'Hellooo',
561+
' World',
562+
]
563+
];
564+
} else {
565+
$a = rand(0,1) ? 'Hello' : 'World';
566+
$b = rand(0,1) ? " Hello World \n" : 123;
567+
568+
$arr = [
569+
[
570+
$a,
571+
$b
572+
]
573+
];
574+
}
575+
576+
return $arr;
577+
}
578+
}

0 commit comments

Comments
 (0)