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
69 changes: 69 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Tests

env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true

on:
pull_request:
push:
branches:
- main
workflow_dispatch:

permissions:
contents: read

jobs:
tests:
name: PHP ${{ matrix.php-version }}
runs-on: ubuntu-latest
timeout-minutes: 15
continue-on-error: ${{ matrix.experimental }}
strategy:
fail-fast: false
matrix:
include:
- php-version: '8.2'
experimental: false
- php-version: '8.3'
experimental: false
- php-version: '8.4'
experimental: false
- php-version: '8.5'
experimental: false
- php-version: 'nightly'
experimental: true

steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false

- name: Setup PHP
uses: shivammathur/setup-php@9e72090525849c5e82e596468b86eb55e9cc5401 # 2.32.0
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, xml, soap, zip
coverage: none

- name: Validate Composer files
run: composer validate

- name: Get Composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT"

- name: Cache Composer packages
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-php-${{ matrix.php-version }}-composer-${{ hashFiles('composer.lock') }}
restore-keys: |
${{ runner.os }}-php-${{ matrix.php-version }}-composer-

- name: Install dependencies
run: composer install --no-progress --prefer-dist

- name: Run tests
run: composer test
19 changes: 19 additions & 0 deletions Dockerfile.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
ARG PHP_VERSION=8.2

FROM php:${PHP_VERSION}-cli

RUN apt-get update \
&& apt-get install -y --no-install-recommends \
git \
libonig-dev \
libxml2-dev \
libzip-dev \
unzip \
&& docker-php-ext-install mbstring soap zip \
&& rm -rf /var/lib/apt/lists/*

COPY --from=composer:2 /usr/bin/composer /usr/bin/composer

WORKDIR /app

CMD ["composer", "test"]
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@ To run tests for all packages that have them, run the following command from the
composer test
```

GitHub Actions runs the full test suite on every pull request and push to `main` across the supported PHP versions: 8.2, 8.3, 8.4, and 8.5. It also runs a non-blocking `nightly` job so upcoming PHP compatibility issues show up early.

PHPUnit is configured to fail on notices, warnings, deprecations, PHPUnit warnings, and PHPUnit deprecations from the package source. Indirect dependency deprecations are ignored, so third-party internals do not hide Pulp compatibility issues.

To reproduce the supported PHP matrix locally with Docker, run:

```bash
bin/test-php-matrix
```

To run only selected versions, set `PHP_VERSIONS`:

```bash
PHP_VERSIONS="8.4 8.5" bin/test-php-matrix
```

Or run the PHP script directly:
```bash
php test.php
Expand Down
34 changes: 34 additions & 0 deletions bin/test-php-matrix
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash

set -euo pipefail

repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
versions="${PHP_VERSIONS:-8.2 8.3 8.4 8.5}"
composer_cache="${COMPOSER_CACHE_DIR:-$repo_root/build/composer-cache}"
tty_args=()

if [ -t 1 ]; then
tty_args=(-t)
fi

mkdir -p "$composer_cache"

for version in $versions; do
image="mapsight-pulp-test-php:$version"

echo "==> Building PHP $version test image"
docker build \
--build-arg "PHP_VERSION=$version" \
-t "$image" \
-f "$repo_root/Dockerfile.test" \
"$repo_root"

echo "==> Running tests on PHP $version"
docker run --rm "${tty_args[@]}" \
-e COMPOSER_CACHE_DIR=/tmp/composer-cache \
-v "$repo_root:/app" \
-v "$composer_cache:/tmp/composer-cache" \
-w /app \
"$image" \
sh -lc 'composer install --no-progress --prefer-dist && composer test'
done
4 changes: 2 additions & 2 deletions packages/pulp-concert/src/PulpConcert.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ public static function trafficMessagesToGeoJSON(): TrafficMessagsToGeoJSONHandle
}

public static function parseTrafficCounters(
Pulp $counterDataPulp = null,
Pulp $counterDerivedDataPulp = null
?Pulp $counterDataPulp = null,
?Pulp $counterDerivedDataPulp = null
): ParseCountersHandler {
return new ParseCountersHandler($counterDataPulp, $counterDerivedDataPulp);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/pulp-concert/src/pulpconcert/Model/DataObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function getAllPropertiesAsArray(): array
];
}

public function jsonSerialize()
public function jsonSerialize(): mixed
{
return $this->getAllPropertiesAsArray();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function getAllPropertiesAsArray(): array
];
}

public function jsonSerialize()
public function jsonSerialize(): mixed
{
return $this->getAllPropertiesAsArray();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function getAllPropertiesAsArray(): array
];
}

public function jsonSerialize()
public function jsonSerialize(): mixed
{
return $this->getAllPropertiesAsArray();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/pulp-geocsv/src/FromCsvHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function onFile(File $file): void

$rows = explode($ls, $csv);
$rows = array_map(static function ($row) use ($fs, $qc): array {
$items = str_getcsv($row, $fs, $qc);
$items = str_getcsv($row, $fs, $qc, '');
return array_map(stripslashes(...), $items);
}, $rows);

Expand Down
2 changes: 1 addition & 1 deletion packages/pulp-geocsv/src/ToCsvHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function onFile(File $file): void
protected static function makeCsvString(array $fields, string $delimiter, string $enclosure): string
{
$f = fopen('php://memory', 'rwb');
if (fputcsv($f, $fields, $delimiter, $enclosure) === false) {
if (fputcsv($f, $fields, $delimiter, $enclosure, '') === false) {
return false;
}
rewind($f);
Expand Down
2 changes: 1 addition & 1 deletion packages/pulp-geojson/PulpGeoJSON.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public static function setIds(): SetIdsHandler
}

public static function fromArcGisJson(
string $idAttribute = null
?string $idAttribute = null
): FromArcGisJsonHandler {
return new FromArcGisJsonHandler($idAttribute);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/pulp-gtfs/src/GtfsDirectoryReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ public function csvRows(string $fileName): Generator
}

try {
$headers = fgetcsv($stream);
$headers = fgetcsv($stream, null, ',', '"', '');
if ($headers === false) {
return;
}

$headers[0] = preg_replace('/^\xEF\xBB\xBF/', '', (string)$headers[0]);
$headerCount = count($headers);

while (($row = fgetcsv($stream)) !== false) {
while (($row = fgetcsv($stream, null, ',', '"', '')) !== false) {
if ($row === [null] || $row === []) {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/pulp-gtfs/src/GtfsFileSetReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ public function csvRows(string $fileName): Generator
$stream = $file->stream();

try {
$headers = fgetcsv($stream);
$headers = fgetcsv($stream, null, ',', '"', '');
if ($headers === false) {
return;
}

$headers[0] = preg_replace('/^\xEF\xBB\xBF/', '', (string)$headers[0]);
$headerCount = count($headers);

while (($row = fgetcsv($stream)) !== false) {
while (($row = fgetcsv($stream, null, ',', '"', '')) !== false) {
if ($row === [null] || $row === []) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/pulp-gtfs/test/GtfsGeoJsonBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ private function writeCsv(string $directory, string $fileName, array $rows): voi
$this->assertIsResource($stream);

foreach ($rows as $row) {
fputcsv($stream, $row);
fputcsv($stream, $row, ',', '"', '');
}

fclose($stream);
Expand Down
1 change: 1 addition & 0 deletions packages/pulp-tic/test/files/tmp/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

28 changes: 27 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php">
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
failOnDeprecation="true"
failOnNotice="true"
failOnPhpunitDeprecation="true"
failOnPhpunitWarning="true"
failOnWarning="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnPhpunitDeprecations="true"
displayDetailsOnTestsThatTriggerWarnings="true"
>
<php>
<ini name="error_reporting" value="-1"/>
<ini name="display_errors" value="1"/>
</php>
<source
restrictNotices="true"
restrictWarnings="true"
ignoreIndirectDeprecations="true"
>
<include>
<directory>packages</directory>
</include>
</source>
<testsuites>
<testsuite name="geojson-reproject">
<directory>packages/geojson-reproject/test</directory>
Expand Down
Loading