Run module tests in OXID eShop 6
As follow up for Run tests for OXID eShop 6 here’s how to get module tests running for OXID eShop 6.
Let’s assume we have a metadata 2.0 module (own module namespace, installable with composer) in some public github repository (original or your own fork). Let’s use the OXIDProjects oxid-module-internals as example.
In case you just want to install the module and be good, check module’s README.md or documentation about how to install via composer. Get your OXID VM up and do vagrant ssh.
Example:
cd /var/www/oxideshop composer require oxid-community/moduleinternals
The module’s source code is downloaded into the vendor directory (vendor/oxid-community/moduleinternals
).
As the shop still expects module source code to be located inside source/modules
, the module’s composer.json contains an entry for the ‘target-directory’ in the extra section and the OXID composer plugin takes care all necessary files are copied into that target-directory.
"extra": { "oxideshop": { "target-directory": "oxcom/moduleinternals" } },
Best way if you want to actually develop the module is to directly git clone the module
into source/modules/target-directory
.
cd /var/www/oxideshop/source/modules git clone https://github.com/OXIDprojects/oxid-module-internals.git oxcom/moduleinternals
As you did not use the composer installation way, you need now to manually register the module’s namespace. Add the module namespace to the shop’s main composer.json, either into autoload or autoload-dev section. Make sure it points to the correct directory.
"autoload": { "psr-4": { ... "OxidCommunity\\ModuleInternals\\": "./source/modules/oxcom/moduleinternals" } },
Then do
cd /var/www/oxideshop composer dump-autoload
Disregarding of you way of installation, doublecheck you have the module tests located
in source/modules/target-directory/Tests
.
Edit the shop’s test_config.yml
... partial_module_paths: oxcom/moduleinternals ... run_tests_for_shop: false run_tests_for_modules: true ...
and run
cd /var/www/oxideshop vendor/bin/reset-shop vendor/bin/runtests
If you like to run module tests automatically you can use/copy the files
https://github.com/OXIDprojects/oxid-module-internals/blob/master/.travis.yml and https://github.com/OXIDprojects/oxid-module-internals/blob/master/.travis.before_script.sh
and register your module in travis. The Service is for free and will execute tests in virtual environment on each commit.