Skip to content
This repository has been archived by the owner on Mar 30, 2018. It is now read-only.

Switch output dependency from TAP to Teamcity #237

Merged
merged 17 commits into from
May 30, 2017
Merged

Conversation

padraic
Copy link
Collaborator

@padraic padraic commented Apr 29, 2017

Just some simple changes. I disabled early termination of the ProcessRunner since it shouldn't be needed if we are telling PHPUnit to stop on first failure (via command line option), and it ends up truncating the failure messages when we do it manually.

However, I think the \Humbug\ProcessRunner needs a bit of attention beyond this. I've commented out lines, and there seems to some interference when underlying unit-under-test is also using processes. You can spot it by attempting to use Humbug on https://github.com/Seldaek/monolog (for example). The failure between Humbug, and running PHPUnit straight on Monolog, are very different, but you can switch failures by manipulating the ProcessRunner. This was happening WITHOUT my changes, so it's a separate pre-existing issue.

Anyways, will add tests and such over next day or so.

@padraic
Copy link
Collaborator Author

padraic commented Apr 30, 2017

Tests have a single failure which seems to have crept in via a possible PHPUnit bug from PHPUnit 5.2.0 onwards. I'm not sure if it's expected or not, but I've reported it here: sebastianbergmann/phpunit#2665

If the outcome is something expected/deprecated or otherwise not to be fixed, I'll scrub the offending test.

@padraic padraic mentioned this pull request May 5, 2017
@omissis
Copy link

omissis commented May 10, 2017

@padraic I was wondering if it might make sense to have adapters for each logging format, so to avoid couple the implementation to a specific one and be able to swap between them more easily.

@padraic
Copy link
Collaborator Author

padraic commented May 10, 2017

@omissis That makes sense. There was a reason originally for the tight coupling, but that's no longer an issue.

@padraic
Copy link
Collaborator Author

padraic commented May 12, 2017

@humbug/core Ready for review here now. There is one test now marked skipped - against the old PHPUnit suite assembly method using AllTests.php files. Can't quite find it documented in the PHPUnit changelog, but Sebastian certainly doesn't consider this a supported feature anymore.

Copy link
Member

@theofidry theofidry left a comment

Choose a reason for hiding this comment

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

I did a first review, there's some questions for you :)

$process->stop();
return;
$hasFailure = true;
//$process->stop();
Copy link
Member

Choose a reason for hiding this comment

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

why the comments?

<directory>.</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
Copy link
Member

Choose a reason for hiding this comment

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

missing ending blank line

Stdout:
> TAP version 13
> not ok 1 - Error: FooTest::testAddsNumbers
##teamcity[testFailed
Copy link
Member

Choose a reason for hiding this comment

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

we no longer get to know where it's failing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The teamcity block will have it - but the block varies between test runs, so I just checked that it was output for the scenario..


protected function extractFail($output)
{
$result = preg_match('%##teamcity\[testFailed.*\]%', $output, $matches);
Copy link
Member

Choose a reason for hiding this comment

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

if (preg_match('%##teamcity\[testFailed.*\]%', $output, $matches)) {
    return $matches[0];
}

return 'No failure output was detected by Humbug, but a failure was reported by PHPUnit.';

Copy link
Member

Choose a reason for hiding this comment

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

Could also be simplified by a ternary operator

@@ -316,4 +316,13 @@ protected function headAndTail($output, $lineCount = 20, $omittedMarker = '[...M
array_slice($lines, -$lineCount, $lineCount)
));
}

protected function extractFail($output)
Copy link
Member

Choose a reason for hiding this comment

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

can we make it private?

&& !preg_match("%# TODO%", $line)) {
return false;
}
if (preg_match("%##teamcity\[testFailed%", $output)) {
Copy link
Member

Choose a reason for hiding this comment

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

return (bool) preg_match("%##teamcity\[testFailed%", $output);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You have to watch the casting to bool with preg_match - that's why I prefer taking the scenic route ;).

Copy link
Member

Choose a reason for hiding this comment

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

but isn't it what is done with the if statement? Too me both look strictly equivalent

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Here's the short version that would work (excl. errors which return FALSE):

return 0 === preg_match("%##teamcity\[testFailed%", $output);

Added via commit just now.

$this->assertTrue($adapter->ok($result));
}

public function testAdapterRunsPhpunitCommandWithAlltestsFileTarget()
{
$this->markTestSkipped('See https://github.com/sebastianbergmann/phpunit/issues/2665');
Copy link
Member

Choose a reason for hiding this comment

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

looks like this issue has been closed and that we shouldn't run that test

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

True - test should actually be deleted now.

if ($result) {
return (int) end($matches[1]);
$this->okCount += $result;
return $this->okCount; // was: (int) end($matches[1]);
Copy link

Choose a reason for hiding this comment

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

I would expect a has* method to always return a boolean

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It probably should, and it's a public method to boot, but something we can clean up with greater forethought for 2.0 when defining interfaces/extension points.

@padraic padraic changed the title [WIP] Switch output dependency from TAP to Teamcity Switch output dependency from TAP to Teamcity May 13, 2017
@padraic
Copy link
Collaborator Author

padraic commented May 13, 2017

@theofidry Some changes made.

Copy link
Member

@theofidry theofidry left a comment

Choose a reason for hiding this comment

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

Last nitpicking, all good for me otherwise

&& !preg_match("%# TODO%", $line)) {
return false;
}
if (preg_match("%##teamcity\[testFailed%", $output)) {
Copy link
Member

Choose a reason for hiding this comment

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

but isn't it what is done with the if statement? Too me both look strictly equivalent

@padraic
Copy link
Collaborator Author

padraic commented May 21, 2017

@theofidry In case my comment was lost in changing that, I updated the preg_match block to

return 0 === preg_match("%##teamcity\[testFailed%", $output);

@theofidry theofidry merged commit 326371f into master May 30, 2017
@theofidry theofidry deleted the feature/teamcity branch May 30, 2017 06:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants