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

Control proxy implementation via env #10282

Merged
merged 1 commit into from
Dec 10, 2022

Conversation

derrabus
Copy link
Member

Our test suite is currently run with the lazy ghost implementation if the var-exporter component is installed. In our CI, we install the component if we want to test the lazy ghost implementation.

This is a bit brittle given that Symfony Cache depends on VarExporter, so the component will be installed no matter what. Also, if I want to run tests locally, it's a bit annoying that I have to install the component and live with local changes in my composer.json.

With this PR, I'm adding VarExporter to the dev requirements. I'm introducing an environment variable ORM_PROXY_IMPLEMENTATION which allows us to control the proxy implementation that should be used by the tests.

@derrabus derrabus added this to the 2.14.0 milestone Dec 10, 2022
@derrabus derrabus requested a review from greg0ire December 10, 2022 15:51
@derrabus
Copy link
Member Author

cc @nicolas-grekas

@derrabus derrabus force-pushed the improvement/proxy-tests branch from 5babe01 to d7f71fc Compare December 10, 2022 15:56
$configuration->setProxyNamespace('Doctrine\Tests\Proxies');

$proxyImplementation = $_ENV['ORM_PROXY_IMPLEMENTATION']
?? $_SERVER['ORM_PROXY_IMPLEMENTATION']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this fallback to $_SERVER needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some SAPIs store environment variables in $_ENV, some in $_SERVER. But since we're not dealing with any SAPI other than CLI, I can probably remove it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, on CLI, environment variables are stored in $_SERVER. I think I might just switch to getenv(). 🤦🏻

Copy link
Member

@greg0ire greg0ire Dec 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember stuggling with that myself in the past, and it seems to be quite a mess: https://www.php.net/manual/en/ini.core.php#ini.variables-order

getenv() seems like a good idea 👍

?? null;

if (! $proxyImplementation) {
$proxyImplementation = trait_exists(LazyGhostTrait::class) ? 'lazy-ghost' : 'common';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not add an new ?? line with that ternary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I also want the fallback to kick in if the environment variable has been set to an empty string.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we do that? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because unsetting environment variables is hard. If you're dealing with enviroment variables, you should always treat the empty string as if the variable wasn't set.

Fun fact: I did not take the empty string into account at first which made the CI fail: https://github.com/doctrine/orm/actions/runs/3664887468/jobs/6195591631

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, where are we unsetting that environment variable? And is that not as simple as putenv('MYVAR')?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, where are we unsetting that environment variable?

We aren't, but e.g. Github Actions needs to do that.

@derrabus derrabus force-pushed the improvement/proxy-tests branch from d7f71fc to 94823fe Compare December 10, 2022 17:01
@derrabus derrabus merged commit 3ea8550 into doctrine:2.14.x Dec 10, 2022
@derrabus derrabus deleted the improvement/proxy-tests branch December 10, 2022 17:11
derrabus added a commit to derrabus/orm that referenced this pull request Dec 10, 2022
* 2.14.x:
  Control proxy implementation via env (doctrine#10282)
derrabus added a commit to derrabus/orm that referenced this pull request Dec 10, 2022
* 2.14.x:
  Control proxy implementation via env (doctrine#10282)
  Fix association mapping with enum fields
  Correct spelling errors
n-e-m-a-nj-a pushed a commit to n-e-m-a-nj-a/orm that referenced this pull request Jan 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants