Skip to content

Commit

Permalink
Merge pull request #304 from plivo/local-docker-enhancement
Browse files Browse the repository at this point in the history
Local docker enhancement
  • Loading branch information
renoldthomas-plivo authored Mar 17, 2023
2 parents 8f4d4b7 + 6d0b4c7 commit 5881558
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
@[ "${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)
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,5 +243,10 @@ export PLIVO_API_PROD_HOST=<plivoapi_public_endpoint>
> 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=<cont_id>` in host, where `<cont_id>` is the docker container id created in 2.
(The docker container should be running)
6. To run test code, run `make run CONTAINER=<cont_id>` in host.
7. To run unit tests, run `make test CONTAINER=<cont_id>` in host.
> `<cont_id>` 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)
23 changes: 13 additions & 10 deletions setup_sdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <path_to_cloned_sdk>/$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 <path_to_cloned_sdk>/$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

0 comments on commit 5881558

Please sign in to comment.