Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature testing with ->get or ->json doesn't pass include string to Manager #42

Open
jminkler opened this issue Aug 28, 2017 · 4 comments

Comments

@jminkler
Copy link

Steps to reproduce

  1. When Testing endpoint, request a response with include
    $json = $this->actingAs($user, 'customer') ->json('GET','v2/customer', ['include'=>'cart']) ->assertJson([ 'data' => [ 'cart' => [ 'data' => [] ] ], ]);

Expected behaviour

Response should assert the 'cart' include, which works if I hit it with postman for example.

Actual behaviour

None of the includes, except the defaults are included

@maximebeaudoin
Copy link
Member

@jminkler
Copy link
Author

Yeah, seems to be duplicate.

@jminkler
Copy link
Author

However, I am not having much luck with the Trait

I get:
Call to undefined method Feature\CartTest::resetPageContext()

Digging into the 5.4.35 Illuminate\Foundation\Testing\Concerns\MakesHttpRequests::call I see it may have changed from what the Trait does.

Tried putting this into TestCase:
`public function call($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null)
{
$kernel = $this->app->make(HttpKernel::class);

    $files = array_merge($files, $this->extractFilesFromDataArray($parameters));

    $symfonyRequest = SymfonyRequest::create(
        $this->prepareUrlForRequest($uri), $method, $parameters,
        $cookies, $files, array_replace($this->serverVariables, $server), $content
    );

    $response = app(\EllipseSynergie\ApiResponse\Contracts\Response::class);

    $response
       ->getManager()
       ->parseIncludes(explode(',', $symfonyRequest->get('include')));

    $response = $kernel->handle($symfonyRequest);

    $kernel->terminate($request, $response);

    return $this->createTestResponse($response);
}`

But getting:
testing.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Call to undefined method Symfony\Component\HttpFoundation\Request::setUserResolver()' in /var/www/html/api/vendor/laravel/framework/src/Illuminate/Auth/AuthServiceProvider.php:85 Stack trace: #0 {main}

Stuck a bit here

@jminkler
Copy link
Author

jminkler commented Aug 28, 2017

I see what I did

Final call()

`public function call($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null)
{
$kernel = $this->app->make(HttpKernel::class);

    $files = array_merge($files, $this->extractFilesFromDataArray($parameters));

    $symfonyRequest = SymfonyRequest::create(
        $this->prepareUrlForRequest($uri), $method, $parameters,
        $cookies, $files, array_replace($this->serverVariables, $server), $content
    );

    $request = Request::createFromBase($symfonyRequest);

    $response = app(\EllipseSynergie\ApiResponse\Contracts\Response::class);

    $response
       ->getManager()
       ->parseIncludes(explode(',', $request->get('include')));

    $response = $kernel->handle($request);

    $kernel->terminate($request, $response);

    return $this->createTestResponse($response);
}`

Actually have no idea how this works since $response gets reset ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants