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

[WIP] Initial phpunit setup #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ocramleznem
Copy link
Contributor

Feel free to comment 🎉

* some unit tests
Copy link
Owner

@jk jk left a comment

Choose a reason for hiding this comment

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

Here are my 2 cents on that. We should probably introduce VCR to stub the network code.


public function testInstance()
{
static::assertInstanceOf('JK\Mittagstisch\MenuItem', $this->instance);
Copy link
Owner

Choose a reason for hiding this comment

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

  • A regular user of PHPUnit should use $this-> instead of self::

Source: sebastianbergmann/phpunit#1914 (comment)


public function testInstance()
{
static::assertInstanceOf('JK\Mittagstisch\Scrapers\Bullerei', $this->instance);
Copy link
Owner

@jk jk Oct 11, 2016

Choose a reason for hiding this comment

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

More or less pointless test. You would have a point in testing it for implementing the new Restaurant interface, though.

{
$menus = $this->invokeScrape($this->instance, 'scrape');
static::assertInternalType('array', $menus);
static::assertContainsOnlyInstancesOf('JK\Mittagstisch\MenuItem', $menus);
Copy link
Owner

Choose a reason for hiding this comment

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

Technically this is a functional test and not a unit test anymore. If that's the case, the network code should be stubbed.

Copy link
Contributor Author

@ocramleznem ocramleznem Oct 11, 2016

Choose a reason for hiding this comment

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

You are right.
Propably there is some kind of method-splitting necessary to test the regex-matching. I will have look at this "network-stubbing", I don't have any experience about that.
It would be really useful to check or parse against given HTML from the past, so that we can catch several "kinds of postings", e.g. extra <p>-tags, changed string-formatting.

$method = $reflection->getMethod($methodName);
$method->setAccessible(true);

return $method->invokeArgs($object, $parameters);
Copy link
Owner

Choose a reason for hiding this comment

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

Not to happy about something like this in a test suite. I understand where you're heading, but since we can change the code, we rather want to do that instead.

@jk jk changed the title [WIP] initial phpunit setup [WIP] Initial phpunit setup Oct 11, 2016
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.

2 participants