Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
21 / 21 |
|
100.00% |
1 / 1 |
CRAP | n/a |
0 / 0 |
|
| getConcreteController | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | // ╔════════════════════════════════════════════════════════════╗ |
| 4 | // ║ MIT Licence (#Expat) - https://opensource.org/licenses/MIT ║ |
| 5 | // ║ Copyright 2026 Frederic Poeydomenge <dyno@phexium.com> ║ |
| 6 | // ╚════════════════════════════════════════════════════════════╝ |
| 7 | |
| 8 | declare(strict_types=1); |
| 9 | |
| 10 | use Nyholm\Psr7\ServerRequest; |
| 11 | use Phexium\Application\AbstractController; |
| 12 | use Psr\Http\Message\ServerRequestInterface; |
| 13 | |
| 14 | function getConcreteController(): AbstractController |
| 15 | { |
| 16 | return new readonly class extends AbstractController { |
| 17 | public function exposeExtractFormData(ServerRequestInterface $request, array $defaults): array |
| 18 | { |
| 19 | return $this->extractFormData($request, $defaults); |
| 20 | } |
| 21 | }; |
| 22 | } |
| 23 | |
| 24 | test('extractFormData() extracts form data with defaults', function (): void { |
| 25 | $controller = getConcreteController(); |
| 26 | |
| 27 | $request = new ServerRequest('POST', '/')->withParsedBody((object) [ |
| 28 | 'title' => 'Test Book', |
| 29 | 'author' => 'John Doe', |
| 30 | ]); |
| 31 | |
| 32 | $defaults = [ |
| 33 | 'title' => '', |
| 34 | 'author' => '', |
| 35 | 'isbn' => '123456789', |
| 36 | ]; |
| 37 | |
| 38 | $result = $controller->exposeExtractFormData($request, $defaults); |
| 39 | |
| 40 | expect($result)->toBe([ |
| 41 | 'title' => 'Test Book', |
| 42 | 'author' => 'John Doe', |
| 43 | 'isbn' => '123456789', |
| 44 | ]); |
| 45 | }); |