★ wanayoo — archive 1999 https://github.com/phpab/phpab/pull/85Nouvelle recherche | Portail wanayoo
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

Test closure in DB DataCollector #85

Merged
merged 4 commits into from May 1, 2016
Merged

Test closure in DB DataCollector #85

merged 4 commits into from May 1, 2016

Conversation

@pachico
Copy link
Member

@pachico pachico commented Apr 26, 2016

As in #83, too much is happening inside DataCollectors without being tested nor having their inputs validated.
This is an attempt to fix that.

Mariano F.co Benítez Mulet
@pachico pachico added the help wanted label Apr 26, 2016
@HellPat
Copy link
Contributor

@HellPat HellPat commented Apr 26, 2016

I'm not sure about this.

Here the conversation from gitter. @waltertamboer maybe we need your input here.

Patrick @psren 23:22
I’m not sure about all the assertions in your branch.
The Event-Subscribers are for the specific events of the implementation of Engine. And so they can safely rely on the parametes passed by the events.
I’d rather vote for testing if the events are getting fired with the correct parameters in our Engine implementation

Mariano Benítez Mulet @pachico 23:22
I see, I didn't take in consideration that Engine might change
but somehow, that implies that a lot of functionality will become either coupled or untested

Patrick @psren 23:25
Coupled to Engine, yes. But Engine will most likely not change, and if so it should comply to the tests. I’m not sure about that.
We could use a callback instead of a closure and then call_user_func_array that thing in our EventSubscriber

@waltertamboer
Copy link
Member

@waltertamboer waltertamboer commented Apr 28, 2016

So I'm trying to understand the problem. We have this type of code where the callback is not covered in the unit tests, am I right?

<?php

class DataCollector implements SubscriberInterface
{
    public function getSubscribedEvents()
    {
        return [
            '...' => function ($options) {
                // This is not covered in the unit test.
            },
        ];
    }
}

We could simply change it to:

<?php

class DataCollector implements SubscriberInterface
{
    public function getSubscribedEvents()
    {
        return [
            '...' => [$this, 'onAction'],
        ];
    }

    public function onAction($options)
    {
        // This can now be covered.
        // It's common sense to never call an on* method.
    }
}
@HellPat
Copy link
Contributor

@HellPat HellPat commented Apr 28, 2016

Correct @waltertamboer

@waltertamboer
Copy link
Member

@waltertamboer waltertamboer commented Apr 28, 2016

So can we just make it a public method? That would solve the problem.

@pachico
Copy link
Member Author

@pachico pachico commented Apr 28, 2016

Seems like a good approach, indeed

@pachico
Copy link
Member Author

@pachico pachico commented Apr 29, 2016

I changed my mind.
Honestly we don't solve anything with this since the problem wasn't that we COULDN'T cover that functionality, simply that we DIDN'T.
The test implemented in this PR would be exactly the one you'd need for this approach.
The objections were about the assertions rather than the closure.

Mariano F.co Benítez Mulet added 3 commits May 1, 2016
Mariano F.co Benítez Mulet
Mariano F.co Benítez Mulet
Mariano F.co Benítez Mulet
@pachico pachico merged commit 5297180 into master May 1, 2016
3 checks passed
3 checks passed
Scrutinizer 1 updated code elements
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
@pachico pachico deleted the test/DBDataCollector branch May 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.