|
1 | 1 | name: PHPUnit & Psalm |
2 | 2 |
|
3 | | -on: [push] |
4 | | - |
5 | | -permissions: |
6 | | - contents: read |
| 3 | +on: [pull_request] |
7 | 4 |
|
8 | 5 | jobs: |
9 | 6 | phpunit: |
10 | | - runs-on: ubuntu-latest |
11 | | - |
| 7 | + runs-on: ubuntu-22.04 |
12 | 8 | strategy: |
13 | 9 | matrix: |
14 | | - include: |
15 | | - - php: '8.0' |
16 | | - - php: '8.1' |
17 | | - - php: '8.2' |
18 | | - steps: |
19 | | - - name: Checkout |
20 | | - uses: actions/checkout@v4 |
21 | | - with: |
22 | | - fetch-depth: 2 |
| 10 | + php-version: [8.0, 8.1, 8.2, 8.3] |
| 11 | + services: |
| 12 | + mysql: |
| 13 | + image: mysql:8.0 |
| 14 | + env: |
| 15 | + MYSQL_ROOT_PASSWORD: root |
| 16 | + MYSQL_DATABASE: test_db |
| 17 | + MYSQL_USER: test_user |
| 18 | + MYSQL_PASSWORD: test_password |
| 19 | + ports: |
| 20 | + - 3306:3306 |
| 21 | + options: >- |
| 22 | + --health-cmd="mysqladmin ping --silent" |
| 23 | + --health-interval=10s |
| 24 | + --health-timeout=5s |
| 25 | + --health-retries=3 |
| 26 | + postgres: |
| 27 | + image: postgres:14 |
| 28 | + env: |
| 29 | + POSTGRES_USER: test_user |
| 30 | + POSTGRES_PASSWORD: test_password |
| 31 | + POSTGRES_DB: test_db |
| 32 | + ports: |
| 33 | + - 5432:5432 |
| 34 | + options: >- |
| 35 | + --health-cmd="pg_isready" |
| 36 | + --health-interval=10s |
| 37 | + --health-timeout=5s |
| 38 | + --health-retries=3 |
23 | 39 |
|
24 | | - - name: Copy .env |
25 | | - run: php -r "file_exists('.env') || copy('.env.example', '.env');" |
26 | | - |
27 | | - - name: Load .env file |
28 | | - uses: xom9ikk/dotenv@v2 |
29 | | - |
30 | | - - uses: isbang/compose-action@v1.4.1 |
31 | | - with: |
32 | | - compose-file: "./docker-compose.yml" |
| 40 | + steps: |
| 41 | + - uses: actions/checkout@v4 |
33 | 42 |
|
34 | 43 | - name: Setup PHP |
35 | 44 | uses: shivammathur/setup-php@v2 |
36 | 45 | with: |
37 | | - coverage: "none" |
38 | | - php-version: "${{ matrix.php }}" |
39 | | - tools: flex |
| 46 | + php-version: ${{ matrix.php-version }} |
| 47 | + extensions: mbstring, pdo, mysql, pgsql |
| 48 | + coverage: none |
| 49 | + |
| 50 | + - name: Wait for MySQL |
| 51 | + run: | |
| 52 | + echo "Waiting for MySQL..." |
| 53 | + until mysqladmin ping -h 127.0.0.1 --silent; do |
| 54 | + sleep 2 |
| 55 | + done |
| 56 | + echo "MySQL is up!" |
| 57 | +
|
| 58 | + echo "Waiting for PostgreSQL..." |
| 59 | + until pg_isready -h 127.0.0.1 -p 5432; do |
| 60 | + sleep 2 |
| 61 | + done |
| 62 | + echo "PostgreSQL is up!" |
40 | 63 |
|
41 | 64 | - name: Install dependencies |
42 | | - run: composer install --prefer-dist --no-progress |
| 65 | + run: composer install --prefer-dist --no-progress --ignore-platform-reqs |
43 | 66 |
|
44 | | - - name: Waiting for MySQL |
| 67 | + - name: Create .env file for testing |
45 | 68 | run: | |
46 | | - while ! mysqladmin ping --host=${{ env.MYSQL_HOST }} --port=${{ env.MYSQL_PORT }} --password=${{ env.MYSQL_PASSWORD }} --silent; do |
47 | | - sleep 1 |
48 | | - done |
| 69 | + echo "POSTGRESQL_HOST=127.0.0.1" > .env |
| 70 | + echo "POSTGRESQL_DATABASE=test_db" >> .env |
| 71 | + echo "POSTGRESQL_USERNAME=test_user" >> .env |
| 72 | + echo "POSTGRESQL_PASSWORD=test_password" >> .env |
| 73 | + echo "POSTGRESQL_PORT=5432" >> .env |
| 74 | + echo "MYSQL_HOST=127.0.0.1" >> .env |
| 75 | + echo "MYSQL_DATABASE=test_db" >> .env |
| 76 | + echo "MYSQL_USERNAME=test_user" >> .env |
| 77 | + echo "MYSQL_PASSWORD=test_password" >> .env |
| 78 | + echo "MYSQL_PORT=3306" >> .env |
| 79 | +
|
| 80 | + - name: Run Tests |
| 81 | + run: ./vendor/bin/phpunit --testdox |
49 | 82 |
|
50 | | - - name: PHPUnit |
51 | | - run: ./vendor/bin/phpunit |
52 | 83 | psalm: |
53 | | - runs-on: ubuntu-latest |
54 | | - |
| 84 | + runs-on: ubuntu-22.04 |
55 | 85 | env: |
56 | | - php-version: '8.0' |
| 86 | + php_version: '8.0' |
| 87 | + |
57 | 88 | steps: |
58 | 89 | - name: Setup PHP |
59 | 90 | uses: shivammathur/setup-php@v2 |
60 | 91 | with: |
61 | | - php-version: ${{ env.php-version }} |
| 92 | + php-version: ${{ env.php_version }} |
62 | 93 | ini-values: "memory_limit=-1" |
63 | 94 | coverage: none |
64 | 95 |
|
|
0 commit comments