igniphp / framework

Swoole, PSR-15, PSR-7, PSR-11 lightweight modular anti-framework for REST micro-services.
MIT License
265 stars 14 forks source link

In tests not possible to pass attributes by example #29

Closed roquie closed 5 years ago

roquie commented 5 years ago

https://github.com/igniphp/framework/tree/master/docs#testing

In the following example, name attribute does not correctly passing to ServerRequest object.

public function testWelcome(): void
    {
        $controller = new WelcomeUserController();
        $response = $controller(new ServerRequest('/hi/Tom'));

        self::assertSame('Hi Tom!', (string) $response->getBody());
        self::assertSame(200, $response->getStatusCode());
    }

Solution:

public function testWelcome(): void
    {
        $controller = new WelcomeUserController();
        $response = $controller((new ServerRequest('/hi/Tom'))->withAttribute('name', 'Tom'));

        self::assertSame('Hi Tom!', (string) $response->getBody());
        self::assertSame(200, $response->getStatusCode());
    }

P.S. This is a WIP issue. I will update it soon.

dkraczkowski commented 5 years ago

@roquie You are right, I will fix the example soon.

roquie commented 5 years ago

It's normal when it passes not automatically? The solution in docs is more pretty and short :)

dkraczkowski commented 5 years ago

@roquie Yeah its normal because it does not go through the framework, so you are actually passing just a request object and you get the same one in the controller.

roquie commented 5 years ago

Hmm, maybe set up something for testing?