diff --git a/.circleci/test.sh b/.circleci/test.sh index 41fd68e..47282e1 100755 --- a/.circleci/test.sh +++ b/.circleci/test.sh @@ -10,3 +10,6 @@ ahoy lint echo "==> Run Behat tests" mkdir -p /tmp/artifacts/behat ahoy test-behat || ahoy test-behat -- --rerun + +echo "==> Run Unit tests" +ahoy cli "/app/vendor/bin/phpunit" diff --git a/README.md b/README.md index 3e8f9a1..5711e48 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,7 @@ Finally, we install the module itself. 1. Uncomment this line in `docker-compose.yml`: ``` #XDEBUG_ENABLE: "true" + #DOCKERHOST: "host.docker.internal" ``` 2. Restart the stack: `ahoy up`. 3. Enable listening for incoming debug connections in your IDE. @@ -181,3 +182,14 @@ To make a change: 6. If the build passes, merge the Dev Tools branch to `master` and make a release. - NOTE: This must be a release in GitHub, see https://github.com/dpc-sdp/dev-tools/releases/new 7. Remove the temporary branch in `tide_*` module from Step 3. + +## Unit test +The dev-tools supports unit tests. +### Registering tests +#### Directory +1. The unit tests should go in `tests\src\Unit` direcotry. +2. The unit tests need to respect PSR-4 namespace naming convention, in our case, + `namespace Drupal\Tests\{module}\Unit` +### 2 ways to run tests +1. commit to CI. +2. Run `./vendor/bin/phpunit` inside CLI container locally. diff --git a/composer.dev.json b/composer.dev.json index 07e110c..f358688 100644 --- a/composer.dev.json +++ b/composer.dev.json @@ -25,7 +25,9 @@ "phpcompatibility/php-compatibility": "^9.1", "ubirak/rest-api-behat-extension": "dev-feature/drupalextension-compatibility as 7.0.0", "symfony/filesystem": "^3.2.8", - "php-http/curl-client": "^1.7" + "php-http/curl-client": "^1.7", + "phpunit/phpunit": "^6.5", + "drupal/core-dev":"8.9.x" }, "autoload": { "classmap": [ diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..8065eec --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ./dpc-sdp/*/tests/src/Unit + + + + + + + + + + + + + + + + + + + + + + + + + ./includes + ./lib + + ./modules + + ./modules/*/src/Tests + ./modules/*/tests + + ../modules + + ../modules/*/src/Tests + ../modules/*/tests + ../modules/*/*/src/Tests + ../modules/*/*/tests + + ../sites + + +