php - Mocking an Eloquent Model -


I have really seen through hundreds of pages, and I do not know how my position differs from work I have found examples on these pages.

I am using the latest Mokery from LARVEVER 4.2, PHPUnit 4.3.1, and composer. I am running a PHPUnit test on my controller, operator, and I want to stop to save an enlightened database while joking the model. When I do not have any errors throwing while making fake, fake also is not related to my model, so even now the rows are being created.

What am I missing here? Thanks!

My error with jokes: joke \ exception \ InvalidCountException: Mockery_0_EventRsvp should save the method (save) 1 times, but 0 times should be called.

  // /app/tests/app/AppControllerTest.php class located in AppControllerTest TestCase Extended {Public Function Setup () {parent :: setup (); Session: start (); Mail :: play (); } Public Function TireDown (originally: Tyrardown (); \ Mock :: pass (); } Public function testPostApp () {$ myvar = array (); $ This- & gt; Fake = \ mockery :: Fake ('eloquent', 'EventRsvp'); $ This- & gt; App- & gt; Example ('EventRsvp', $ this- & gt; Counterfeit); $ This- & gt; Fake - & gt; Receive ('Save') - & gt; Once () - & gt; And return ('right'); $ Response = $ this- & gt; Call ('POST', '/ 3tDYSL0', $ myvar); }} AppController BaseController {Public Function saveApp ($ shortUrl) {$ rsvp = new EventRsvp;} in the App / Controllers / App Controller Class;   
  $ RSVP- & gt; Field on = '124'; $ Rsvp- & gt; Field = 2 = '30233'; $ Rsvp- & gt; Save (); $ ReturnDirect = Redirect :: to (Request :: Path (.) '/ Complete'); Return refund; }}   
  // /app/models/EventRsvp.php located at  Retail To ('Relationivo', 'Idituo'); }}? & Gt; Instead of calling    

new EventRsvp

You may want to create a repository that will provide your controller with EventRsvp s, then you can easily duplicate the repo and inject it instead of the actual one .

Just you know, while doing whatever you try, it is possible to get it, I do not:

  $ fake = joke :: fake ('Surcharge: EventRsvp'); $ Counterfeit & gt; ShouldReceive ('save') - & gt; Once () - & gt; AndReturn (right); $ Response = $ this- & gt; Call ('POST', '/ 3tDYSL0', $ myvar);   

This is a joke with joking example , and it will catch the new EventRsvp call in your controller, and that $ Will be used instead of fake model instead of the real model but then, use dependency injection, this is what you want.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -