Laravel testing with PHPUnit and Mockery - Setting up dependencies on Controller test

前端 未结 2 918
刺人心
刺人心 2021-02-16 00:24

After finally getting my stupid simple test to pass, I have a feeling that I\'m not doing it correctly.

I have a SessionsController, that is responsible for displaying

2条回答
  •  青春惊慌失措
    2021-02-16 00:43

    Yes, you can use a "helper". Move the creation of the mocked dependencies into another function, then call that when you need them. Check out slide 52 in this presentation: https://speakerdeck.com/jcarouth/guiding-object-oriented-design-with-tests-1 (well check out the whole thing, but the example is on slide 52)

    Edit: The setUp way is even better, I was thinking for something you didn't need in ALL the tests, but I think for what you described doing it in the setUp is way better.

提交回复
热议问题