test.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/env bash
  2. down=false
  3. php="8.0"
  4. while true; do
  5. case "$1" in
  6. --down ) down=true; shift ;;
  7. --php ) php=$2; shift 2;;
  8. -- ) shift; break ;;
  9. * ) break ;;
  10. esac
  11. done
  12. if $down; then
  13. docker-compose down -t 0
  14. exit 0
  15. fi
  16. echo "Ensuring docker is running"
  17. if ! docker info > /dev/null 2>&1; then
  18. echo "Please start docker first."
  19. exit 1
  20. fi
  21. echo "Ensuring services are running"
  22. docker-compose up -d
  23. if docker run -it --rm "registry.gitlab.com/grahamcampbell/php:$php-base" -r "\$tries = 0; while (true) { try { \$tries++; if (\$tries > 30) { throw new RuntimeException('MySQL never became available'); } sleep(1); new PDO('mysql:host=docker.for.mac.localhost;dbname=forge', 'root', '', [PDO::ATTR_TIMEOUT => 3]); break; } catch (PDOException \$e) {} }"; then
  24. echo "Running tests"
  25. if docker run -it -w /data -v ${PWD}:/data:delegated \
  26. --user "www-data" --entrypoint vendor/bin/phpunit \
  27. --env CI=1 --env DB_HOST=docker.for.mac.localhost --env DB_USERNAME=root \
  28. --env DB_HOST=docker.for.mac.localhost --env DB_PORT=3306 \
  29. --env DYNAMODB_ENDPOINT=docker.for.mac.localhost:8000 --env DYNAMODB_CACHE_TABLE=cache --env AWS_ACCESS_KEY_ID=dummy --env AWS_SECRET_ACCESS_KEY=dummy \
  30. --env REDIS_HOST=docker.for.mac.localhost --env REDIS_PORT=6379 \
  31. --env MEMCACHED_HOST=docker.for.mac.localhost --env MEMCACHED_PORT=11211 \
  32. --rm "registry.gitlab.com/grahamcampbell/php:$php-base" "$@"; then
  33. exit 0
  34. else
  35. exit 1
  36. fi
  37. else
  38. docker-compose logs
  39. exit 1
  40. fi