• Stars
    star
    124
  • Rank 287,328 (Top 6 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 5 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Provides assertArraySubset for use in PHPunit

PHPUnit AssertArraySubset Extension

In PHPUnit 8 the function assertArraySubset was deprecated. This function was often misunderstood and thus removed, but it still holds true as a very useful tool, hence it was extracted here.

Disclaimer: The initial version contained here is copied over from phpunit and is heavily based on the original work by Márcio Almada.

Installation

Simply use it by importing it with Composer

composer require --dev dms/phpunit-arraysubset-asserts

💡 The package can be safely required on PHP 5.4 to current in combination with PHPUnit 4.8.36/5.7.21 to current.

When the PHPUnit assertArraySubset() method is natively available and not deprecated (PHPUnit 4.x - 7.x), the PHPUnit native functionality will be used. For PHPUnit 8 and higher, the extension will kick in and polyfill the functionality which was removed from PHPUnit.

Usage

You have two options to use this in your classes: either directly as a static call or as a trait if you wish to keep existing references working.

Trait use example

<?php

namespace Your\Package\Tests;

use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
use PHPUnit\Framework\TestCase;

final class ExampleTest extends TestCase
{
    use ArraySubsetAsserts;

    public function testWithTrait(): void
    {
        $expectedSubset = ['bar' => 0];

        $content = ['bar' => '0'];

        self::assertArraySubset($expectedSubset, $content, true);

        $content = ['foo' => '1'];

        $this->assertArraySubset($expectedSubset, $content, true);
    }
}

Static class method example

<?php

namespace Your\Package\Tests;

use DMS\PHPUnitExtensions\ArraySubset\Assert;
use PHPUnit\Framework\TestCase;

final class ExampleTest extends TestCase
{
    public function testWithDirectCall(): void
    {
        $expectedSubset = ['bar' => 0];

        $content = ['bar' => '0'];

        Assert::assertArraySubset($expectedSubset, $content, true);
    }
}

More Repositories

1

dms-filter

Library that offers Input Filtering based on Annotations for use with Objects. Check out 2.dev for 2.0 pre-release.
PHP
91
star
2

meetup-api-client

Guzzle powered Meetup.com API Client
PHP
77
star
3

dms-filter-bundle

Provides a FilterService for Symfony to allow users to implement input filtering in entities using Annotations
PHP
76
star
4

facebook-testuser-manager

A manager for Facebook API test users
JavaScript
37
star
5

DMS

Component library
PHP
36
star
6

pronto

Pronto! The blazing fast CfP submission tool.
JavaScript
35
star
7

NerdTrack

Projeto finalizado. Conheça nosso novo projeto, o Podtrack!
Ruby
32
star
8

dms-twig-extension-bundle

DMS Twig Extension Bundle, leverages Fabien Potencier's extra twig extensions for your website.
PHP
19
star
9

ManoWars

Sample code for teaching about Unit Tests and TDD
PHP
11
star
10

sloth

A plugin-enabled HTTP environment for Slack integrations
CSS
9
star
11

fixthatcode.com

Website to display coding horrors and how to fix them
JavaScript
9
star
12

chainlink

Drop-in implementation of the Chain of Responsibility pattern
PHP
5
star
13

aggregatein

Sample app to group Joind.in talks. Built to test out Silex and Azure.
JavaScript
5
star
14

textlint-action

Github Action that uses textlinter to proofread documentation
JavaScript
4
star
15

Tweester

A Wordpress plugin to display lists of users who have tweeted a define phrase, useful to display a list of supporters on your site.
PHP
3
star
16

superfeedr-api-client

API Client for the Superfeedr Service, based on Guzzle.
PHP
3
star
17

PHPRegExpTester

Titanium app that allows you to test regular expression in PHP on the desktop
JavaScript
3
star
18

PHPSP-Promos

Site irmão do Blog do PHPSP com sistemas relacionados a diferentes ações do grupo, por exemplo: Sou PHPSP e Contribuo.
PHP
3
star
19

js-panic-board

Backbone.js implementation of a Panic Board
JavaScript
3
star
20

ugDirectory

Application meant to manage a list of User Groups and their information
PHP
2
star
21

com.dms.streamdeck.github

A Stream Deck Plugin for interfacing with Github
CSS
2
star
22

php-shirts

CSS
2
star
23

Sample-Azure-App

Sample Twitter Application used for my Windows Azure App.
PHP
1
star
24

dms-meetup-api-bundle

DMS Meetup Api Bundle. Subdirectory split, pelase go to rdohms/DMS
PHP
1
star
25

php-usergroups

A quick guid on starting your User Group
1
star
26

simple-raml-path-validator

Validates that Path and Method are available in a RAML spec file.
PHP
1
star
27

talk-app-metrics

Supporting material for the Application Metrics with Prometheus talk.
Makefile
1
star
28

jetbrains-config

IDE settings
PHP
1
star
29

php-ug-directory

A tool to track user groups. *ABANDONED* this project never made it out of alpha planning phase.
PHP
1
star
30

chainlink-bundle

Symfony Bundle that wraps and provides Chain of Resposibility implementation
PHP
1
star
31

rdohms.github.com

1
star