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

Generators: add initial set of tests #671

Merged
merged 3 commits into from
Nov 13, 2024
Merged

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Nov 12, 2024

Description

These new tests safeguard the output generated by the Text, Markdown and HTML doc generators and the logic in the abstract Generator class.

Notes about the setup for these tests:

These tests use a set of test fixtures specially crafted for these tests. The use of fixtures means that the tests don't use real documentation as included with the various standards, which is subject to change and would make the tests unstable.

As the test fixtures are set up as an external standard, these tests will not only safeguard that doc generation works as expected, but also that it continues to work with external standards. This should help prevent issues as previously fixed in a10bea6 and e5bdaad.

The footer output for the Markdown and HTML generators contains a date and a PHPCS version nr, which, again, would make the tests unstable. To mitigate this, test double classes are included for these classes, which overload the printFooter() methods and replace the date and PHPCS version number with placeholders for the generic documentation tests.

The real footer is still tested, but via a regex pattern in a separate test in the MarkdownTest and HTMLTest classes.

Finally, as things were, the tests for Markdown and HTML would fail on Windows due to the generated output containing mixed line endings in the HTML <style> tag and in the code samples for both.

Commit 85b4a90 previously changed the EOL char used for output to screen to PHP_EOL, but these two places were overlooked. That is now fixed via this commit.

Suggested changelog entry

  • Output from the --generator=... feature will respect the expected EOL, based on the OS on which PHPCS is run, in more places.

Related issues/external references

This PR is part of a series of PRs which will add a complete set of tests for the Generator feature.

Related to #146

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Copy link
Contributor

@rodrigoprimo rodrigoprimo left a comment

Choose a reason for hiding this comment

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

LGTM!

I left a few comments related to the Generator test. One that might require some changes if I'm not missing something.

tests/Core/Generators/GeneratorTest.php Outdated Show resolved Hide resolved
tests/Core/Generators/GeneratorTest.php Outdated Show resolved Hide resolved
tests/Core/Generators/GeneratorTest.php Show resolved Hide resolved
@jrfnl jrfnl modified the milestones: 3.11.1, 3.11.x Next Nov 12, 2024
@rodrigoprimo rodrigoprimo self-requested a review November 13, 2024 13:56
These new tests safeguard the output generated by the `Text`, `Markdown` and `HTML` doc generators and the logic in the abstract `Generator` class.

**Notes about the setup for these tests**:

These tests use a set of test fixtures specially crafted for these tests.
The use of fixtures means that the tests don't use _real_ documentation as included with the various standards, which is subject to change and would make the tests unstable.

As the test fixtures are set up as an external standard, these tests will not only safeguard that doc generation works as expected, but also that it continues to work with external standards.
This should help prevent issues as previously fixed in a10bea6 and e5bdaad.

The footer output for the `Markdown` and `HTML` generators contains a date and a PHPCS version nr, which, again, would make the tests unstable. To mitigate this, test double classes are included for these classes, which overload the `printFooter()` methods and replaces the date and PHPCS version number with placeholders for the generic documentation tests.

The _real_ footer is still tested, but via a regex pattern in a separate test in the `MarkdownTest` and `HTMLTest` classes.

Finally, as things were, the tests for `Markdown` and `HTML` would fail on Windows due to the generated output containing mixed line endings in the HTML `<style>` tag and in the code samples for both.

Commit 85b4a90 previously changed the EOL char used for output to screen to `PHP_EOL`, but these two places were overlooked.
That is now fixed via this commit.
@jrfnl
Copy link
Member Author

jrfnl commented Nov 13, 2024

After #663, I'm going to add the @group Windows annotation to these tests too. (Also see #678)

I'll also rebase the PR (without changes other than the one mentioned above), as the CI setup has undergone some changes and some new required builds are missing. Once the build has passed, I'll get this merged.

@jrfnl jrfnl force-pushed the feature/generators-add-tests branch from e7fa943 to c883660 Compare November 13, 2024 21:01
@jrfnl jrfnl merged commit f9c5f18 into master Nov 13, 2024
70 checks passed
@jrfnl jrfnl deleted the feature/generators-add-tests branch November 13, 2024 21:59
jrfnl added a commit that referenced this pull request Nov 13, 2024
These new tests safeguard the output generated by the `Text`, `Markdown` and `HTML` doc generators and the logic in the abstract `Generator` class.

**Notes about the setup for these tests**:

These tests use a set of test fixtures specially crafted for these tests.
The use of fixtures means that the tests don't use _real_ documentation as included with the various standards, which is subject to change and would make the tests unstable.

As the test fixtures are set up as an external standard, these tests will not only safeguard that doc generation works as expected, but also that it continues to work with external standards.
This should help prevent issues as previously fixed in a10bea6 and e5bdaad.

The footer output for the `Markdown` and `HTML` generators contains a date and a PHPCS version nr, which, again, would make the tests unstable. To mitigate this, test double classes are included for these classes, which overload the `printFooter()` methods and replaces the date and PHPCS version number with placeholders for the generic documentation tests.

The _real_ footer is still tested, but via a regex pattern in a separate test in the `MarkdownTest` and `HTMLTest` classes.

Finally, as things were, the tests for `Markdown` and `HTML` would fail on Windows due to the generated output containing mixed line endings in the HTML `<style>` tag and in the code samples for both.

Commit 85b4a90 previously changed the EOL char used for output to screen to `PHP_EOL`, but these two places were overlooked.
That is now fixed via this commit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants