Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 15 additions & 4 deletions core/Output/Terminal/Renderer/RunStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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),
);
}

Expand All @@ -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);
}
}
8 changes: 4 additions & 4 deletions core/Pipeline/Attribute/InterceptorOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -40,15 +40,15 @@
/**
* 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.
*
* 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
Expand All @@ -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(
/**
Expand Down
2 changes: 1 addition & 1 deletion plugin/bench/tests/Unit/BenchTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 18 additions & 0 deletions tests/Core/Pipeline/Attribute/InterceptorOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading