@@ -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+
802850Additional 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