Skip to content

Commit b492f09

Browse files
committed
Drop EOLed php versions
- add Github Actions to replace old CI (part 1/3) - upgrade PHPUnit to v9 - lock symfony/var-dumper to v5.2 as @stable is too wide for testing (lowest is incompatible, symfony/var-dumper/Resources/functions/dump.php is missing)
1 parent b3cb411 commit b492f09

12 files changed

+138
-177
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: "Continuous Integration"
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- "master"
8+
schedule:
9+
- cron: "42 3 * * *"
10+
11+
env:
12+
fail-fast: true
13+
14+
jobs:
15+
phpunit:
16+
name: "PHPUnit"
17+
runs-on: "ubuntu-20.04"
18+
19+
strategy:
20+
matrix:
21+
php-version:
22+
- "7.3"
23+
- "7.4"
24+
- "8.0"
25+
dependencies:
26+
- "highest"
27+
include:
28+
- dependencies: "lowest"
29+
php-version: "7.3"
30+
31+
steps:
32+
- name: "Checkout"
33+
uses: "actions/checkout@v2"
34+
with:
35+
fetch-depth: 2
36+
37+
- name: "Install PHP"
38+
uses: "shivammathur/setup-php@v2"
39+
with:
40+
php-version: "${{ matrix.php-version }}"
41+
coverage: "pcov"
42+
ini-values: "zend.assertions=1"
43+
44+
- name: "Install dependencies with Composer"
45+
uses: "ramsey/composer-install@v1"
46+
with:
47+
dependency-versions: "${{ matrix.dependencies }}"
48+
49+
- name: "Run PHPUnit"
50+
run: "vendor/bin/phpunit --coverage-clover=coverage.xml"
51+
52+
- name: "Upload coverage file"
53+
uses: "actions/upload-artifact@v2"
54+
with:
55+
name: "phpunit-sqlite-${{ matrix.deps }}-${{ matrix.php-version }}.coverage"
56+
path: "coverage.xml"
57+
58+
upload_coverage:
59+
name: "Upload coverage to Codecov"
60+
runs-on: "ubuntu-20.04"
61+
needs:
62+
- "phpunit"
63+
64+
steps:
65+
- name: "Checkout"
66+
uses: "actions/checkout@v2"
67+
with:
68+
fetch-depth: 2
69+
70+
- name: "Download coverage files"
71+
uses: "actions/download-artifact@v2"
72+
with:
73+
path: "reports"
74+
75+
- name: "Upload to Codecov"
76+
uses: "codecov/codecov-action@v1"
77+
with:
78+
directory: reports

.scrutinizer.yml

Lines changed: 0 additions & 32 deletions
This file was deleted.

.travis.yml

Lines changed: 0 additions & 37 deletions
This file was deleted.

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
]
1616
},
1717
"require": {
18-
"php": ">=5.3"
18+
"php": "^7.3 || ^8.0"
1919
},
2020
"require-dev": {
21-
"phpunit/phpunit": "^4.0|^5.0|^6.0|^7.0",
21+
"phpunit/phpunit": "^9",
2222
"squizlabs/php_codesniffer": "^2.0|^3.4",
23-
"symfony/var-dumper": "@stable"
23+
"symfony/var-dumper": "^5.2"
2424
}
2525
}

phpunit.xml.dist

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,21 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit backupGlobals="false"
3-
backupStaticAttributes="false"
4-
beStrictAboutTestsThatDoNotTestAnything="true"
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
4+
beStrictAboutChangesToGlobalState="true"
55
beStrictAboutOutputDuringTests="true"
6-
bootstrap="vendor/autoload.php"
6+
beStrictAboutTodoAnnotatedTests="true"
7+
executionOrder="random"
78
colors="true"
8-
convertErrorsToExceptions="true"
9-
convertNoticesToExceptions="true"
10-
convertWarningsToExceptions="true"
11-
failOnRisky="true"
12-
failOnWarning="true"
13-
processIsolation="false"
14-
stopOnError="false"
15-
stopOnFailure="false"
16-
verbose="true"
9+
bootstrap="tests/bootstrap.php"
1710
>
1811
<testsuites>
1912
<testsuite name="Test Suite">
2013
<directory>tests</directory>
2114
</testsuite>
2215
</testsuites>
23-
<filter>
24-
<whitelist processUncoveredFilesFromWhitelist="true">
25-
<directory suffix=".php">./src</directory>
26-
<exclude>
27-
<file>src/iterable-map-php53.php</file>
28-
<file>src/iterable-map-php55.php</file>
29-
</exclude>
30-
</whitelist>
31-
</filter>
16+
<coverage>
17+
<include>
18+
<directory suffix=".php">src</directory>
19+
</include>
20+
</coverage>
3221
</phpunit>

src/iterable-functions.php

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,41 @@
22

33
use BenTools\IterableFunctions\IterableObject;
44

5-
if (version_compare(PHP_VERSION, '5.5') >= 0) {
6-
include_once __DIR__ . '/iterable-map-php55.php';
7-
} else {
8-
include_once __DIR__ . '/iterable-map-php53.php';
5+
if (!function_exists('iterable_map')) {
6+
7+
/**
8+
* Maps a callable to an iterable.
9+
*
10+
* @param iterable|array|\Traversable $iterable
11+
* @param callable $map
12+
* @return array|ArrayIterator
13+
* @throws InvalidArgumentException
14+
*/
15+
function iterable_map($iterable, $map)
16+
{
17+
if (!is_iterable($iterable)) {
18+
throw new \InvalidArgumentException(
19+
sprintf('Expected array or Traversable, got %s', is_object($iterable) ? get_class($iterable) : gettype($iterable))
20+
);
21+
}
22+
23+
// Cannot rely on callable type-hint on PHP 5.3
24+
if (null !== $map && !is_callable($map) && !$map instanceof Closure) {
25+
throw new InvalidArgumentException(
26+
sprintf('Expected callable, got %s', is_object($map) ? get_class($map) : gettype($map))
27+
);
28+
}
29+
30+
if ($iterable instanceof Traversable) {
31+
return new ArrayIterator(array_map($map, iterator_to_array($iterable)));
32+
}
33+
34+
return array_map($map, $iterable);
35+
}
36+
937
}
1038

39+
1140
if (!function_exists('is_iterable')) {
1241

1342
/**

src/iterable-map-php53.php

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/iterable-map-php55.php

Lines changed: 0 additions & 34 deletions
This file was deleted.

tests/IterableFilterTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@ public function testTraversableFilter()
2323
$this->assertEquals(array(1 => 'bar'), iterable_to_array(iterable_filter($iterable, $filter)));
2424
}
2525

26-
/**
27-
* @expectedException InvalidArgumentException
28-
*/
2926
public function testInvalidIterable()
3027
{
28+
$this->expectException(InvalidArgumentException::class);
29+
3130
$filter = function () {
3231
return true;
3332
};

tests/IterableMapTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ public function testTraversableMap()
1919
$this->assertEquals(array('FOO', 'BAR'), iterable_to_array(iterable_map($iterable, $map)));
2020
}
2121

22-
/**
23-
* @expectedException InvalidArgumentException
24-
*/
2522
public function testInvalidIterable()
2623
{
24+
$this->expectException(InvalidArgumentException::class);
25+
2726
$filter = function () {
2827
return true;
2928
};

0 commit comments

Comments
 (0)