Skip to content

TestCase: data provider supports \Traversable - #272

Merged
milo merged 1 commit into
nette:masterfrom
jiripudil:feature/dataprovider-generator
Nov 14, 2015
Merged

TestCase: data provider supports \Traversable#272
milo merged 1 commit into
nette:masterfrom
jiripudil:feature/dataprovider-generator

Conversation

@jiripudil

Copy link
Copy Markdown
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'];

    // ...
}

Comment thread src/Framework/TestCase.php Outdated

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

👍

@milo

milo commented Nov 13, 2015

Copy link
Copy Markdown
Member

What about to support \Traversable instead of \Generator?

@jiripudil

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

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

Comment thread src/Framework/TestCase.php Outdated

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

removed

@milo

milo commented Nov 13, 2015

Copy link
Copy Markdown
Member

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

@jiripudil

Copy link
Copy Markdown
Contributor Author

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

@milo

milo commented Nov 14, 2015

Copy link
Copy Markdown
Member

Yes please.

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

Copy link
Copy Markdown
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

milo commented Nov 14, 2015

Copy link
Copy Markdown
Member

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