Skip to content

Latest commit

 

History

History
52 lines (45 loc) · 1.43 KB

features.md

File metadata and controls

52 lines (45 loc) · 1.43 KB

Features

Verifying Objects as JSON

If you need a nice way of printing objects, JSON works very well.

Note: ApprovalTests will sort your fields alphabetically so that you have consistency in your JSON.

Here's an example.

public function testVerifyAsJson()
{
    $obj = [
        "color" => "black",
        "category" => "hue",
        "type" => "primary",
        "code" => [
            "rgba" => [255, 255, 255, 1],
            "hex" => "#000",
        ]
    ];
    Approvals::verifyAsJson($obj);
}

snippet source | anchor

will create the approved file

{
    "category": "hue",
    "code": {
        "hex": "#000",
        "rgba": [
            255,
            255,
            255,
            1
        ]
    },
    "color": "black",
    "type": "primary"
}

snippet source | anchor