Skip to content

Commit 0bf480b

Browse files
committed
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.
1 parent 6c48614 commit 0bf480b

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

testing/end_to_end.rst

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,56 @@ variable to ``false`` in your style file:
799799
800800
$enable-smooth-scroll: false;
801801
802+
Assets not loading
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 served them directly.
850+
851+
802852
Additional Documentation
803853
------------------------
804854

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

0 commit comments

Comments
 (0)