Skip to content

Commit 2dbb3d6

Browse files
committed
test action variadic
1 parent e8db62d commit 2dbb3d6

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed

tests/ActionVariadicTest.php

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
/*
4+
* This file is part of Chevere.
5+
*
6+
* (c) Rodolfo Berrios <rodolfo@chevere.org>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Chevere\Tests;
15+
16+
use Chevere\Tests\src\ActionTestVariadic;
17+
use PHPUnit\Framework\TestCase;
18+
19+
final class ActionVariadicTest extends TestCase
20+
{
21+
public function testNamed(): void
22+
{
23+
$result = (new ActionTestVariadic())
24+
(id: 1, foo: 'super', bar: 'taldo');
25+
$this->assertSame(
26+
[
27+
'id' => 1,
28+
'name' => [
29+
'foo' => 'super',
30+
'bar' => 'taldo',
31+
],
32+
],
33+
$result
34+
);
35+
}
36+
37+
public function testNamedSome(): void
38+
{
39+
$result = (new ActionTestVariadic())
40+
(1, 'super', bar: 'taldo');
41+
$this->assertSame(
42+
[
43+
'id' => 1,
44+
'name' => [
45+
0 => 'super',
46+
'bar' => 'taldo',
47+
],
48+
],
49+
$result
50+
);
51+
}
52+
53+
public function testPositional(): void
54+
{
55+
$result = (new ActionTestVariadic())
56+
(1);
57+
$this->assertSame(
58+
[
59+
'id' => 1,
60+
'name' => [],
61+
],
62+
$result
63+
);
64+
}
65+
66+
public function testPositionalSome(): void
67+
{
68+
$result = (new ActionTestVariadic())
69+
(1, 'super', 'taldo');
70+
$this->assertSame(
71+
[
72+
'id' => 1,
73+
'name' => [
74+
'super',
75+
'taldo',
76+
],
77+
],
78+
$result
79+
);
80+
}
81+
}

tests/src/ActionTestVariadic.php

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/*
4+
* This file is part of Chevere.
5+
*
6+
* (c) Rodolfo Berrios <rodolfo@chevere.org>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Chevere\Tests\src;
15+
16+
use Chevere\Action\Action;
17+
18+
final class ActionTestVariadic extends Action
19+
{
20+
public function main(
21+
int $id,
22+
string ...$name
23+
): array {
24+
return get_defined_vars();
25+
}
26+
}

0 commit comments

Comments
 (0)