/rtfm/source/_pages/usage/test_suite.rst

https://github.com/welaika/wordless · ReStructuredText · 101 lines · 56 code · 45 blank · 0 comment · 0 complexity · 25a7c7204bf5de2674cad227a3e966f9 MD5 · raw file

  1. .. _TestSuite:
  2. Test Suite
  3. ==========
  4. The default Wordless theme is shipped with preconfigured test suite.
  5. The test suite is implemented using the awesome `WPBrowser`_ and thus `Codeception`_.
  6. .. note::
  7. By default Wordless is configured to run **acceptance** (aka **integration** or **e2e** or **browser**) test suite alone. If you'd like to run *functional* or *unit* suites, you'll simply have to update the ``yarn test`` script accordingly in ``package.json`` file.
  8. Quick start
  9. ###########
  10. Add tests to the ``tests/acceptance/WPFirstCest.php`` file or write your own file in the same folder.
  11. To run acceptance test suite you have to start the test server in one terminal
  12. .. code-block:: bash
  13. yarn test:server
  14. and in another terminal let's actually run tests:
  15. .. code-block:: bash
  16. yarn test
  17. While ``test`` will simply run **acceptance** test suite, ``test:server`` is a variant of the default ``server`` task which load different ``Procfile`` and ``.env`` files.
  18. Where are test configurations?
  19. ##############################
  20. * ``test/`` folder. This is where your test suites lay.
  21. * PHP dependencies declared in ``composer.json`` file shipped within the theme. This will create a ``/vendor`` folder inside the theme whilist ``yarn setup`` task
  22. * custom ``wp-config.php``. This will be helpful to autodymagically (automatically, dynamically, magically; just in case you were wondering 🙄) switch from development to test database whilist test suite execution
  23. * 2 test related node scripts: ``yarn test:server`` and ``yarn test``. Obviously declared inside ``package.json``
  24. * a test database on your local machine called ``$THEME_NAME_test`` (where ``$THEME_NAME`` is the chosen name during Wordless' installation process) is created whilist ``yarn setup`` task
  25. * *ad hoc* ``Procfile.testing``, ``.env.testing`` and ``.env.ci``
  26. * ready-to-go ``.gitlab-ci.yml`` file into the project root
  27. .. note::
  28. ``vendor/`` folders are ignored in ``.gitignore`` by default
  29. .. _WPBrowser: https://wpbrowser.wptestkit.dev/
  30. .. _Codeception: https://codeception.com/
  31. How should I write tests?
  32. #########################
  33. This documentation is not intended to giude you thourgh testing concepts nor on Codeception's syntax. You can already find great documentation and I advice you to start from
  34. * https://wpbrowser.wptestkit.dev/modules/wpwebdriver
  35. * https://wpbrowser.wptestkit.dev/modules/wpbrowser
  36. * https://wpbrowser.wptestkit.dev/modules/wpdb
  37. where you will find Wordpress specific methods and links to base Codeception's methods all in one place.
  38. Factory template
  39. """"""""""""""""
  40. The only thing Wordless actually adds to the default WPBrowser's setup is a ``FactoryHelper`` class, which is intended to create factory methods and which already integrates `Faker`_.
  41. Take a look at its ``haveOnePost()`` method to understand the simple concept behind the factory.
  42. .. _Faker: https://packagist.org/packages/fzaninotto/faker
  43. CI
  44. ##
  45. We ship default configuration for GitLab by putting a ``.gitlab-ci.yml`` file in you project's root folder.
  46. That is configured to run out-of-the-box. And if you use other CI's products you can use it as a starting point for your own configuration and then delete it without any regard :)
  47. Troubleshooting
  48. ###############
  49. * **yarn setup -> Error: Error establishing a database connection.**
  50. Check your dbs username & password in the ``wp-config.php``
  51. * **yarn test -> Db: SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client while creating PDO connection**
  52. Check your dbs username & password in ``.env.testing``, inside the themes folder
  53. * **yarn test -> Could not find, or could not parse, the original site URL; you can set the "originalUrl" parameter in the module configuration to skip this step and fix this error.**
  54. The command ``yarn test:db:snapshot`` can be useful.
  55. * **yarn test -> [ConnectionException] Can't connect to Webdriver at http://localhost:4444/wd/hub. Please make sure that Selenium Server or PhantomJS is running.**
  56. Check if you are running ``yarn test:server`` in another terminal .