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

Injection Inception, Change #6: Final cleanup of test environment setup #8027

Merged
merged 14 commits into from Jun 11, 2015

Conversation

diosmosis
Copy link
Member

This PR is based off of #8008

Changes:

  • Rename TestingEnvironment to TestingEnvironmentVariables, since that is really all it is for.
  • Remove TestingEnvironment::addHooks() and move to new environment manipulator (along w/ Environment.bootstrapped event observer in test.php).
  • Get rid of the TestingEnvironment test event TestingEnvironment.addHooks and replace w/ DI use.
  • Merge MockAccess w/ FakeAccess.
  • Resolve redundant Fixture/TestCase variable $loadTranslations (handled byTestingEnvironmentVariables.
  • Add custom definition source TestingEnvironmentVariablesDefinitionSource that allows accessing TestingEnvironmentVariables variables through DI. Also allows overriding these variables easily from within test case classes (via provideContainerConfig(BeforeClass)).

@diosmosis diosmosis added Pull Request WIP Indicates the current pull request is still work in progress and not ready yet for a review. c: Tests & QA For issues related to automated tests or making it easier to QA & test issues. labels Jun 1, 2015
@diosmosis diosmosis self-assigned this Jun 1, 2015
@diosmosis diosmosis added this to the 2.14.0 milestone Jun 1, 2015
@diosmosis diosmosis added Needs Review PRs that need a code review and removed Pull Request WIP Indicates the current pull request is still work in progress and not ready yet for a review. labels Jun 2, 2015
@diosmosis diosmosis force-pushed the test_env_di_8 branch 2 times, most recently from 3c8399b to 0453aaf Compare June 3, 2015 17:06
@diosmosis
Copy link
Member Author

After merging, QueuedTracking will have to be modified, as it still uses the TestingEnvironment.addHooks event.

@diosmosis
Copy link
Member Author

Looks like this PR depends on #8026, there are some odd access related failures. Waiting for that one.

}
}

private function getExtraDefinitionsFromManpulators()
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: getExtraDefinitionsFromManpulators -> getExtraDefinitionsFromManipulators

@mnapoli
Copy link
Contributor

mnapoli commented Jun 4, 2015

Coming back again on the topic of "environment manipulators": the interface comment says:

Only used by the testing environment setup code, shouldn't be used anywhere else.

So if I understand correctly:

  • we have an interface that is meant to be implemented only by one specific class
  • the Environment has an array of "manipulators" (link) whereas it should contain only one entry

If that's correct then maybe Environment could have a single object instead of an array, and we could get rid of the interface?


Regarding TestingEnvironmentVariablesDefinitionSource, it's a nice and clean implementation I'm happy to see that extending PHP-DI works so easily ;) However would it make more sense (i.e. simpler) to just take all the testing env variables, dump them into an array (and we add the prefix here) and just pass the array to be added to the container by the environment?

That would avoid the custom definition source + this custom code for tests in the ContainerFactory

@diosmosis
Copy link
Member Author

If that's correct then maybe Environment could have a single object instead of an array, and we could get rid of the interface?

We could just have one, I was hoping an array would look like less of a hack.

As for the interface, I think it's a good idea to keep it. Otherwise, Environment.php would reference a test file, namely the environment manipulator I added. I don't think application code should do that if possible.

However would it make more sense (i.e. simpler) to just take all the testing env variables, dump them into an array (and we add the prefix here) and just pass the array to be added to the container by the environment?

Where would this be done? Would we be able to override the vars in provideContainerConfig()?

Note: It would only avoid the lines that add the definition source.

@mnapoli
Copy link
Contributor

mnapoli commented Jun 5, 2015

Where would this be done? Would we be able to override the vars in provideContainerConfig()?

I'm not sure. But since the testing env manipulator does provide container entries to the environment (e.g. the entries defined in fixtures or test classes), it could also provide those entries through an array instead of a custom definition source? Maybe it's not possible, I was deep into the code yesterday but now I'm out of it and maybe it doesn't happen at the same time…

For the interface I'm OK to keep it I see your point with coupling the core code to test code, for the array of env manipulators I would say let's turn it into a single dependency it's that's ok with you? I'd rather keep this core code as simple as we can so that it's easy to understand

diosmosis added 4 commits June 5, 2015 13:04
…ddHooks() to a new EnvironmentManipulator. Remove MakeGlobalSettingsWithFile since it is now redundant.
@diosmosis
Copy link
Member Author

Maybe it's not possible, I was deep into the code yesterday but now I'm out of it and maybe it doesn't happen at the same time…

It's not easily possible it seems. Using a definition source, we can return null for variables that don't exist in the json file. Can't do that if we just add the variables in an array.

diosmosis added 2 commits June 5, 2015 14:35
…r. Add hook in EnvironmentManipulator to get extra environment names, and specify test environment this way instead of through detecting PIWIK_TEST_MODE.
…nvironmentManipulator instead of in ContainerFactory.php.
@diosmosis
Copy link
Member Author

Ready for another review.

@mnapoli
Copy link
Contributor

mnapoli commented Jun 10, 2015

Looks good to merge, except for the the Travis build: 2 failures in SystemTests: https://travis-ci.org/piwik/piwik/jobs/65642678#L524 Is it the random failure or something else?

@diosmosis
Copy link
Member Author

Ah those are queued tracking errors, I have to modify the plugin...

@diosmosis
Copy link
Member Author

QueuedTracking PR: matomo-org/plugin-QueuedTracking#8

The build won't pass, there's one failure left. I tried to fix it, but can't seem to figure out what the problem is.

diosmosis added a commit that referenced this pull request Jun 11, 2015
Injection Inception, Change #6: Final cleanup of test environment setup. Remove TestingEnvironment.addHooks event, make sure core doesn't depend on test files/classes/constants, integrate test environment variables w/ DI for easier overriding in tests, and related clean ups to test environment setup.
@diosmosis diosmosis merged commit ccef590 into master Jun 11, 2015
@diosmosis diosmosis deleted the test_env_di_8 branch June 11, 2015 02:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: Tests & QA For issues related to automated tests or making it easier to QA & test issues. Needs Review PRs that need a code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants