Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Simplify failure description returned by PHPMatcherConstraint #226

Conversation

niklasnatter
Copy link
Contributor

Change Log

Added

Fixed

Changed

  • Omit pattern and empty backtrace in failure description returned by PHPMatcherConstraint

Removed

Deprecated

Security


Description

This PR simplifies the failure description returned by the PHPMatcherConstraint class. The intention of the change is to make the actual error easier to find. We are happily using the library for testing an API with big responses. Prepending the error with the given value and the pattern makes it hard to sport the actual error in such a usecase.

The PR changes the output when running the following example test cases like this:

use Coduo\PHPMatcher\PHPUnit\PHPMatcherConstraint;
use PHPUnit\Framework\TestCase;

class PatternTest extends TestCase
{
    public function testPattern(): void
    {
        $pattern = <<<EOF
            {
                "name": "@string@",
                "description": "test-1"
            }
EOF;

        $value = <<<EOF
            {
                "name": "test-2",
                "description": "test-2"
            }
EOF;

        TestCase::assertThat(
            $value,
            new PHPMatcherConstraint($pattern)
        );
    }
}

Old output:

1) Namespace\PatternTest::testPattern
Failed asserting that '            {\n
                "name": "test-2",\n
                "description": "test-2"\n
            }' matches given pattern.
Pattern: '            {\n
                "name": "@string@",\n
                "description": "test-1"\n
            }'
Error: Value "test-2" does not match pattern "test-1" at path: "[description]"
Backtrace: 
Empty.
--- Expected
+++ Actual
@@ @@
 {
-    "description": "test-1",
-    "name": "@string@"
+    "description": "test-2",
+    "name": "test-2"
 }

New output:

1) Namespace\PatternTest::testPattern
Failed asserting that Value "test-2" does not match pattern "test-1" at path: "[description]".
--- Expected
+++ Actual
@@ @@
 {
-    "description": "test-1",
-    "name": "@string@"
+    "description": "test-2",
+    "name": "test-2"
 }

@niklasnatter niklasnatter force-pushed the enhancement/constraint-failure-description branch from 930f96d to 7dfc942 Compare March 1, 2021 11:08
@niklasnatter niklasnatter force-pushed the enhancement/constraint-failure-description branch from 7dfc942 to 144a2b9 Compare March 1, 2021 11:41
@niklasnatter niklasnatter marked this pull request as ready for review March 1, 2021 12:10
@norberttech norberttech merged commit 4514ac0 into coduo:6.x Mar 1, 2021
@norberttech
Copy link
Member

awesome, thanks @nnatter 🙌

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants