@@ -799,6 +799,56 @@ variable to ``false`` in your style file:
799
799
800
800
$enable-smooth-scroll: false;
801
801
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
+
802
852
Additional Documentation
803
853
------------------------
804
854
@@ -825,3 +875,5 @@ documentation:
825
875
.. _`Gitlab CI` : https://docs.gitlab.com/ee/ci/
826
876
.. _`AppVeyor` : https://www.appveyor.com/
827
877
.. _`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