TestingTestingTesting's avatar

Want to test the calling of a specific method created by a factory

I am trying to write an integration test that does something like this.

  • Create instance of class in setUp method of test using ::factory([$params]) rather than a constructor
  • Call some methods on this class that cause various things to happen
  • Event will get fired at some point
  • Event is listened for, event listener will call a method on the same object that produced the event. Exactly which method will be called (and params) depends on some logic inside the class (which is mostly what I'm trying to test).
  • Method itself doesn't do anything (at the moment), but I want to know that is was called. Functionality will probably be implemented by a subclass at some point in the future by someone else.

So I want to assert that this method was called at some point during the test, and test which parameters were passed into it. At the moment I've managed to mock out the event itself to check that this was fired, but I can only test that the method was called manually (by putting a dd() into it). I can't seem to find a way to do this without mocking out the entire object (which would defeat the purpose of the test, because at that point I'm just testing the mock).

I know you can do "partial" mocks and maybe that's what I need, but that doesn't seem to play well with the ::factory([$params]) style of constructor.

0 likes
0 replies

Please or to participate in this conversation.