Skip to content
Open
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
11 changes: 9 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ php:
# see http://php.net/supported-versions.php
- '7.3' # Until 6 Dec 2021
- '7.4' # Until 28 Nov 2022
- '8.0' # Until 26 Nov 2023

env:
global:
- COMPOSER_CACHE_DIR=/home/travis/.composer
- XDEBUG_MODE=coverage
matrix:
# see https://phpunit.de/supported-versions.html
- PHPUNIT_VERSION=8.0.*
- PHPUNIT_VERSION=8.5.*
- PHPUNIT_VERSION=9.2.*
- PHPUNIT_VERSION=9.5.*

matrix:
Expand All @@ -27,6 +26,14 @@ matrix:
env: PHPUNIT_VERSION=7.5.*
- php: '7.2'
env: PHPUNIT_VERSION=8.5.*
- php: '7.3'
env: PHPUNIT_VERSION=8.0.*
- php: '7.4'
env: PHPUNIT_VERSION=8.5.*
- php: '8.0'
env: PHPUNIT_VERSION=8.5.*
- php: '8.0'
env: PHPUNIT_VERSION=8.4.*

# We add some tests here for that we want to achieve or keep compatibility.
# Some are made due to unstable SemVer of testing packages (guess which).
Expand Down
11 changes: 10 additions & 1 deletion lib/Compat/v8/Constraint/ArraySubset.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ class ArraySubset extends Constraint

public function __construct(iterable $subset, bool $strict = false)
{
parent::__construct();
if (in_array('__construct', get_class_methods(Constraint::class))) {
// Seen in 8.4.* but vanished in 8.5.0
parent::__construct();
}

$this->strict = $strict;
$this->subset = $subset;
Expand Down Expand Up @@ -96,6 +99,12 @@ public function evaluate($other, $description = '', $returnResult = false)
*/
public function toString(): string
{
if (method_exists($this, 'exporter')) {
// For PHPUnit 8.5.*
return 'has the subset ' . $this->exporter()->export($this->subset);
}

// For PHPUnit 8.4.*
return 'has the subset ' . $this->exporter->export($this->subset);
}

Expand Down
50 changes: 50 additions & 0 deletions opt/doc/TestCase/Constraint/ArraySubsetTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

/**
* ArraySubsetTest.php
*
* LICENSE: This source file is created by the company around M. Pretzlaw
* located in Germany also known as rmp-up. All its contents are proprietary
* and under german copyright law. Consider this file as closed source and/or
* without the permission to reuse or modify its contents.
* This license is available through the world-wide-web at the following URI:
* https://rmp-up.de/license-generic.txt . If you did not receive a copy
* of the license and are unable to obtain it through the web, please send a
* note to mail@rmp-up.de so we can mail you a copy.
*
* @package phpunit-compat
* @copyright 2021 Pretzlaw
* @license https://rmp-up.de/license-generic.txt
*/

declare(strict_types=1);


namespace RmpUp\PHPUnitCompat\TestCase\Constraint;

use PHPUnit\Framework\AssertionFailedError;
use RmpUp\PHPUnitCompat\TestCase;

/**
* ArraySubsetTest
*
* @copyright 2021 Pretzlaw (https://rmp-up.de)
*/
class ArraySubsetTest extends TestCase
{
public function testCanDetermineIfArrayHasSubset()
{
self::assertArraySubset(
['a' => 1],
['c' => 3, 'a' => 1, 'b' => 2]
);
}

public function testFailsWhenArrayDoesNotHaveSubset()
{
$this->expectException(AssertionFailedError::class);

self::assertArraySubset(['a' => 1], []);
}
}