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

isInTestingEnvironment function is not working with php artisan config:cache #537

Closed
ivankolodii opened this issue Jun 26, 2018 · 7 comments
Labels

Comments

@ivankolodii
Copy link

protected function isInTestingEnvironment()
{
        return getenv('CASHIER_ENV') === 'testing';
}

If you use php artisan config:cache this function will always return null according to https://laravel.com/docs/5.6/configuration#configuration-caching.

Config file should be created and used via config('cashier.env')

P.S. Still don't understand purpose of this function. Value testing should be used on production too.

@driesvints
Copy link
Member

I cannot see why you would use testing in production. Your production environment is for live keys only. This method shouldn't be used in combination with caching your config.

@ivankolodii
Copy link
Author

Stripe Webhook controller is using that method.

public function handleWebhook(Request $request)
    {
        $payload = json_decode($request->getContent(), true);

        if (! $this->isInTestingEnvironment() && ! $this->eventExistsOnStripe($payload['id'])) {
            return;
        }

        $method = 'handle'.studly_case(str_replace('.', '_', $payload['type']));

        if (method_exists($this, $method)) {
            return $this->{$method}($payload);
        } else {
            return $this->missingMethod();
        }
    }

@driesvints
Copy link
Member

@ivankolodii ah sorry, gotcha. But the same remark stands. On production this will simply default to false.

@fbingha
Copy link

fbingha commented Nov 2, 2018

You should fix this since caching configuration is a valid option in a testing environment.

There is an issue on Windows Apache when using multiple projects under the same server. When one project is calling the api of a second project, the configuration of one project is read by the second project. Since the standard line to resolve this is "cache your config" then you should fix the problem here so I don't have to overwrite isInTestingEnvironment to not use getenv.

"To clear things up; this is a known issue. It's just not documented.

You must run php artisan config:cache in both Laravel projects to generate a cached configuration. This is a requirement for Apache on Windows (and many other setups)."

laravel/framework#19990
laravel/framework#21533
laravel/framework#20207
laravel/framework#19454
laravel/framework#13906
laravel/framework#8191

If you attended Laracon 2018 then surely you heard when Taylor said to not call getenv() in your code.

@driesvints
Copy link
Member

Heya @fbingha. Thanks for bringing this to my attention. I'll re-open this to have another look at a later time. In the meantime feel free to send in a PR which might be able to fix this.

@driesvints
Copy link
Member

I've sent in a proposal which refactors the way we tackle this problem. Please have a look and let me know what you think: #591

@driesvints
Copy link
Member

The behavior for this has been changed in 9.0 which will be released soon. An upgrade guide will be provided.

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

No branches or pull requests

3 participants