Home

Awesome

build

License

<!-- START doctoc generated TOC please keep comment here to allow auto update --> <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

Table of Contents

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

ApprovalTests.PHP

Capturing Human Intelligence - ApprovalTests is an open source assertion/verification library to aid unit testing.

It is compatible with PHPUnit

What can it be used for?

Approval Tests can be used for verifying objects that require more than a simple assert. They also come prepackaged with utilities for some common scenarios including

How to get it

It's on Packagist; search for 'approval-tests'. If you're using Composer, you can add it as follows:

composer req --dev approvals/approval-tests

Video Tutorials

You can watch a bunch of short videos on getting started and using ApprovalTests at YouTube. These cover approval tests in Java and .NET, but the same concepts apply.

Podcasts

If you prefer auditory learning, you might enjoy the following podcast (Note: Some of these talk about the .Net and Java side)

Examples

ApprovalTests eats it own dogfood, so the best examples are in the source code itself.

None the less, Here's a quick look at some Sample Code

<!-- snippet: array_example -->

<a id='snippet-array_example'></a>

class ApprovalTest extends TestCase
{
    public function testVerifyArray()
    {
        $list = ['zero', 'one', 'two', 'three', 'four', 'five'];
        Approvals::verifyList($list);
    }

<sup><a href='/tests/ApprovalTest.php#L8-L16' title='Snippet source file'>snippet source</a> | <a href='#snippet-array_example' title='Start of snippet'>anchor</a></sup>

<!-- endSnippet -->

Will Produce a File

<!-- snippet: tests/approvals/ApprovalTest.testVerifyArray.approved.txt -->

<a id='snippet-tests/approvals/ApprovalTest.testVerifyArray.approved.txt'></a>

[0] -> zero
[1] -> one
[2] -> two
[3] -> three
[4] -> four
[5] -> five

<sup><a href='/tests/approvals/ApprovalTest.testVerifyArray.approved.txt#L1-L6' title='Snippet source file'>snippet source</a> | <a href='#snippet-tests/approvals/ApprovalTest.testVerifyArray.approved.txt' title='Start of snippet'>anchor</a></sup>

<!-- endSnippet -->

Simply rename this to ApprovalTest.testVerifyArray.approved.txt and the test will now pass.

Approved File Artifacts

The *.approved.* files must be checked into source your source control. This can be an issue with git as it will change the line endings. The suggested fix is to add *.approved.* binary to your .gitattributes

More Info

LICENSE

Apache 2.0 License

Questions?

twitter: @LlewellynFalco or @notthatjoshkel or #ApprovalTests