Skip to content

Commit eb71ee4

Browse files
committed
minor #20316 [AssetMapper] Add info about troubleshooting assets loading with Panther. (WedgeSama)
This PR was merged into the 6.4 branch. Discussion ---------- [AssetMapper] Add info about troubleshooting assets loading with Panther. Add more info on Panther tests due to PHP built in server. When a requested URI is not a `.php` file nor a directory, the built in server will try to directly server the corresponding "file". But if the file does not exist AND must be handle by Symfony app, the built in server just return a 404. - Can happen with any requested URI that look like a non `.php` file - Case can happen with AssetMapper. see symfony/panther#630 https://symfonycasts.com/screencast/last-stack/testing#debugging-by-opening-the-browser https://www.php.net/manual/en/features.commandline.webserver.php Commits ------- f2a68b5 Add info about troubleshooting assets loading with Panther. - Can happen with any requested uri that look like a non `.php` file - Case can happen with AssetMapper.
2 parents bfe88ec + f2a68b5 commit eb71ee4

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

testing/end_to_end.rst

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,55 @@ variable to ``false`` in your style file:
799799
800800
$enable-smooth-scroll: false;
801801
802+
Assets not loading (PHP built-in server only)
803+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
804+
805+
You may face cases where your assets are not loaded while running your tests.
806+
Because Panther use the `PHP built-in server`_ to serve your app, if your assets files
807+
(or any requested URI that not a ``.php`` file) does not exist in your public directory
808+
(e.g. rendered by your Symfony app), the built-in server will return a 404 not found.
809+
810+
This can happen when using :doc:`AssetMapper component </frontend/asset_mapper>`
811+
if you let your Symfony app handle your assets in dev environment.
812+
813+
To solve this, add a ``tests/router.php``::
814+
815+
// tests/router.php
816+
if (is_file($_SERVER['DOCUMENT_ROOT'].\DIRECTORY_SEPARATOR.$_SERVER['SCRIPT_NAME'])) {
817+
return false;
818+
}
819+
820+
$script = 'index.php';
821+
822+
$_SERVER = array_merge($_SERVER, $_ENV);
823+
$_SERVER['SCRIPT_FILENAME'] = $_SERVER['DOCUMENT_ROOT'].\DIRECTORY_SEPARATOR.$script;
824+
825+
$_SERVER['SCRIPT_NAME'] = \DIRECTORY_SEPARATOR.$script;
826+
$_SERVER['PHP_SELF'] = \DIRECTORY_SEPARATOR.$script;
827+
828+
require $script;
829+
830+
Then declare it as a router for Panther server in ``phpunit.xml.dist`` using ``PANTHER_WEB_SERVER_ROUTER`` var:
831+
832+
.. code-block:: xml
833+
834+
<!-- phpunit.xml.dist -->
835+
<phpunit>
836+
<!-- ... -->
837+
<php>
838+
<!-- ... -->
839+
<server name="PANTHER_WEB_SERVER_ROUTER" value="../tests/router.php"/>
840+
</php>
841+
</phpunit>
842+
843+
Credit from `Testing Part 2 Functional Testing on Symfony cast`_ were you can see more about this case.
844+
845+
.. note::
846+
847+
When using :doc:`AssetMapper component </frontend/asset_mapper>`, you can also compile your assets before running
848+
your tests. It will make your tests faster because Symfony will not have to handle them, the built-in server
849+
will serve them directly.
850+
802851
Additional Documentation
803852
------------------------
804853

@@ -825,3 +874,5 @@ documentation:
825874
.. _`Gitlab CI`: https://docs.gitlab.com/ee/ci/
826875
.. _`AppVeyor`: https://www.appveyor.com/
827876
.. _`LiipFunctionalTestBundle`: https://github.com/liip/LiipFunctionalTestBundle
877+
.. _`PHP built-in server`: https://www.php.net/manual/en/features.commandline.webserver.php
878+
.. _`Testing Part 2 Functional Testing on Symfony cast`: https://symfonycasts.com/screencast/last-stack/testing

0 commit comments

Comments
 (0)