Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[Bug]: Pest + PHP Matcher = simplexml_load_string(): Entity: line 1: parser error : Start tag expected, '<' not found #1186

Open
mdacosta opened this issue Jul 3, 2024 · 0 comments
Labels

Comments

@mdacosta
Copy link

mdacosta commented Jul 3, 2024

What Happened

When I want to do some JSON assertions using PHP Matcher, the tests passes, but there is a warning : simplexml_load_string(): Entity: line 1: parser error : Start tag expected, '<' not found

Capture d’écran 2024-07-03 à 20 14 45

The exact same test written in PHPUnit style runs without any warning :
Capture d’écran 2024-07-03 à 20 16 11

How to Reproduce

Sample Repository

https://github.com/mdacosta/pest-issue

Pest Version

2.34.8

PHP Version

8.3.7, 8.3.8

Operation System

macOS, Linux

Notes

Pest test :

<?php

declare (strict_types = 1);

use Coduo\PHPMatcher\PHPUnit\PHPMatcherConstraint;

test('example', function () {
    $data = [
        /* @lang JSON */
        '{
            "url": "/profile/01BX5ZZKBKACTAV9WEVGEMMVS0"
        }',
        /* @lang JSON */
        '{
            "url": "/profile/@ulid@"
        }',
    ];

    $this->assertThat($data[0], new PHPMatcherConstraint($data[1]));
});

PHPUnit test :

<?php

declare(strict_types=1);

namespace App\Tests;

use Coduo\PHPMatcher\PHPUnit\PHPMatcherConstraint;
use Coduo\PHPMatcher\PHPUnit\PHPMatcherTestCase;

class MatcherTest extends PHPMatcherTestCase
{
    public function test_matcher_with_json(): void
    {
        $data = [
            /* @lang JSON */
            '{
              "url": "/profile/01BX5ZZKBKACTAV9WEVGEMMVS0"
            }',
                /* @lang JSON */
                '{
                "url": "/profile/@ulid@"
            }',
        ];

        $this->assertThat($data[0], new PHPMatcherConstraint($data[1]));
    }
}

The issue comes from the fact that I want to do some assertions like this "url": "/profile/@ulid@".
I the string contains only a ULID, then doing this "url": "@ulid@" works fine.

The reason why I created this is issue here and not on PHPMatcher project is because it works with PHPUnit, which makes me think that there is something wrong with Pest.

This other reason why I think this is a Pest issue is that I already used Pest + PHP Matcher in the past, and it was working well. But it was Pest 1. Maybe something changed in Pest 2.

@mdacosta mdacosta added the bug label Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant