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

Fix not found ShortcodeTest class by the autoloader #10

Closed
wants to merge 1 commit into from

Conversation

FabianSchmick
Copy link
Member

If you extend the Webfactory\ShortcodeBundle\Tests\Functional\ShortcodeTest class as recommended in the README.md you will recieve an error which tells you, that the class could not be found.

This is because of:

    "autoload-dev": {
        "psr-4": {
            "Webfactory\\ShortcodeBundle\\Tests\\": "tests"
        }
    },

which will not load the class if the bundle is installed as a dependency.

This bug was found with the help of @mpdude maybe you want to extend my explanation?

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.

I don't think it's a good idea to move test code into the production directory/production autoloading. This e.g. will lead to problems with composer-require-checker. What do you think about extending the "Automated Tests for your Shortcodes" section in the README.md instead with something like:

Include the folliwing in your composer.json:

"autoload-dev": {
       "psr-4": {
           "Webfactory\\ShortcodeBundle\\Tests\\": "vendor/webfactory/shortcode-bundle/tests"
       }
   },

?

@mpdude mpdude closed this in #23 May 31, 2022
mpdude added a commit that referenced this pull request May 31, 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.

2. 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.

Co-authored-by: Malte Wunsch <mw@webfactory.de>
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