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

The match of type @integer@ doesn't work. #469

Open
fr0N73ND3r opened this issue Oct 31, 2023 · 3 comments
Open

The match of type @integer@ doesn't work. #469

fr0N73ND3r opened this issue Oct 31, 2023 · 3 comments
Labels

Comments

@fr0N73ND3r
Copy link

final class MatchTest extends WebTestCase
{
    use PHPMatcherAssertions;

    public function testMatcher()
    {
        $this->assertMatchesPattern('@integer@', "1"); // true
    }

If you remove the class Matcher\TextMatcher from the factory (\Coduo\PHPMatcher\Factory\MatcherFactory), everything works well.

Version 6.0.11

@norberttech
Copy link
Member

Could you share your pattern and data you are trading to match against?

@fr0N73ND3r
Copy link
Author

fr0N73ND3r commented Nov 1, 2023

I added only the library to the composer.

// src/index.php
<?php

require __DIR__ . '/../vendor/autoload.php';

// https://github.com/coduo/php-matcher/blob/6.x/src/PHPMatcher.php#L55
$factory = new Coduo\PHPMatcher\Factory\MatcherFactory();
$backtrace = new Coduo\PHPMatcher\Backtrace\VoidBacktrace();

$matcher = $factory->createMatcher($backtrace);

$matcher->match('1', '@number@'); // is true
$matcher->match(1, '@number@'); // is true
$matcher->match('1', '@integer@'); // is true <- wrong
$matcher->match(1, '@integer@'); // is true

@norberttech
Copy link
Member

Ahh I see, the problem is that Matcher Factory is creating a chain of matchers, they are executed in a specific order.
It works this way because typically, you want to use matcher against JSON files, so what happens here is that TextMatcher recognizes your input as a text and it's probably using the wrong matcher.

I think the problem is an order of matchers here but it's been a while since I looked into this logic so you might need to play with it a bit.

@norberttech norberttech added the bug label Oct 7, 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

2 participants