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

Custom object formatters #766

Merged

Conversation

MartinMystikJonas
Copy link
Contributor

Possibility to set custom objet formatters for specific classes or interfaces. If formatter is set it's used instead of default formatter outputing public properties.

        \Mockery::getConfiguration()->setObjectFormatter(
            'ClassWithCustomFormatter',
            function($object) {
                return array(
                    "properties" => array(
                        "stringProperty" => $object->stringProperty
                    ),
                    "getters" => array(
                        "gettedProperty" => $object->getArrayProperty()
                    )
                );
            }
        );

Copy link
Collaborator

@davedevelopment davedevelopment left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

library/Mockery/Configuration.php Outdated Show resolved Hide resolved
@mockery mockery deleted a comment from coveralls Jul 17, 2017
@mockery mockery deleted a comment from coveralls Jul 17, 2017
@mockery mockery deleted a comment from coveralls Jul 17, 2017
@mockery mockery deleted a comment from coveralls Jul 17, 2017
@mockery mockery deleted a comment from coveralls Jul 17, 2017
@mockery mockery deleted a comment from coveralls Jul 17, 2017
@mockery mockery deleted a comment from coveralls Jul 17, 2017
@mockery mockery deleted a comment from coveralls Jul 17, 2017
@mockery mockery deleted a comment from coveralls Jul 17, 2017
library/Mockery/Configuration.php Outdated Show resolved Hide resolved
@robertbasic
Copy link
Collaborator

@MartinMystikJonas hey, thanks for the PR! Can you fix the conflicts and update the PR based on @davedevelopment's and mine requests? Thank you!

@MartinMystikJonas
Copy link
Contributor Author

Finally had time to finish this. Sorry about three years gap but after our daughter was born I had only little time for open source :-)

@MartinMystikJonas
Copy link
Contributor Author

Let me know if you want to merge it I will squash commits

@MichaelKubovic
Copy link

Friendly ping, is there anything we can do to merge this?


$array = array(
'class' => $class,
'identity' => '#' . md5(spl_object_hash($object))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is often useful to be able to compare object identities not only their class + some optional custom info from formatter. Should I remove it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean why the md5. Just use spl_object_id.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besause spl_object_id is hard to compare visually becaue usually two instances have most characters of spl_object_hash identical. Using of md5 of spl_object_hash is quite common practice i saw in many libraries.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example I just used it on two objects and I got:
000000002f73941b000000004f808351 and 000000002ffa4e380000000026e9a821
If you use md5 it becomes different at the first sight:
69850868ab17d5cd4d7effccd55ba63c and 43147e68957af1fcbd045979c3c3fda3

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

Successfully merging this pull request may close these issues.

None yet

5 participants