ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
PostDataFromServerRequestTestTBD.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once(__DIR__ . "/../../../../../../../../vendor/composer/vendor/autoload.php");
22
24use Psr\Http\Message\ServerRequestInterface;
25use PHPUnit\Framework\TestCase;
26
27class PostDataFromServerRequestTest extends TestCase
28{
30
31 public function setUp(): void
32 {
33 $request = Mockery::mock(ServerRequestInterface::class);
34 $request->shouldReceive("getParsedBody")->andReturn(["foo" => "bar"]);
35 $this->post_data = new PostDataFromServerRequest($request);
36 }
37
38 public function testGetSuccess(): void
39 {
40 $this->assertEquals("bar", $this->post_data->get("foo"));
41 }
42
43 public function testGetFail(): void
44 {
45 $raised = false;
46 try {
47 $this->post_data->get("baz");
48 } catch (LogicException $e) {
49 $raised = true;
50 }
51 $this->assertTrue($raised, "Logic exception was raised.");
52 }
53
54 public function testGetOrMatch(): void
55 {
56 $this->assertEquals("bar", $this->post_data->getOr("foo", "baz"));
57 }
58
59 public function testGetOrNoMatch(): void
60 {
61 $this->assertEquals("blaw", $this->post_data->getOr("baz", "blaw"));
62 }
63}
Implements interaction of input element with post data from psr-7 server request.