phpspec / prophecy

Highly opinionated mocking framework for PHP 5.3+
MIT License
8.53k stars 241 forks source link

Add the ability to customize the __toString representation of a CallbackToken #573

Closed ian-zunderdorp closed 1 year ago

ian-zunderdorp commented 1 year ago

Whenever we run tests using CallbackToken's and the CallbackToken fails to match, we get unhelpful assertion failures. When the specific test case does not use a lot of CallbackToken's, it is pretty easy to track which assertion has failed. This is aimed at the scenario where there are multiple identical function signatures with different CallbackToken's, so the following example becomes more readable:

    [exec]  Test  tests/unit/Example/ExampleTest.php:testItDoesSomething
     [exec] Expected exactly 1 calls that match:
     [exec]   Double\ExampleInterface\P2->doSomething(callback())
     [exec] but none were made.
     [exec] Recorded `doSomething(...)` calls:

should become

    [exec]  Test  tests/unit/Example/ExampleTest.php:testItDoesSomething
     [exec] Expected exactly 1 calls that match:
     [exec]   Double\ExampleInterface\P2->doSomething(Clear description)
     [exec] but none were made.
     [exec] Recorded `doSomething(...)` calls:

If you would like a separate issue for discussion, please let me know so I can create one.