diff --git a/Dockerfile b/Dockerfile index ca6aaba1..e8c02df7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM php:7.3-alpine -RUN apk update && apk add git vim bash curl +RUN apk update && apk add git vim bash curl make # Install composer RUN curl -sS https://getcomposer.org/installer | php diff --git a/Makefile b/Makefile index afa88995..3dc93e32 100644 --- a/Makefile +++ b/Makefile @@ -4,4 +4,11 @@ build: docker-compose up --build --remove-orphans test: - docker exec -it $$CONTAINER /bin/bash -c "/usr/src/app/vendor/bin/phpunit --verbose tests" \ No newline at end of file + @[ "${CONTAINER}" ] && \ + docker exec -it $$CONTAINER /bin/bash -c "/usr/src/app/vendor/bin/phpunit --verbose --bootstrap tests/bootstrap.php --testsuite resources-tests tests" || \ + /usr/src/app/vendor/bin/phpunit --verbose --bootstrap tests/bootstrap.php --testsuite resources-tests tests + +run: + @[ "${CONTAINER}" ] && \ + (docker exec -it $$CONTAINER /bin/bash -c 'cd /usr/src/app/php-sdk-test/ && php test.php') || \ + (cd /usr/src/app/php-sdk-test/ && php test.php) \ No newline at end of file diff --git a/README.md b/README.md index 249d60fd..545092c7 100644 --- a/README.md +++ b/README.md @@ -243,5 +243,10 @@ export PLIVO_API_PROD_HOST= > To use the local code in the test file, import the sdk in test file using: `require /usr/src/app/vendor/autoload.php` (Local sdk code will be mounted at `/usr/src/app` inside the container and `vendor` directory will be created by setup script while installing dependencies). -6. To run unit tests, run `make test CONTAINER=` in host, where `` is the docker container id created in 2. -(The docker container should be running) \ No newline at end of file +6. To run test code, run `make run CONTAINER=` in host. +7. To run unit tests, run `make test CONTAINER=` in host. +> `` is the docker container id created in 2. +(The docker container should be running) + +> Test code and unit tests can also be run within the container using +`make run` and `make test` respectively. (`CONTAINER` argument should be omitted when running from the container) \ No newline at end of file diff --git a/setup_sdk.sh b/setup_sdk.sh index 48e215aa..6a030566 100755 --- a/setup_sdk.sh +++ b/setup_sdk.sh @@ -33,14 +33,17 @@ if [ ! -f $testDir/test.php ]; then cd - fi -echo -e "\n\nSDK setup complete!" -echo "To test your changes:" -echo -e "\t1. Add your test code in /$testDir/test.php on host (or /usr/src/app/$testDir/test.php in the container)" -echo -e "\t\tNote: To use sdk in test file, import using $GREEN require '/usr/src/app/vendor/autoload.php';$NC" -echo -e "\t2. Run a terminal in the container using: $GREEN docker exec -it $HOSTNAME /bin/bash$NC" -echo -e "\t3. Navigate to the test directory: $GREEN cd /usr/src/app/$testDir$NC" -echo -e "\t4. Run your test file: $GREEN php test.php$NC" -echo -e "\t5. For running unit tests, run on host: $GREEN make test CONTAINER=$HOSTNAME$NC" - -# To keep the container running post setup +echo -e "\n\nSDK setup complete! You can test changes either on host or inside the docker container:" +echo -e "\ta. To test your changes ON HOST:" +echo -e "\t\t1. Add your test code in /$testDir/test.php" +echo -e "\t\t2. Run your test file using: $GREEN make run CONTAINER=$HOSTNAME$NC" +echo -e "\t\t3. Run unit tests using: $GREEN make test CONTAINER=$HOSTNAME$NC" +echo +echo -e "\tb. To test your changes INSIDE CONTAINER:" +echo -e "\t\t1. Run a terminal in the container using: $GREEN docker exec -it $HOSTNAME /bin/bash$NC" +echo -e "\t\t2. Add your test code in /usr/src/app/$testDir/test.php" +echo -e "\t\t3. Run your test file using: $GREEN make run$NC" +echo -e "\t\t4. Run unit tests using: $GREEN make test$NC" + +## To keep the container running post setup /bin/bash \ No newline at end of file