Skip to content

Drop EOLed php versions #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 18, 2021
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
73 changes: 73 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: "Continuous Integration"

on:
pull_request:
push:
schedule:
- cron: "0 0 1 * *"

jobs:
phpunit:
name: "PHPUnit"
runs-on: "ubuntu-20.04"

strategy:
matrix:
php-version:
- "7.3"
- "7.4"
- "8.0"
dependencies:
- "highest"
include:
- dependencies: "lowest"
php-version: "7.3"

steps:
- name: "Checkout"
uses: "actions/checkout@v2"
with:
fetch-depth: 2

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php-version }}"
coverage: "pcov"
ini-values: "zend.assertions=1"

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"
with:
dependency-versions: "${{ matrix.dependencies }}"

- name: "Run PHPUnit"
run: "vendor/bin/phpunit --coverage-clover=coverage.xml"

- name: "Upload coverage file"
uses: "actions/upload-artifact@v2"
with:
name: "phpunit-${{ matrix.deps }}-${{ matrix.php-version }}.coverage"
path: "coverage.xml"

upload_coverage:
name: "Upload coverage to Codecov"
runs-on: "ubuntu-20.04"
needs:
- "phpunit"

steps:
- name: "Checkout"
uses: "actions/checkout@v2"
with:
fetch-depth: 2

- name: "Download coverage files"
uses: "actions/download-artifact@v2"
with:
path: "reports"

- name: "Upload to Codecov"
uses: "codecov/codecov-action@v1"
with:
directory: reports
32 changes: 0 additions & 32 deletions .scrutinizer.yml

This file was deleted.

37 changes: 0 additions & 37 deletions .travis.yml

This file was deleted.

11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
[![Latest Stable Version](https://poser.pugx.org/bentools/iterable-functions/v/stable)](https://packagist.org/packages/bentools/iterable-functions)
[![License](https://poser.pugx.org/bentools/iterable-functions/license)](https://packagist.org/packages/bentools/iterable-functions)
[![Build Status](https://img.shields.io/travis/bpolaszek/php-iterable-functions/master.svg?style=flat-square)](https://travis-ci.org/bpolaszek/php-iterable-functions)
[![Coverage Status](https://coveralls.io/repos/github/bpolaszek/php-iterable-functions/badge.svg?branch=master)](https://coveralls.io/github/bpolaszek/php-iterable-functions?branch=master)
[![Quality Score](https://img.shields.io/scrutinizer/g/bpolaszek/php-iterable-functions.svg?style=flat-square)](https://scrutinizer-ci.com/g/bpolaszek/php-iterable-functions)
[![GitHub Actions][GA master image]][GA master]
[![Code Coverage][Coverage image]][CodeCov Master]
[![Total Downloads](https://poser.pugx.org/bentools/iterable-functions/downloads)](https://packagist.org/packages/bentools/iterable-functions)

Iterable functions
Expand Down Expand Up @@ -191,3 +189,8 @@ Unit tests
```
./vendor/bin/phpunit
```

[CodeCov Master]: https://codecov.io/gh/bpolaszek/php-iterable-functions/branch/2.0.x-dev
[Coverage image]: https://codecov.io/gh/bpolaszek/php-iterable-functions/branch/2.0.x-dev/graph/badge.svg
[GA master]: https://github.com/bpolaszek/php-iterable-functions/actions?query=workflow%3A%22Continuous+Integration%22+branch%3A2.0.x-dev
[GA master image]: https://github.com/bpolaszek/php-iterable-functions/workflows/Continuous%20Integration/badge.svg
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
]
},
"require": {
"php": ">=5.3"
"php": "^7.3 || ^8.0"
},
"require-dev": {
"phpunit/phpunit": "^4.0|^5.0|^6.0|^7.0",
"phpunit/phpunit": "^9",
"squizlabs/php_codesniffer": "^2.0|^3.4",
"symfony/var-dumper": "@stable"
"symfony/var-dumper": "^5.2"
}
}
40 changes: 12 additions & 28 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,37 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
beStrictAboutTestsThatDoNotTestAnything="true"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
beStrictAboutChangesToGlobalState="true"
beStrictAboutOutputDuringTests="true"
bootstrap="vendor/autoload.php"
beStrictAboutTodoAnnotatedTests="true"
executionOrder="random"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
failOnRisky="true"
failOnWarning="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
verbose="true"
bootstrap="tests/bootstrap.php"
>
<testsuites>
<testsuite name="Test Suite">
<file>tests/TestIsIterable.php</file>
<file>tests/TestIterableToArray.php</file>
<file>tests/TestIterableToTraversable.php</file>
<file>tests/TestIterableFilter.php</file>
<file>tests/TestIterableMap.php</file>
<file>tests/TestIterableObject.php</file>
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
<exclude>
<file>src/iterable-map-php53.php</file>
<file>src/iterable-map-php55.php</file>
</exclude>
</whitelist>
</filter>
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
</phpunit>
37 changes: 33 additions & 4 deletions src/iterable-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,41 @@

use BenTools\IterableFunctions\IterableObject;

if (version_compare(PHP_VERSION, '5.5') >= 0) {
include_once __DIR__ . '/iterable-map-php55.php';
} else {
include_once __DIR__ . '/iterable-map-php53.php';
if (!function_exists('iterable_map')) {

/**
* Maps a callable to an iterable.
*
* @param iterable|array|\Traversable $iterable
* @param callable $map
* @return array|ArrayIterator
* @throws InvalidArgumentException
*/
function iterable_map($iterable, $map)
{
if (!is_iterable($iterable)) {
throw new \InvalidArgumentException(
sprintf('Expected array or Traversable, got %s', is_object($iterable) ? get_class($iterable) : gettype($iterable))
);
}

// Cannot rely on callable type-hint on PHP 5.3
if (null !== $map && !is_callable($map) && !$map instanceof Closure) {
throw new InvalidArgumentException(
sprintf('Expected callable, got %s', is_object($map) ? get_class($map) : gettype($map))
);
}

if ($iterable instanceof Traversable) {
return new ArrayIterator(array_map($map, iterator_to_array($iterable)));
}

return array_map($map, $iterable);
}

}


if (!function_exists('is_iterable')) {

/**
Expand Down
35 changes: 0 additions & 35 deletions src/iterable-map-php53.php

This file was deleted.

34 changes: 0 additions & 34 deletions src/iterable-map-php55.php

This file was deleted.

2 changes: 1 addition & 1 deletion tests/TestIsIterable.php → tests/IsIterableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use PHPUnit\Framework\TestCase;

class TestIsIterable extends TestCase
final class IsIterableTest extends TestCase
{

public function testFunctionExists()
Expand Down
11 changes: 6 additions & 5 deletions tests/TestIterableFilter.php → tests/IterableFilterTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

class TestIterableFilter extends \PHPUnit\Framework\TestCase
use PHPUnit\Framework\TestCase;

final class IterableFilterTest extends TestCase
{

public function testArrayFilter()
Expand All @@ -21,14 +23,13 @@ public function testTraversableFilter()
$this->assertEquals(array(1 => 'bar'), iterable_to_array(iterable_filter($iterable, $filter)));
}

/**
* @expectedException InvalidArgumentException
*/
public function testInvalidIterable()
{
$this->expectException(InvalidArgumentException::class);

$filter = function () {
return true;
};
iterable_filter('foo', $filter);
}
}
}
Loading