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

Fix test ServerRequestTest::testGetUploadedFiles #109

Merged
merged 1 commit into from
Aug 2, 2019

Conversation

danopz
Copy link
Member

@danopz danopz commented Aug 1, 2019

Fixed an unit tests which was suddenly failing on my local machine for reason:

There was 1 error:

  1. Slim\Tests\Psr7\Integration\ServerRequestTest::testGetUploadedFiles
    RuntimeException: Could not create Stream. Check your config

/data/workspace/Slim-Psr7/vendor/php-http/psr7-integration-tests/src/BaseTest.php:111
/data/workspace/Slim-Psr7/vendor/php-http/psr7-integration-tests/src/ServerRequestIntegrationTest.php:83

@coveralls
Copy link

Coverage Status

Coverage remained the same at 99.731% when pulling 223117a on danopz:fix-unit-test into 8066cee on slimphp:master.

@akrabat
Copy link
Member

akrabat commented Aug 2, 2019

@danopz That's a fairly significant change. Any idea why?

@l0gicgate l0gicgate added this to the 0.4 milestone Aug 2, 2019
@l0gicgate l0gicgate merged commit 2ffa436 into slimphp:master Aug 2, 2019
@danopz
Copy link
Member Author

danopz commented Aug 2, 2019

@akrabat in general I can't tell why it was working before. As far as I can see there was no change in either of both libraries which changed some behaviour for this, so it should have been failing before.

protected function buildUploadableFile($data)
{
    if (defined('UPLOADED_FILE_FACTORY')) {
        $factoryClass = UPLOADED_FILE_FACTORY;
        $factory = new $factoryClass();
        if (!$factory instanceof \Psr\Http\Message\UploadedFileFactoryInterface) {
            throw new \RuntimeException('Constant "UPLOADED_FILE_FACTORY" must be a reference to a Psr\Http\Message\UploadedFileFactoryInterface');
        }

        $stream = $this->buildStream($data);

        return $factory->createUploadedFile($stream);
    }

    if (class_exists(GuzzleUploadedFile::class)) {
        return new GuzzleUploadedFile($data, strlen($data), 0);
    }

    if (class_exists(ZendUploadedFile::class)) {
        return new ZendUploadedFile($data, strlen($data), 0);
    }

    throw new \RuntimeException('Could not create Stream. Check your config');
}

Thats the function we want to overwrite here since we want to create our own objects for the tests. As it looks we (or I?) wrote a createUploadedFile like the one which is called from the UPLOADED_FILE_FACTORY.
But because we didn't use the constants here for setting own factories this function should have always thrown the error.

@danopz danopz deleted the fix-unit-test branch August 2, 2019 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants