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

How does the .inArray() pattern expander work ? #296

Closed
wijourdil opened this issue Jan 3, 2022 · 3 comments
Closed

How does the .inArray() pattern expander work ? #296

wijourdil opened this issue Jan 3, 2022 · 3 comments

Comments

@wijourdil
Copy link

Hi,

I have an issue, I don't know how to use the .inArray() pattern expander.
Whatever I try, I get this error message :

MyTest::test_something
Failed asserting that Value "my-string" does not match pattern "@string@.inArray([])" at path: "[0][id]".

/.../my-project/vendor/coduo/php-matcher/src/PHPUnit/PHPMatcherConstraint.php:65
/.../my-project/vendor/coduo/php-matcher/src/PHPUnit/PHPMatcherAssertions.php:21
/.../my-project/tests/MyTest.php:35

I'm using the assertMatchedPattern() trait method, and the pattern I use is this :
(I try with an empty array, but I also tried with hardcoded array or "json-encoded" variables)

[
    'id' => "@string@.inArray([])",
    'name' => "@string@.isNotEmpty()",
]

According to what I saw in the InArray expander class, I should have one of these error messages :

InArray expander require "array", got "%s".

or

%s doesn't have \"%s\" element.

Am I using it wrong ? Is it possible to add an example in the documentation ? Thanks a lot ! 🙏

@wijourdil
Copy link
Author

I think I have understood my mistake.

Is this pattern expander supposed to check if a string is contained in a given array, or to check if an array contains a given string ?

@norberttech
Copy link
Member

Hey, yeah now when I look at it, inArray expander is not as self descriptive as I thought originally, I will adjust the documentation with proper example but in the meantime please find it here: @array@.inArray() example

@norberttech
Copy link
Member

I'm closing this one, in case of any more questions, feel free to open new issues. I also updated readme with an example of inArray

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

No branches or pull requests

2 participants