arraypath icon indicating copy to clipboard operation
arraypath copied to clipboard

Static approach makes this class unmockable

Open func0der opened this issue 7 years ago • 3 comments

Hey there,

I found that you class seems to be unmockable for PHPUnit, because all its calls are static and the state is saved staticalled, too.

I could imagine, why you would have chosen this approach, but it hinders us from mocking it away.

Do you see a way of combining a 'correct' stateful approach with your easy accessible static one? Maybe with the singleton pattern for example? With this approach there would be almost to none changes to your existing public api, because you could hide the instanciating process in your class. Or maybe something else, like a new major with a compatibility break?

func0der avatar Jul 03 '17 08:07 func0der

Hi, thanks for reaching out. Could you provide some code example of what you are trying to do?

On 3 July 2017 at 10:01, Lars [email protected] wrote:

Hey there,

I found that you class seems to be unmockable for PHPUnit, because all its calls are static and the state is saved staticalled, too.

I could imagine, why you would have chosen this approach, but it hinders us from mocking it away.

Do you see a way of combining a 'correct' stateful approach with your easy accessible static one? Maybe with the singleton pattern for example? With this approach there would be almost to none changes to your existing public api, because you could hide the instanciating process in your class. Or maybe something else, like a new major with a compatibility break?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/mathiasgrimm/arraypath/issues/9, or mute the thread https://github.com/notifications/unsubscribe-auth/AAbeFSqyDFPnlCdjvd2hLUTPS-2mfX2Lks5sKJ--gaJpZM4OL87r .

mathiasgrimm avatar Jul 03 '17 08:07 mathiasgrimm

Of what I am trying to test or how I would imagine your class in the non-static approach?

func0der avatar Jul 03 '17 09:07 func0der

Of what are you not being able to test properly

On 3 July 2017 at 11:54, Lars [email protected] wrote:

Of what I am trying to test or how I would imagine your class in the non-static approach?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/mathiasgrimm/arraypath/issues/9#issuecomment-312602461, or mute the thread https://github.com/notifications/unsubscribe-auth/AAbeFUF1gQQ6SRdsnAccVRcpHliaDuo4ks5sKLprgaJpZM4OL87r .

mathiasgrimm avatar Jul 03 '17 12:07 mathiasgrimm