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

Add helper classes for shortcode testing #23

Merged
merged 17 commits into from
May 31, 2022
Merged

Add helper classes for shortcode testing #23

merged 17 commits into from
May 31, 2022

Conversation

mpdude
Copy link
Member

@mpdude mpdude commented May 30, 2022

This PR addresses the shortcomings outlined in #12 and #13, and probably replaces #10 and #18 as well.

  1. Deprecate the \Webfactory\ShortcodeBundle\Tests\Functional\ShortcodeTest class.
  • It was not available through the regular autoload mechanism (required extra trickery),
  • depended on undeclared dependencies (BrowserKit and DomCrawler),
  • came without tests,
  • suggested users to do/prefer full-scale Application Testing (using WebTestCase) and
  • worked only through the means of (ab-)using the Shortcode Guide.
  1. Provide alternate means of testing shortcode processing
  • Encourage users to do plain/direct unit testing (or integration testing, when necessary) of their shortcode handlers and/or shortcode handling controllers through new sections in the README. This gives best (most direct) control of input parameters.
  • Add the public \Webfactory\ShortcodeBundle\Test\ShortcodeDefinitionTestHelper service that can be used in Kernel-based (functional) tests to verify a given shortcode name is known, the controller can be resolved etc.
  • Add a \Webfactory\ShortcodeBundle\Test\EndToEndTestHelper class that simplifies full end-to-end (from content to processed content) functional testing, including round-trips through Symfony's FragmentHandler for controller-based shortcodes.

Fixes #12, fixes #13, closes #10, closes #18, closes #24.

@mpdude mpdude changed the title Add helper classes for shortcode testing, and update the README to explain various testing approaches Add helper classes for shortcode testing May 30, 2022
@MalteWunsch MalteWunsch linked an issue May 30, 2022 that may be closed by this pull request
Copy link
Member

@MalteWunsch MalteWunsch left a comment

Choose a reason for hiding this comment

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

Good job 💚

/**
* @test
*/
public function resolve__placeholder_shortcode_in__twig(): void
Copy link
Member

Choose a reason for hiding this comment

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

I've noticed these double underscores several times and wonder if I've missed some meaning?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, somehow they keep reappearing when I run PHP-CS-Fixer.

Comment on lines +20 to +22
<service id="Thunder\Shortcode\Handler\PlaceholderHandler">
<tag name="webfactory.shortcode" shortcode="placeholder" />
</service>
Copy link
Member

Choose a reason for hiding this comment

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

I'm not entirely happy for our tests to depend on this external PlaceholderHandler class. But it is officially mentioned in thunderer's README, so 👍

Base automatically changed from shortcode-as-config to master May 31, 2022 11:48
@mpdude mpdude force-pushed the testing-helpers branch from 75540a0 to adb1ef6 Compare May 31, 2022 11:57
@mpdude mpdude merged commit ee4e741 into master May 31, 2022
@mpdude mpdude deleted the testing-helpers branch May 31, 2022 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants