diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 76e5adb0..4913040a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -76,6 +76,42 @@ jobs: - name: Run Tests run: composer test:ci + ci-32bit: + runs-on: ubuntu-latest + name: Tests PHP8.4-32bit + + steps: + + - name: Checkout + uses: actions/checkout@v7 + + - name: Resolve root package version + run: echo "COMPOSER_ROOT_VERSION=$(jq -r '.["."]' resources/version.json)" >> "$GITHUB_ENV" + + # Dependencies are installed by a 64-bit PHP of the same version: the runner's actions do not + # run inside an i386 container, and the vendor code is the same for both. + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.4 + coverage: none + + - name: Install Composer dependencies + uses: ramsey/composer-install@v3 + with: + dependency-versions: highest + + - name: Install bin tools + run: composer bin all install --ignore-platform-req=php + + # Rector itself packs 64-bit values, so its fixtures cannot run on 32-bit PHP. + - name: Run Tests on 32-bit PHP + run: >- + docker run --rm --platform linux/386 + -v "$PWD":/app -w /app -e TESTO_CI=1 + php:8.4-cli + sh -c 'php -r "echo PHP_INT_SIZE * 8, \" bit\n\"; exit(PHP_INT_SIZE === 4 ? 0 : 1);" && php vendor/bin/testo --type=!rector-fixture' + code-coverage: runs-on: ubuntu-latest name: Code Coverage diff --git a/core/Output/Terminal/Renderer/RunStatus.php b/core/Output/Terminal/Renderer/RunStatus.php index e0b57197..3ba281e9 100644 --- a/core/Output/Terminal/Renderer/RunStatus.php +++ b/core/Output/Terminal/Renderer/RunStatus.php @@ -110,8 +110,8 @@ public function caseStarted(CaseInfo $case): void $width = $this->suiteEnd - $this->suiteStart; $count = \count($this->cases); - $this->caseStart = $this->suiteStart + \intdiv($width * $index, $count); - $this->caseEnd = $this->suiteStart + \intdiv($width * ($index + 1), $count); + $this->caseStart = $this->suiteStart + self::share($width, $index, $count); + $this->caseEnd = $this->suiteStart + self::share($width, $index + 1, $count); $this->caseTests = \count($case->definition->tests->getTests()); $this->caseFinished = 0; $this->report($this->caseStart); @@ -125,7 +125,7 @@ public function testFinished(): void $this->caseFinished = \min($this->caseFinished + 1, $this->caseTests); $this->report( - $this->caseStart + \intdiv(($this->caseEnd - $this->caseStart) * $this->caseFinished, $this->caseTests), + $this->caseStart + self::share($this->caseEnd - $this->caseStart, $this->caseFinished, $this->caseTests), ); } @@ -146,8 +146,19 @@ public function sessionFinished(RunResult $result): void }; } + /** + * The `$part` of `$whole` shares of `$width`, rounded down. + * + * The product is taken in float: on 32-bit PHP it overflows int. It stays exact below 2^53, and the full + * share gives exactly `$width`. + */ + private static function share(int $width, int $part, int $whole): int + { + return (int) \floor((float) $width * $part / $whole); + } + private function report(int $position): void { - $this->status->working(\intdiv(100 * $position, self::SCALE), $this->suiteName); + $this->status->working(self::share(100, $position, self::SCALE), $this->suiteName); } } diff --git a/core/Pipeline/Attribute/InterceptorOptions.php b/core/Pipeline/Attribute/InterceptorOptions.php index dadd66ba..dfb3ac88 100644 --- a/core/Pipeline/Attribute/InterceptorOptions.php +++ b/core/Pipeline/Attribute/InterceptorOptions.php @@ -17,7 +17,7 @@ /** * Handles {@see Interceptable} attributes */ - public const ORDER_ATTRIBUTES = -300_000_000_000; + public const ORDER_ATTRIBUTES = -1_000_000_000; /** * Filtering files, classes, tests, etc. @@ -40,7 +40,7 @@ /** * Interceptors that are applied right before the test function. */ - public const ORDER_RIGHT_BEFORE_TEST = 300_000_000_000; + public const ORDER_RIGHT_BEFORE_TEST = 1_000_000_000; /** * Collects code coverage for the test. @@ -48,7 +48,7 @@ * Outer to {@see ORDER_ASYNC_COROUTINE} on purpose: a collector has to close its window around * every fiber switch it can see, and it can only do that for fibers Testo drives itself. */ - public const ORDER_COVERAGE = 300_000_100_000; + public const ORDER_COVERAGE = 1_001_000_000; /** * Hands the test body to a coroutine — an event loop, a coroutine scope — that owns the fiber it @@ -58,7 +58,7 @@ * {@see ORDER_COVERAGE}: a suspension relayed out of a fiber the interceptor does not drive is * never resumed. */ - public const ORDER_ASYNC_COROUTINE = 300_000_300_000; + public const ORDER_ASYNC_COROUTINE = 1_003_000_000; public function __construct( /** diff --git a/plugin/bench/tests/Unit/BenchTableTest.php b/plugin/bench/tests/Unit/BenchTableTest.php index 3bd24a55..5d58d6cb 100644 --- a/plugin/bench/tests/Unit/BenchTableTest.php +++ b/plugin/bench/tests/Unit/BenchTableTest.php @@ -170,7 +170,7 @@ public function roundsRendersZeroTimeAndMemoryAsBareZero(): void #[DataSet([0.5, 512, '500.00ns', '512 B'], 'sub-microsecond -> ns, sub-kibibyte -> bytes')] #[DataSet([5.0, 2048, '5.00µs', '2.00 KB'], 'microseconds and kibibytes')] #[DataSet([5000.0, 3145728, '5.00ms', '3.00 MB'], 'milliseconds and mebibytes')] - #[DataSet([2000000.0, 2147483648, '2.00s', '2.00 GB'], 'seconds and gibibytes')] + #[DataSet([2000000.0, 1610612736, '2.00s', '1.50 GB'], 'seconds and gibibytes')] public function roundsFormatsTimeAndMemoryMagnitudes( float $time, int $memory, diff --git a/tests/Core/Pipeline/Attribute/InterceptorOptionsTest.php b/tests/Core/Pipeline/Attribute/InterceptorOptionsTest.php index 37b0f0c8..1ece2612 100644 --- a/tests/Core/Pipeline/Attribute/InterceptorOptionsTest.php +++ b/tests/Core/Pipeline/Attribute/InterceptorOptionsTest.php @@ -38,6 +38,24 @@ public function resolvableAsClassAttribute(): void Assert::same(ConflictPolicy::Merge, $options->onConflict); Assert::same(['unit', 'integration'], $options->testType); } + + /** + * On 32-bit PHP a literal above 2^31-1 compiles to float and breaks the `int $order` parameter. + */ + public function orderConstantsFitIn32BitInt(): void + { + $constants = (new \ReflectionClass(InterceptorOptions::class))->getConstants(); + + foreach ($constants as $name => $value) { + if (!\str_starts_with($name, 'ORDER_')) { + continue; + } + + Assert::int($value) + ->greaterThanOrEqual(-2_147_483_648) + ->lessThanOrEqual(2_147_483_647); + } + } } #[InterceptorOptions(