Skip to content

chore: upgrade PHPStan to 2.x and fix reported errors - #74

Merged
shyim merged 2 commits into
mainfrom
chore/phpstan-2
Sep 14, 2026
Merged

shyim merged 2 commits into
mainfrom
chore/phpstan-2

Conversation

@shyim

@shyim shyim commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator

Summary

Upgrades PHPStan from 1.12 to 2.2 (plus phpstan-phpunit 2.0) and fixes everything it reports at level 9.

Dependency changes

  • phpstan/phpstan ^1.8^2.2
  • phpstan/phpstan-phpunit ^1.1^2.0
  • phpstan/extension-installer ^1.2^1.4
  • beluga-php/docker-php ^1.45^1.45.7 and an explicit beluga-php/docker-php-api ^7.1.45.5, since older releases still ship the old EndpointSettings constructor and nullable FETCH_RESPONSE return types

Source fixes

  • GenericContainer: EndpointSettings no longer has an array constructor in the current docker-php-api, so it is now built via setNetworkID()/setAliases(). The aliases and mounts properties and the port bindings return type are typed as list<> to match the Docker API setters.
  • StartedGenericContainer: execStart/containerLogs with FETCH_RESPONSE return a non-null response, so the nullsafe calls and ?? '' fallbacks were dead code. getFirstMappedPort() now throws instead of indexing with null when array_key_first() returns null.
  • PortNormalizer: removed a redundant is_string() check.
  • WaitForExec: command parameter documented as list<string>, matching StartedTestContainer::exec().
  • WaitForHttp: URL built via interpolation and typed non-empty-string for CURLOPT_URL.

Test fixes

  • OpenSearchContainerTest passed JSON_THROW_ON_ERROR as the depth argument of json_decode(); fixed to use the default depth and assert on the decoded array directly.
  • Removed an always-true assertNotNull() and tightened two anonymous test class return types.
  • Removed ReflectionProperty::setAccessible() calls, which are no-ops since PHP 8.1 and emit deprecations on PHP 8.5 that failed six unit tests.

Test plan

  • composer run phpstan — no errors at level 9
  • vendor/bin/phpunit tests/Unit — 33 tests pass
  • php-cs-fixer --dry-run — clean
  • Integration tests (CI, requires Docker)

🤖 Generated with Claude Code

Upgrade phpstan/phpstan to ^2.2 and phpstan/phpstan-phpunit to ^2.0.

Fix errors reported against the updated docker-php-api types and the
stricter list<> inference in PHPStan 2:

- Build EndpointSettings via setters (no array constructor anymore)
- Drop dead nullsafe calls on execStart/containerLogs responses
- Type aliases, mounts and port bindings as lists
- Guard array_key_first() returning null in getFirstMappedPort()
- Pass a correct depth to json_decode() in OpenSearchContainerTest
- Remove redundant type checks and assertions in tests
- Remove ReflectionProperty::setAccessible() calls (no-op since 8.1,
  deprecated in PHP 8.5)

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@netlify

netlify Bot commented Sep 14, 2026

Copy link
Copy Markdown

Deploy Preview for testcontainers-php ready!

Name Link
🔨 Latest commit 969bb44
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-php/deploys/6aa7ebe97d2f500008d72df2
😎 Deploy Preview https://deploy-preview-74--testcontainers-php.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Older releases ship the previous EndpointSettings constructor and
nullable FETCH_RESPONSE return types the code no longer targets.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@shyim
shyim merged commit 551f3fa into main Sep 14, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant