Skip to content

Commit 03de678

Browse files
committed
Merge branch '6.4' into 7.1
* 6.4: 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 88c93ec + 78e0a19 commit 03de678

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

frontend/asset_mapper.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ If you look at the HTML in your page, the URL will be something
7373
like: ``/assets/images/duck-3c16d9220694c0e56d8648f25e6035e9.png``. If you change
7474
the file, the version part of the URL will also change automatically.
7575

76+
.. _asset-mapper-compile-assets:
77+
7678
Serving Assets in dev vs prod
7779
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7880

testing/end_to_end.rst

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,54 @@ variable to ``false`` in your style file:
799799
800800
$enable-smooth-scroll: false;
801801
802+
Assets not Loading when Using the PHP Built-In Server
803+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
804+
805+
Sometimes, your assets might not load during tests. This happens because Panther
806+
uses the `PHP built-in server`_ to serve your app. If asset files (or any requested
807+
URI that's not a ``.php`` file) aren't in your public directory, the built-in
808+
server will return a 404 error. This often happens when letting the :doc:`AssetMapper component </frontend/asset_mapper>`
809+
handle your application assets in the ``dev`` environment.
810+
811+
One solution when using AssetMapper is to ref:`compile assets <asset-mapper-compile-assets>`
812+
before running your tests. This will also speed up your tests, as Symfony won't
813+
need to handle the assets, allowing the PHP built-in server to serve them directly.
814+
815+
Another option is to create a file called ``tests/router.php`` and add the following to it::
816+
817+
// tests/router.php
818+
if (is_file($_SERVER['DOCUMENT_ROOT'].\DIRECTORY_SEPARATOR.$_SERVER['SCRIPT_NAME'])) {
819+
return false;
820+
}
821+
822+
$script = 'index.php';
823+
824+
$_SERVER = array_merge($_SERVER, $_ENV);
825+
$_SERVER['SCRIPT_FILENAME'] = $_SERVER['DOCUMENT_ROOT'].\DIRECTORY_SEPARATOR.$script;
826+
827+
$_SERVER['SCRIPT_NAME'] = \DIRECTORY_SEPARATOR.$script;
828+
$_SERVER['PHP_SELF'] = \DIRECTORY_SEPARATOR.$script;
829+
830+
require $script;
831+
832+
Then declare it as a router for Panther server in ``phpunit.xml.dist`` using the
833+
``PANTHER_WEB_SERVER_ROUTER`` environment variable:
834+
835+
.. code-block:: xml
836+
837+
<!-- phpunit.xml.dist -->
838+
<phpunit>
839+
<!-- ... -->
840+
<php>
841+
<!-- ... -->
842+
<server name="PANTHER_WEB_SERVER_ROUTER" value="./tests/router.php"/>
843+
</php>
844+
</phpunit>
845+
846+
.. seealso::
847+
848+
See the `Functional Testing tutorial`_ on SymfonyCasts.
849+
802850
Additional Documentation
803851
------------------------
804852

@@ -825,3 +873,5 @@ documentation:
825873
.. _`Gitlab CI`: https://docs.gitlab.com/ee/ci/
826874
.. _`AppVeyor`: https://www.appveyor.com/
827875
.. _`LiipFunctionalTestBundle`: https://github.com/liip/LiipFunctionalTestBundle
876+
.. _`PHP built-in server`: https://www.php.net/manual/en/features.commandline.webserver.php
877+
.. _`Functional Testing tutorial`: https://symfonycasts.com/screencast/last-stack/testing

0 commit comments

Comments
 (0)