diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index 51288050a..147e6498c 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -16,29 +16,11 @@ jobs: fail-fast: false matrix: include: - - php-version: "8.0" - db-image: 'mysql:8.0' - reflector: "pdo-mysql" - mode: "recording" - php-version: "8.0" db-image: 'mysql:8.0' reflector: "mysqli" mode: "recording" - - php-version: "8.1" - db-image: 'mysql:8.0' - reflector: "mysqli" - mode: "recording" - - php-version: '8.1' - db-image: 'mariadb:latest' - reflector: "mysqli" - mode: "recording" - - - php-version: "8.1" - db-image: 'mysql:8.0' - reflector: "mysqli" - mode: "replay-and-recording" - env: DBA_REFLECTOR: ${{ matrix.reflector }} DBA_MODE: ${{ matrix.mode }} @@ -75,41 +57,3 @@ jobs: mysql -uroot -h127.0.0.1 -proot < tests/schema.sql - run: composer phpstan - - replay: - name: PHPStan (reflection replay) - runs-on: ubuntu-latest - - strategy: - fail-fast: false - matrix: - include: - - php-version: "8.1" - reflector: "mysqli" - mode: "replay" - - php-version: "8.1" - reflector: "pdo-mysql" - mode: "replay" - - env: - DBA_REFLECTOR: ${{ matrix.reflector }} - DBA_MODE: ${{ matrix.mode }} - - steps: - - uses: actions/checkout@v2 - with: - repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }} - ref: ${{ github.event.client_payload.pull_request.head.ref }} - - - name: Setup PHP - id: setup-php - uses: shivammathur/setup-php@v2 - with: - php-version: "${{ matrix.php-version }}" - coverage: none - - - uses: "ramsey/composer-install@v2" - with: - composer-options: "--prefer-dist --no-progress" - - - run: composer phpstan diff --git a/.github/workflows/tests-postgres.yml b/.github/workflows/tests-postgres.yml deleted file mode 100644 index 812206340..000000000 --- a/.github/workflows/tests-postgres.yml +++ /dev/null @@ -1,69 +0,0 @@ -name: Unit Tests Postgres - -on: - push: - branches: - - main - pull_request: - -jobs: - phpunit: - name: PHPUnit - runs-on: ubuntu-latest - - strategy: - fail-fast: false - matrix: - include: - - php-version: "8.0" - db-image: 'postgres:14' - reflector: "pdo-pgsql" - mode: "recording" - - env: - DBA_REFLECTOR: ${{ matrix.reflector }} - DBA_MODE: ${{ matrix.mode }} - DBA_USER: postgres - DBA_DATABASE: postgres - DBA_PASSWORD: postgres - - # https://docs.github.com/en/free-pro-team@latest/actions/guides/about-service-containers - services: - postgres: - image: ${{ matrix.db-image }} - env: - POSTGRES_PASSWORD: postgres - options: --health-cmd=pg_isready --health-interval=10s --health-timeout=5s --health-retries=3 - ports: - - 5432:5432 - - steps: - - uses: actions/checkout@v2 - with: - repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }} - ref: ${{ github.event.client_payload.pull_request.head.ref }} - - - name: Setup PHP with PDO - uses: shivammathur/setup-php@v2 - with: - php-version: "${{ matrix.php-version }}" - coverage: none - - - uses: "ramsey/composer-install@v2" - with: - composer-options: "--prefer-dist --no-progress" - - - name: Setup Problem Matchers for PHPUnit - run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - - - name: Install PostgreSQL client - run: | - sudo apt-get update - sudo apt-get install --yes postgresql-client - - - name: Setup PSQL - run: psql -h localhost -U postgres < tests/pgsql-schema.sql - env: - PGPASSWORD: postgres - - - run: composer phpunit diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml deleted file mode 100644 index 17a5f676c..000000000 --- a/.github/workflows/tests.yml +++ /dev/null @@ -1,126 +0,0 @@ -name: Unit Tests MySQL - -on: - push: - branches: - - main - pull_request: - -jobs: - - phpunit: - name: PHPUnit - runs-on: ubuntu-latest - - strategy: - fail-fast: false - matrix: - include: - - php-version: "7.4" - db-image: 'mysql:8.0' - reflector: "pdo-mysql" - mode: "recording" - - php-version: "8.0" - db-image: 'mysql:8.0' - reflector: "pdo-mysql" - mode: "recording" - - php-version: "8.0" - db-image: 'mysql:8.0' - reflector: "mysqli" - mode: "recording" - - - php-version: "8.1" - db-image: 'mysql:8.0' - reflector: "mysqli" - mode: "recording" - - php-version: '8.1' - db-image: 'mariadb:latest' - reflector: "mysqli" - mode: "recording" - - - php-version: "8.1" - db-image: 'mysql:8.0' - reflector: "pdo-mysql" - mode: "replay-and-recording" - - env: - DBA_REFLECTOR: ${{ matrix.reflector }} - DBA_MODE: ${{ matrix.mode }} - - # https://docs.github.com/en/free-pro-team@latest/actions/guides/about-service-containers - services: - mysql: - image: ${{ matrix.db-image }} - env: - MYSQL_ROOT_PASSWORD: root - ports: - - 3306:3306 - options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 - - steps: - - uses: actions/checkout@v2 - with: - repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }} - ref: ${{ github.event.client_payload.pull_request.head.ref }} - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: "${{ matrix.php-version }}" - coverage: none - - - uses: "ramsey/composer-install@v2" - with: - composer-options: "--prefer-dist --no-progress" - - - name: Setup Problem Matchers for PHPUnit - run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - - - name: Lint - run: php vendor/bin/parallel-lint --colors src tests - - - name: Setup mysql - run: | - mysql -uroot -h127.0.0.1 -proot < tests/schema.sql - - - run: composer phpunit - - replay: - name: PHPUnit (reflection replay) - runs-on: ubuntu-latest - - strategy: - fail-fast: false - matrix: - include: - - php-version: "8.1" - reflector: "pdo-mysql" - mode: "replay" - - php-version: "8.1" - reflector: "mysqli" - mode: "replay" - - env: - DBA_REFLECTOR: ${{ matrix.reflector }} - DBA_MODE: ${{ matrix.mode }} - - steps: - - uses: actions/checkout@v2 - with: - repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }} - ref: ${{ github.event.client_payload.pull_request.head.ref }} - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: "${{ matrix.php-version }}" - coverage: none - - - uses: "ramsey/composer-install@v2" - with: - composer-options: "--prefer-dist --no-progress" - - - name: Setup Problem Matchers for PHPUnit - run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - - - run: composer phpunit diff --git a/bootstrap.php b/bootstrap.php index b0ebbdbec..a5c442ed8 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -15,6 +15,7 @@ $config = RuntimeConfiguration::create(); $config->errorMode(RuntimeConfiguration::ERROR_MODE_EXCEPTION); // $config->debugMode(true); +$config->analyzeQueryPlans(true, 2); if (false === getenv('GITHUB_ACTION') && false === getenv('DBA_MODE')) { putenv('DBA_MODE=replay-and-recording'); diff --git a/demo.php b/demo.php new file mode 100644 index 000000000..71585f757 --- /dev/null +++ b/demo.php @@ -0,0 +1,41 @@ +query('SELECT email, adaid FROM ada', PDO::FETCH_ASSOC); + + foreach ($stmt as $row) { + parse_str($row['adaid'], $x); + if ($row['email'] + 25) { + $x = $row['doesnotexit']; + } + } + + // ---------- query plan analysis ---------- + + $pdo->query("SELECT * FROM `ada` WHERE email = 'test@example.com';"); + + // ---------- in-depth query analysis ---------- + + $pdo->query('SELECT * FROM unknownTable', PDO::FETCH_ASSOC); + + $pdo->query('SELECT email adaid WHERE gesperrt freigabe1u1 FROM ada', PDO::FETCH_ASSOC); + + $pdo->query('SELECT doesNotExist, adaid, gesperrt, freigabe1u1 FROM ada', PDO::FETCH_ASSOC); + + $stmt = $pdo->prepare('SELECT email, adaid FROM ada WHERE adaid = :adaid'); + $stmt->execute([':wrongParamName' => 1]); + + $stmt = $pdo->prepare('SELECT email, adaid FROM ada WHERE adaid = :adaid'); + $stmt->execute(); + + $stmt = $pdo->prepare('SELECT email, adaid FROM ada WHERE adaid = ? and email = ?'); + $stmt->execute([1]); + + $stmt = $pdo->prepare('SELECT email, adaid FROM ada WHERE adaid = :adaid and email = :email'); + $stmt->execute(['adaid' => 1]); + + $stmt = $pdo->prepare('SELECT email, adaid FROM ada WHERE adaid = :adaid and email = :email'); + $stmt->execute([':email' => 'email@example.org']); +} diff --git a/phpstan.neon.dist b/phpstan.neon.dist index a66a82f3a..a5eecb0ca 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,12 +1,11 @@ includes: - - config/stubFiles.neon - - config/extensions.neon + - config/dba.neon parameters: level: max paths: - - src/ + - demo.php bootstrapFiles: - bootstrap.php