Skip to content

Commit

Permalink
Build: Drop older PHP versions, use github actions (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpolaszek authored Jan 2, 2022
1 parent ba7b880 commit 4237215
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 115 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: CI Workflow

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
code-style:
name: Code Style & Static Analysis
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
extensions: mbstring, pcntl

- name: Validate composer.json and composer.lock
run: composer validate

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

- name: Check code style
run: vendor/bin/phpcs --standard=psr2 -n src/


tests:
name: Test Suite
runs-on: ubuntu-20.04
strategy:
max-parallel: 10
matrix:
php:
- 7.4
- 8.0
- 8.1

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: mbstring, curl, zip
coverage: xdebug

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

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

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
32 changes: 0 additions & 32 deletions .scrutinizer.yml

This file was deleted.

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

This file was deleted.

5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
[![Latest Stable Version](https://poser.pugx.org/bentools/cartesian-product/v/stable)](https://packagist.org/packages/bentools/cartesian-product)
[![License](https://poser.pugx.org/bentools/cartesian-product/license)](https://packagist.org/packages/bentools/cartesian-product)
[![Build Status](https://img.shields.io/travis/bpolaszek/cartesian-product/master.svg?style=flat-square)](https://travis-ci.org/bpolaszek/cartesian-product)
[![Coverage Status](https://coveralls.io/repos/github/bpolaszek/cartesian-product/badge.svg?branch=master)](https://coveralls.io/github/bpolaszek/cartesian-product?branch=master)
[![Quality Score](https://img.shields.io/scrutinizer/g/bpolaszek/cartesian-product.svg?style=flat-square)](https://scrutinizer-ci.com/g/bpolaszek/cartesian-product)
[![CI Workflow](https://github.com/bpolaszek/cartesian-product/actions/workflows/ci-workflow.yml/badge.svg)](https://github.com/bpolaszek/cartesian-product/actions/workflows/ci-workflow.yml)
[![Coverage](https://codecov.io/gh/bpolaszek/cartesian-product/branch/master/graph/badge.svg?token=3CF5QH0CKG)](https://codecov.io/gh/bpolaszek/cartesian-product)
[![Total Downloads](https://poser.pugx.org/bentools/cartesian-product/downloads)](https://packagist.org/packages/bentools/cartesian-product)

# Cartesian Product
Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
]
},
"require": {
"php": ">=5.6"
"php": ">=7.4"
},
"require-dev": {
"phpunit/phpunit": "^5.0|^6.0",
"phpunit/phpunit": "^8.0|^9.0",
"squizlabs/php_codesniffer": "@stable",
"php-coveralls/php-coveralls": "@stable",
"symfony/var-dumper": "^3.2|^4.0"
"symfony/var-dumper": "^3.2|^4.0",
"dms/phpunit-arraysubset-asserts": "^0.3.1"
}
}
37 changes: 11 additions & 26 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
failOnRisky="true"
failOnWarning="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
verbose="true"
>
<testsuites>
<testsuite name="Test Suite">
<file>tests/TestCartesianProduct.php</file>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutOutputDuringTests="true" bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" failOnRisky="true" failOnWarning="true" processIsolation="false" stopOnError="false" stopOnFailure="false" verbose="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Test Suite">
<file>tests/TestCartesianProduct.php</file>
</testsuite>
</testsuites>
</phpunit>
6 changes: 3 additions & 3 deletions tests/CountableIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
final class CountableIterator implements IteratorAggregate, Countable
{

private $items = [];
private array $items = [];

/**
* CountableIterator constructor.
Expand All @@ -25,12 +25,12 @@ public function __construct(array $items)
}


public function getIterator()
public function getIterator(): \Traversable
{
return new ArrayIterator($this->items);
}

public function count()
public function count(): int
{
return \count($this->items);
}
Expand Down
40 changes: 20 additions & 20 deletions tests/TestCartesianProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,35 @@

namespace BenTools\CartesianProduct\Tests;

use function BenTools\CartesianProduct\cartesian_product;
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
use PHPUnit\Framework\TestCase;

use function BenTools\CartesianProduct\cartesian_product;

class TestCartesianProduct extends TestCase
{
use ArraySubsetAsserts;

/**
* @dataProvider dataProvider
*/
public function testCartesianProduct(array $cases, array $expected)
public function testCartesianProduct(array $cases, array $expected): void
{
$result = cartesian_product($cases);
$this->assertArraySubset($expected, $result->asArray());
$this->assertArraySubset($expected, $result->asArray());
}

public function testEmptySet()
public function testEmptySet(): void
{
$set = [];
$this->assertCount(0, iterator_to_array(cartesian_product($set)));
$this->assertEquals([], cartesian_product($set)->asArray());
}

/**
* @expectedException \InvalidArgumentException
*/
public function testSetWithEmptyArraySubset()
public function testSetWithEmptyArraySubset(): void
{
$this->expectException(\InvalidArgumentException::class);
$set = [
'fruits' => [
'strawberry',
Expand All @@ -46,7 +48,7 @@ public function testSetWithEmptyArraySubset()
}
}

public function testSetWithIteratorSubset()
public function testSetWithIteratorSubset(): void
{
$set = [
'fruit' => [
Expand Down Expand Up @@ -81,11 +83,9 @@ public function testSetWithIteratorSubset()

}

/**
* @expectedException \InvalidArgumentException
*/
public function testSetWithInvalidSubset()
public function testSetWithInvalidSubset(): void
{
$this->expectException(\InvalidArgumentException::class);
$set = [
'fruits' => [
'strawberry',
Expand All @@ -103,7 +103,7 @@ public function testSetWithInvalidSubset()
}
}

public function testCount()
public function testCount(): void
{
$set = [
['a', 'b', 'c', 'd', 'e', 'f'],
Expand All @@ -113,7 +113,7 @@ public function testCount()
$this->assertCount(60, cartesian_product($set)); // Assert we can call it several times
}

public function testRetrieveCurrentCombination()
public function testRetrieveCurrentCombination(): void
{
$current = null;
$set = [
Expand Down Expand Up @@ -144,14 +144,14 @@ function (array $combination) use (&$current) {
continue;
}
$this->assertNotNull($current);
$this->assertInternalType('array', $current);
$this->assertIsArray($current);
$this->assertArrayHasKey('hair', $current);
$this->assertArrayHasKey('skin', $current);
$this->assertArrayNotHasKey('eyes', $current);
$this->assertArrayNotHasKey('gender', $current);
}

public function dataProvider()
public function dataProvider(): array
{
return [
'shapesAndColors' => $this->shapesAndColors(),
Expand All @@ -161,7 +161,7 @@ public function dataProvider()
];
}

private function shapesAndColors()
private function shapesAndColors(): array
{
return [
'cases' => [
Expand Down Expand Up @@ -217,7 +217,7 @@ private function shapesAndColors()
];
}

private function moreShapesThanColors()
private function moreShapesThanColors(): array
{
return [
'cases' => [
Expand Down Expand Up @@ -260,7 +260,7 @@ private function moreShapesThanColors()
];
}

private function moreColorsThanShapes()
private function moreColorsThanShapes(): array
{
return [
'cases' => [
Expand Down Expand Up @@ -303,7 +303,7 @@ private function moreColorsThanShapes()
];
}

private function iCanHazClozures()
private function iCanHazClozures(): array
{
return [
'cases' => [
Expand Down

0 comments on commit 4237215

Please sign in to comment.