Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add golden test for reflection #2679

Merged
merged 19 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
201 changes: 201 additions & 0 deletions .github/workflows/reflection-golden-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
# https://help.github.com/en/categories/automating-your-workflow-with-github-actions

name: "Reflection golden test"

on:
pull_request:
paths-ignore:
- 'compiler/**'
- 'apigen/**'
- 'changelog-generator/**'
- 'issue-bot/**'
push:
branches:
- "1.10.x"
paths-ignore:
- 'compiler/**'
- 'apigen/**'
- 'changelog-generator/**'
- 'issue-bot/**'

env:
COMPOSER_ROOT_VERSION: "1.10.x-dev"
REFLECTION_GOLDEN_TEST_FILE: "/tmp/reflection-golden.test"
REFLECTION_GOLDEN_SYMBOLS_FILE: "/tmp/reflection-golden-symbols.txt"

concurrency:
group: reflection-golden-test-${{ github.head_ref || github.run_id }} # will be canceled on subsequent pushes in pull requests but not branches
cancel-in-progress: true

jobs:
dump-php-symbols:
name: "Dump PHP symbols"
runs-on: "ubuntu-latest"

steps:
- name: "Checkout"
uses: actions/checkout@v3

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "8.3"
# Include exotic extensions to discover more symbols
extensions: ds,mbstring,runkit7,scoutapm,seaslog,simdjson,var_representation,yac

- name: "Install dependencies"
run: "composer install --no-interaction --no-progress"

- name: "Dump phpSymbols.txt"
run: "php tests/dump-reflection-test-symbols.php"

- uses: actions/upload-artifact@v3
with:
name: phpSymbols
path: ${{ env.REFLECTION_GOLDEN_SYMBOLS_FILE }}

reflection-golden-test:
name: "Reflection golden test"
needs: dump-php-symbols
runs-on: "ubuntu-latest"
timeout-minutes: 60

strategy:
fail-fast: false
matrix:
php-version:
- "7.3"
- "7.4"
- "8.0"
- "8.1"
- "8.2"
- "8.3"

steps:
- name: "Download phpSymbols.txt"
uses: actions/download-artifact@v3
with:
name: phpSymbols
path: /tmp

- name: "Checkout base commit"
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.base.sha || github.event.push.before }}

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "${{ matrix.php-version }}"
tools: pecl
extensions: ds,mbstring
ini-file: development
ini-values: memory_limit=2G

- name: "Install dependencies"
run: "composer install --no-interaction --no-progress"

- name: "Install PHP for code transform"
if: matrix.php-version != '8.1' && matrix.php-version != '8.2' && matrix.php-version != '8.3'
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: 8.1
extensions: mbstring, intl

- name: "Rector downgrade cache key"
id: rector-cache-key-base
if: matrix.php-version != '8.1' && matrix.php-version != '8.2' && matrix.php-version != '8.3'
run: echo "sha=$(php build/rector-cache-files-hash.php)" >> $GITHUB_OUTPUT

- name: "Rector downgrade cache"
if: matrix.php-version != '8.1' && matrix.php-version != '8.2' && matrix.php-version != '8.3'
uses: actions/cache@v3
with:
path: ./tmp/rectorCache.php
key: "rector-v3-tests-${{ matrix.script }}-${{ matrix.operating-system }}-${{ hashFiles('composer.lock', 'build/rector-downgrade.php') }}-${{ matrix.php-version }}-${{ steps.rector-cache-key-base.outputs.sha }}"
restore-keys: |
rector-v3-tests-${{ matrix.script }}-${{ matrix.operating-system }}-${{ hashFiles('composer.lock', 'build/rector-downgrade.php') }}-${{ matrix.php-version }}-

- name: "Transform source code"
if: matrix.php-version != '8.1' && matrix.php-version != '8.2' && matrix.php-version != '8.3'
shell: bash
run: "build/transform-source ${{ matrix.php-version }}"

- name: "Reinstall matrix PHP version"
if: matrix.php-version != '8.1' && matrix.php-version != '8.2' && matrix.php-version != '8.3'
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "${{ matrix.php-version }}"
tools: pecl
extensions: ds,mbstring
ini-file: development
ini-values: memory_limit=2G

- name: "Dump previous reflection data"
run: "php tests/generate-reflection-test.php"

- uses: actions/upload-artifact@v3
with:
name: reflection-${{ matrix.php-version }}.test
path: ${{ env.REFLECTION_GOLDEN_TEST_FILE }}

- name: "Checkout"
uses: actions/checkout@v3

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "${{ matrix.php-version }}"
tools: pecl
extensions: ds,mbstring
ini-file: development
ini-values: memory_limit=2G
schlndh marked this conversation as resolved.
Show resolved Hide resolved

- name: "Install dependencies"
run: "composer install --no-interaction --no-progress"

- name: "Install PHP for code transform"
if: matrix.php-version != '8.1' && matrix.php-version != '8.2' && matrix.php-version != '8.3'
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: 8.1
extensions: mbstring, intl

- name: "Rector downgrade cache key"
id: rector-cache-key-head
if: matrix.php-version != '8.1' && matrix.php-version != '8.2' && matrix.php-version != '8.3'
run: echo "sha=$(php build/rector-cache-files-hash.php)" >> $GITHUB_OUTPUT

- name: "Rector downgrade cache"
if: matrix.php-version != '8.1' && matrix.php-version != '8.2' && matrix.php-version != '8.3'
uses: actions/cache@v3
with:
path: ./tmp/rectorCache.php
key: "rector-v3-tests-${{ matrix.script }}-${{ matrix.operating-system }}-${{ hashFiles('composer.lock', 'build/rector-downgrade.php') }}-${{ matrix.php-version }}-${{ steps.rector-cache-key-head.outputs.sha }}"
restore-keys: |
rector-v3-tests-${{ matrix.script }}-${{ matrix.operating-system }}-${{ hashFiles('composer.lock', 'build/rector-downgrade.php') }}-${{ matrix.php-version }}-

- name: "Transform source code"
if: matrix.php-version != '8.1' && matrix.php-version != '8.2' && matrix.php-version != '8.3'
shell: bash
run: "build/transform-source ${{ matrix.php-version }}"

- name: "Reinstall matrix PHP version"
if: matrix.php-version != '8.1' && matrix.php-version != '8.2' && matrix.php-version != '8.3'
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "${{ matrix.php-version }}"
tools: pecl
extensions: ds,mbstring
ini-file: development
ini-values: memory_limit=2G

- name: "Reflection golden test"
run: "make tests-golden-reflection"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
!.idea/icon.png
/tests/tmp
/tests/.phpunit.result.cache
/tests/PHPStan/Reflection/data/golden/
tmp/.memory_limit
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ tests-levels:
tests-coverage:
php vendor/bin/paratest --runner WrapperRunner

tests-golden-reflection:
php vendor/bin/paratest --runner WrapperRunner --no-coverage tests/PHPStan/Reflection/ReflectionProviderGoldenTest.php

lint:
php vendor/bin/parallel-lint --colors \
--exclude tests/PHPStan/Analyser/data \
Expand Down
5 changes: 5 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -1742,6 +1742,11 @@ parameters:
count: 1
path: tests/PHPStan/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocatorTest.php

-
message: "#^Creating new PHPStan\\\\Php8StubsMap is not covered by backward compatibility promise\\. The class might change in a minor PHPStan version\\.$#"
count: 1
path: tests/PHPStan/Reflection/ReflectionProviderGoldenTest.php

-
message: "#^Creating new PHPStan\\\\Php8StubsMap is not covered by backward compatibility promise\\. The class might change in a minor PHPStan version\\.$#"
count: 1
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<testsuites>
<testsuite name="PHPStan">
<directory suffix="Test.php">tests/PHPStan</directory>
<exclude>tests/PHPStan/Reflection/ReflectionProviderGoldenTest.php</exclude>
</testsuite>
</testsuites>

Expand Down