@mnapoli opened this Pull Request on March 15th 2015 Member

In order to add tests for #7429 I added a way to provide DI configuration in test fixtures. This DI config is then applied to Piwik while running during the UI tests (like the "test environment" variables that allow to edit the INI config). That's really cool because then we can override any config/service to mock it.

Here is an example where I replace a service with a mock:

class FailUpdateHttpsFixture extends Fixture
{
    public function provideContainerConfig()
    {
        return array(
            'Piwik\Plugins\CoreUpdater\Updater' => \DI\object('Piwik\Plugins\CoreUpdater\Test\Mock\UpdaterMock'),
        );
    }
}

To provide DI config, a fixture has to implement provideContainerConfig() and return an array of config.
#7429 is based on this PR so it should be merged for 2.12 (and before #7429).

@diosmosis commented on March 15th 2015 Member

:+1: next step would be to allow this method to be use in IntegrationTestCase/SystemTestCase (and maybe unit tests, not sure how though).

@mnapoli commented on March 15th 2015 Member

In unit tests (and maybe integration tests) I tend to build the environment in the test (i.e. create the container with the config) because there are no separate PHP processes involved.

In system tests it could indeed be interesting!

@diosmosis commented on March 15th 2015 Member

Integration tests sometimes use fixtures, so they might need to override DI. Not sure though...

@mnapoli commented on March 15th 2015 Member

OK! Anyway that will be the same thing as for system test so no problem for that.

@diosmosis commented on March 15th 2015 Member

Cool :)

@mattab commented on March 15th 2015 Owner

Could you add documentation (even small) about using DI in Screenshot tests in this file: http://developer.piwik.org/guides/tests-ui#manipulating-the-test-environment ?

Besides missing doc, looks good to me!

@mnapoli commented on March 16th 2015 Member
@mattab commented on March 16th 2015 Owner

Question: I didn't merge the pull request myself, but it got merged and it says I merged it. Is it because i merged the other PR in #7429 and it automatically merged this one (somehow) ? I don't get this

@mattab commented on March 16th 2015 Owner
@mnapoli commented on March 16th 2015 Member

@mattab yes when the other PR was merged the commit here was too. I didn't think of that but that's actually simpler than merging the PRs in the correct order, good to know for next time ;)

This Pull Request was closed on March 16th 2015
Powered by GitHub Issue Mirror