1. Go to this page and download the library: Download korchasa/matcho library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
korchasa / matcho example snippets
use korchasa\Vhs\AssertMatchedTrait;
use PHPUnit\Framework\TestCase;
class IntegrationTest extends TestCase
{
use AssertMatchedTrait;
public function testResponseJson()
{
$this->assertJsonMatched(
'{
"baz": {
"value": 1
},
"items": [
{
"a": "b***",
"c": 2
},
"***"
]
}',
$this->server()->call()->responseJson()
);
/**
Given value of `items.0.c` not match pattern `2`
--- Pattern
+++ Actual
@@ @@
-2
+22
*/
}
public function testArray()
{
$this->assertArrayMatched(
[
"foo" => "somestring***", // check string pattern
"bar" => "***", // check only presence
"baz" => 42 // check presence and value
],
$complexArray
);
/**
Given value has no key `baz`
--- Pattern
+++ Actual
@@ @@
array (
- 'foo' => 'something***',
- 'baz' => "***",
+ 'foo' => 'something2',
*/
}
public function testString()
{
$this->assertStringMatched('cu***mber', $somestring);
/**
Given value not match pattern
--- Pattern
+++ Actual
@@ @@
-cu***mber
+kucumber
*/
}
}