Giter Club home page Giter Club logo

Comments (9)

imjohnbon avatar imjohnbon commented on August 15, 2024

I temporarily switched to https://github.com/spatie/laravel-fractal to see if the issue would still persist, and it did. Which causes me to believe this may not be an issue with this package, and rather with Laravel or Fractal instead.

This is completely perplexing me at this point. I can't imagine why this would work in practice but fail during automated tests. Very odd. Would love to hear from the creator of this package to see if he ever successfully application tested relationships.

from api-response.

maximebeaudoin avatar maximebeaudoin commented on August 15, 2024

I'll try to take a look at it. Thank you for the report

from api-response.

maximebeaudoin avatar maximebeaudoin commented on August 15, 2024

@imjohnbon I found the problem, but not the solution for now.

The problem is simple, it's because the parsing is triggered on the boot method of the service provider like this : $manager->parseIncludes(explode(',', $this->app['Illuminate\Http\Request']->get('include'))); So at this point, when the http request occur, the content of the request is populate with the include value.

BUT, in the testing process, we are not doing the normal http request. Laravel doing a internal call via $this->call and the value of includes was already loaded and will NOT be refresh.

For now, the only way i see to resolve this is to replace the method in Illuminate\Foundation\Testing\Concerns\MakesHttpRequests::call by this code

    /**
     * Call the given URI and return the Response.
     *
     * @param  string  $method
     * @param  string  $uri
     * @param  array   $parameters
     * @param  array   $cookies
     * @param  array   $files
     * @param  array   $server
     * @param  string  $content
     * @return \Illuminate\Http\Response
     */
    public function call($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null)
    {
        $kernel = $this->app->make('Illuminate\Contracts\Http\Kernel');

        $this->currentUri = $this->prepareUrlForRequest($uri);

        $this->resetPageContext();

        $symfonyRequest = SymfonyRequest::create(
            $this->currentUri, $method, $parameters,
            $cookies, $this->filterFiles($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->response = $response;
    }

This code will intercept the new Request object and parse the include value.

Someday i may probably create some Trait to help people resolve that issue.

from api-response.

imjohnbon avatar imjohnbon commented on August 15, 2024

Thanks for the update! I figured it was something like that. Unfortunately editing core Laravel files isn't an option for me or most people I would assume. Hopefully one day this can be solved within the package.

from api-response.

maximebeaudoin avatar maximebeaudoin commented on August 15, 2024

@imjohnbon You just have to create your own call method in the TestCase class for now if you want a quick fix.

from api-response.

imjohnbon avatar imjohnbon commented on August 15, 2024

Ah of course, thanks for the tip!

from api-response.

mehrdad-shokri avatar mehrdad-shokri commented on August 15, 2024

@maximebeaudoin can provide a code snippet on hwo to create m own call method in TestCase

from api-response.

maximebeaudoin avatar maximebeaudoin commented on August 15, 2024

@mehrdaad I have create a trait to resolve this. https://github.com/ellipsesynergie/api-response/blob/master/src/Testing/Laravel/AddTestingSupportForInclude.php

from api-response.

mehrdad-shokri avatar mehrdad-shokri commented on August 15, 2024

@maximebeaudoin thanks, I had a suggestion for this trait, Could we convert call to a private function and create 3 or 4 protected functions like get, post etc to keep Laravel signature untouched?
One problem I can think of it that it would create confusion for the trait client.
Any suggestions?

from api-response.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.