Skip to content

Commit

Permalink
Support for array type in ParamConverter.
Browse files Browse the repository at this point in the history
  • Loading branch information
jingu committed Nov 9, 2023
1 parent 02ad56d commit dfb9078
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/ToScalarInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@

interface ToScalarInterface
{
public function toScalar(): bool|string|int|float;
/** @return scalar|array<int,scalar> */
public function toScalar(): bool|string|int|float|array;
}
12 changes: 12 additions & 0 deletions tests/Fake/FakeArray.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Ray\MediaQuery;

class FakeArray implements ToScalarInterface
{
/** @return array<int,int> */
public function toScalar(): array
{
return [0, 1];
}
}
14 changes: 12 additions & 2 deletions tests/ParamConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,19 @@ class ParamConverterTest extends TestCase
{
public function testInvoke(): void
{
$values = ['date_val' => new UnixEpocTime(), 'bool_val' => new FakeBool(), 'string_val' => new FakeString()];
$values = [
'date_val' => new UnixEpocTime(),
'bool_val' => new FakeBool(),
'string_val' => new FakeString(),
'array_val' => new FakeArray(),
];
(new ParamConverter())($values);
$this->assertSame(['date_val' => UnixEpocTime::TEXT, 'bool_val' => true, 'string_val' => 'a'], $values);
$this->assertSame([
'date_val' => UnixEpocTime::TEXT,
'bool_val' => true,
'string_val' => 'a',
'array_val' => [0, 1],
], $values);
}

public function testInvalidParam(): void
Expand Down

0 comments on commit dfb9078

Please sign in to comment.