Skip to content

Conversation

@jiripudil
Copy link
Contributor

I've found that if you want to return some more complex structures from a data provider or even do some other logic to it inbetween, generators seem to be a more convenient approach than arrays.

In my case, I need to test data validation of a third-party API, generating a valid request and breaking it in a lot of slightly different ways, and generators just seem to be much more expressive:

public function dataProvider()
{
    $request = $this->createValidRequest();
    unset($request['title']);
    yield [$request, 'Missing parameter title'];

    $request = $this->createValidRequest();
    unset($request['description']);
    yield [$request, 'Missing parameter description'];

    // ...
}

Copy link
Member

Choose a reason for hiding this comment

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

IMHO version check is not needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, I'll get rid of it

@fprochazka
Copy link
Contributor

👍

@milo
Copy link
Member

milo commented Nov 13, 2015

What about to support \Traversable instead of \Generator?

@jiripudil
Copy link
Contributor Author

@milo I thought about it, but didn't find any use case for Traversables other than Generators. But yeah, why not, while I'm at it :)

@jiripudil jiripudil force-pushed the feature/dataprovider-generator branch from 870b790 to 027fb44 Compare November 13, 2015 17:16
@jiripudil jiripudil changed the title TestCase: data provider supports generators TestCase: data provider supports \Traversable Nov 13, 2015
@jiripudil
Copy link
Contributor Author

I've added support for Traversable and squashed the branch into a single commit.

Copy link
Member

Choose a reason for hiding this comment

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

Why leading slash?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

@milo
Copy link
Member

milo commented Nov 13, 2015

Imho ready to merge. I left few CS hint comments.

@jiripudil
Copy link
Contributor Author

@milo I've fixed the CS compliance. Should I squash it now?

@milo
Copy link
Member

milo commented Nov 14, 2015

Yes please.

@jiripudil jiripudil force-pushed the feature/dataprovider-generator branch from 98b0db6 to 7066509 Compare November 14, 2015 17:33
@jiripudil
Copy link
Contributor Author

Squashed.

milo added a commit that referenced this pull request Nov 14, 2015
TestCase: data provider supports \Traversable
@milo milo merged commit fea9659 into nette:master Nov 14, 2015
@milo
Copy link
Member

milo commented Nov 14, 2015

Thank you.

@jiripudil jiripudil deleted the feature/dataprovider-generator branch November 14, 2015 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants