application_tests.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/bin/sh
  2. # Configuration des paramètres de la base de données
  3. DB_USER="root"
  4. DB_PASSWORD="mysql660"
  5. DB_HOST="127.0.0.1"
  6. DB_PORT="3306"
  7. DB_NAME="opentalent"
  8. DB_TEST_NAME="opentalent_test"
  9. MARIADB_CONTAINER="mariaDb"
  10. # Fonction pour réinitialiser la base de données de test
  11. reset_test_database() {
  12. echo "Dropping test database if it exists..."
  13. docker exec $MARIADB_CONTAINER mysql --user=$DB_USER --password=$DB_PASSWORD --host=$DB_HOST --port=$DB_PORT -e "DROP DATABASE IF EXISTS $DB_TEST_NAME;"
  14. echo "Dumping schema from the main database..."
  15. docker exec $MARIADB_CONTAINER mysqldump --user=$DB_USER --password=$DB_PASSWORD --host=$DB_HOST --port=$DB_PORT --default-character-set=utf8 --single-transaction=TRUE --no-data --skip-triggers "$DB_NAME" | sed 's/ AUTO_INCREMENT=[0-9]*//g' > opentalent_test.sql
  16. echo "Creating test database..."
  17. docker exec $MARIADB_CONTAINER mysql --user=$DB_USER --password=$DB_PASSWORD --host=$DB_HOST --port=$DB_PORT -e "CREATE DATABASE $DB_TEST_NAME;"
  18. echo "Importing schema into the test database..."
  19. docker exec -i $MARIADB_CONTAINER mysql --user=$DB_USER --password=$DB_PASSWORD --host=$DB_HOST --port=$DB_PORT -D $DB_TEST_NAME < opentalent_test.sql
  20. echo "Database setup completed."
  21. }
  22. # Réinitialiser la base de données de test
  23. reset_test_database
  24. total_tests=0
  25. passed_tests=0
  26. failed_tests=0
  27. for test_file in $(find tests/Application -name "*Test.php"); do
  28. echo "Running test: $test_file"
  29. php bin/phpunit $test_file
  30. result=$?
  31. total_tests=$((total_tests + 1))
  32. if [ $result -ne 0 ]; then
  33. echo "Test failed: $test_file"
  34. failed_tests=$((failed_tests + 1))
  35. else
  36. passed_tests=$((passed_tests + 1))
  37. fi
  38. done
  39. echo "===================================="
  40. echo "Test Summary:"
  41. echo "Total tests run: $total_tests"
  42. echo "Tests passed: $passed_tests"
  43. echo "Tests failed: $failed_tests"
  44. echo "===================================="
  45. if [ $failed_tests -ne 0 ]; then
  46. exit 1
  47. else
  48. exit 0
  49. fi