Skip to content

PHPUnit 6 support + refactoring #23

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

Merged
merged 14 commits into from
Nov 20, 2020
Merged

Conversation

VeryStrongFingers
Copy link
Contributor

@VeryStrongFingers VeryStrongFingers commented Nov 9, 2020

Was originally just adding PHPUnit 6 support (I know, gross and old :( )
Somehow ended up refactoring the various "Printers", essentially to centralise repeated code (ie. Don't Repeat Yourself).

Overall additions:

P.S. I tested the Github actions workflow @ https://github.com/VeryStrongFingers/phpunit-github-actions-printer/actions/runs/354432750
P.P.S. You might find value running those Github actions workflow for pull_request too

Copy link
Owner

@mheap mheap left a comment

Choose a reason for hiding this comment

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

This looks great @VeryStrongFingers!

I've added a couple of inline comments with a few questions and one required thing to fix (newline escaping)

// Some messages might contain paths. Let's convert thost to relative paths too
$message = relativePath($message);
$lineFeedPosition = strpos($message, '%0A');
if (is_int($lineFeedPosition) === true) {
Copy link
Owner

Choose a reason for hiding this comment

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

This is an incorrect change imo. The old behaviour stripped linefeeds from the end of the error, whilst the new behaviour truncates any error messages that contain a line feed. Could we revert to the old behaviour?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's my bad - I wasn't 100% sure if it was intentional or not, I'll revert it and leave a comment to avoid future developer confusion

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mheap I'm not sure why, but reverting it is not playing ball with PHPUnit 6
see https://github.com/VeryStrongFingers/phpunit-github-actions-printer/runs/1377052224?check_suite_focus=true#step:8:20
any ideas?

Copy link
Owner

Choose a reason for hiding this comment

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

This is very strange. It looks as though PHPUnit 6 does not add the additional information.

We could have a .phpt file just for PHPUnit 6, or update the printer to add this information (we have it available in file and line)

class Printer8 extends ResultPrinter
{
use Trait8;
Copy link
Owner

Choose a reason for hiding this comment

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

What was the thinking behind removing the Trait here? Printer8 and Printer9 look like duplications to me now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Printer9 and Printer8 extend different classes, is the only difference - otherwise Printer9 could just extend Printer8.
I left them both as individual concrete classes otherwise just in case adjustments need to be made specific to that version in the future.
(please note I am personally biased against the use of traits for various reasons).
I could make an abstract base class, not extending PHPUnit to avoid this duplication, if preferred?

Copy link
Owner

Choose a reason for hiding this comment

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

Using a trait allows us to keep the functionality DRY whilst still extending from different classes.

What are the benefits/risks of using a base class rather than a trait in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the method signatures vary over the PHPUnit versions, and traits are not actually concrete testable structures, sort of invisible magic.

Trait8 & Printer7 are already repeating logic because of this.
It would be a valid use case of traits if the method signatures were the same, but you'll end up with less codeby decorating the common methods with helper functions or something alike

@VeryStrongFingers
Copy link
Contributor Author

VeryStrongFingers commented Nov 16, 2020

@mheap I had a change of heart, and decided not to implement PHPUnit v6 - as it is EOL, and don't really want to encourage using unsupported tooling.
You're still welcome to merge PR, or close - all good either way
(I removed the printer & relevant code, so all tests as passing)

@mheap mheap merged commit 91658a4 into mheap:master Nov 20, 2020
@mheap
Copy link
Owner

mheap commented Nov 20, 2020

Thanks for this @VeryStrongFingers! Although PHPUnit 6 is EOL there are still people out there using it, and given that it's not too much more code to maintain I think it's worth adding.

I appreciate the refactoring, and I even learned about --SKIPIF--!

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