2017 © Pedro Peláez
 

library phpunit-bliss

Collection of assertions for PhpUnit

image

boukeversteegh/phpunit-bliss

Collection of assertions for PhpUnit

  • Wednesday, November 30, 2016
  • by boukeversteegh
  • Repository
  • 1 Watchers
  • 0 Stars
  • 538 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 3 % Grown

The README.md

PHPUnit Bliss

Installation

composer require boukeversteegh/phpunit-bliss dev-master

Usage

Add use \PhpUnitBliss\Assertions; to your test class, (*1)

assertArrayMatches

See tests/AssertionsTest.php for many examples., (*2)

Add a useful assertion to your TestCase: assertArrayMatches, which allows you to test that a given array matches a certain subset. You can match by value, or by other assertions., (*3)


class AssertionsTest extends \PHPUnit_Framework_TestCase { use \PhpUnitBliss\Assertions; public function testSimpleExample() { $array = [ 'id' => 1, 'name' => 'John', 'preferences' => [ 'vegetables' => true, 'beer' => false, ], ]; $pattern = [ 'name' => 'John', 'preferences' => [ 'vegetables' => true, ], ]; $this->assertArrayMatches($array, $pattern); $notPattern = [ 'name' => 'John', 'preferences' => [ 'beer' => true, ], ]; $this->assertArrayNotMatches($array, $notPattern); } /** * You can use constraints to match values inside arrays */ public function testComplexExample() { $array = [ 'id' => 1, 'age' => 25, 'friends' => [ [ 'name' => 'Sally', ] ], 'other' => 'some field that is ignored', 'tree' => [ 'subtree' => ['foo', 'bar', 'baz'] ], ]; $pattern = [ 'id' => self::anything(), 'age' => self::greaterThan(18), 'friends' => self::contains(['name' => 'Sally']), 'tree' => [ 'subtree' => self::logicalAnd( self::countOf(3), self::arrayMatches([1 => 'bar']) ) ], ]; $this->assertArrayMatches($array, $pattern); } }

The Versions

30/11 2016

dev-phpunit5

dev-phpunit5

Collection of assertions for PhpUnit

  Sources   Download

MIT

The Requires

 

25/11 2015

dev-master

9999999-dev

Collection of assertions for PhpUnit

  Sources   Download

MIT

The Requires