for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace EmberDb;
use PHPUnit\Framework\TestCase;
class DocumentTest extends TestCase
{
public function providerHas()
$defaultPreconditions = [
'document' => [
'foo' => [
'bar' => 'baz'
]
];
$defaultExpectations = [];
$testCases = [
'1-element subpath of existing 2-element-path' => [
'preconditions' => [
'path' => 'foo'
],
'expectations' => [
'has' => true
'Existing, two-element path' => [
'path' => 'foo.bar'
'Non-existing, two-element path' => [
'path' => 'foo.baz'
'has' => false
'Non-existing 3-element-path in a document only containing 2-element-paths' => [
'path' => 'foo.bar.baz'
'Non-existing 3-element-path in a document only containing 2-element-paths with an empty array' => [
'bar' => []
// Merge test data with default data
foreach ($testCases as &$testCase) {
$testCase['preconditions'] = array_merge($defaultPreconditions, $testCase['preconditions']);
$testCase['expectations'] = array_merge($defaultExpectations, $testCase['expectations']);
}
return $testCases;
/**
* @dataProvider providerHas
*/
public function testHas($preconditions, $expectations)
$document = new Document($preconditions['document']);
$has = $document->has($preconditions['path']);
$this->assertEquals($expectations['has'], $has);