PHP Mockery partial test double not calling method from parent class2019 Community Moderator ElectionHow do I test a private function or a class that has private methods, fields or inner classes?Reference — What does this symbol mean in PHP?Reference - What does this error mean in PHP?How to partially mock a class using Mockery?Mockery: how does a passive partial mock differ from the default mock?Passing type to SplObserver update methodTesting that one class method calls anothermocking out database queries laravel mockeryMockery: mock publicaly overridden protected methodMockery not able to call my method in testing method

Is there a way to find out the age of climbing ropes?

Can inspiration allow the Rogue to make a Sneak Attack?

The need of reserving one's ability in job interviews

Under what conditions would I NOT add my Proficiency Bonus to a Spell Attack Roll (or Saving Throw DC)?

Can you run a ground wire from stove directly to ground pole in the ground

How do we objectively assess if a dialogue sounds unnatural or cringy?

Are Wave equations equivalent to Maxwell equations in free space?

Is being socially reclusive okay for a graduate student?

Is "cogitate" an appropriate word for this?

Ultrafilters as a double dual

Replacing tantalum capacitor with ceramic capacitor for Op Amps

Did Amazon pay $0 in taxes last year?

Convert an array of objects to array of the objects' values

Should we avoid writing fiction about historical events without extensive research?

Is divide-by-zero a security vulnerability?

Professor forcing me to attend a conference

What is the purpose of a disclaimer like "this is not legal advice"?

How to write a chaotic neutral protagonist and prevent my readers from thinking they are evil?

Are small insurances worth it

If nine coins are tossed, what is the probability that the number of heads is even?

Has a sovereign Communist government ever run, and conceded loss, on a fair election?

Why is my explanation wrong?

When to use the term transposed instead of modulation?

Why is there an extra space when I type "ls" on the Desktop?



PHP Mockery partial test double not calling method from parent class



2019 Community Moderator ElectionHow do I test a private function or a class that has private methods, fields or inner classes?Reference — What does this symbol mean in PHP?Reference - What does this error mean in PHP?How to partially mock a class using Mockery?Mockery: how does a passive partial mock differ from the default mock?Passing type to SplObserver update methodTesting that one class method calls anothermocking out database queries laravel mockeryMockery: mock publicaly overridden protected methodMockery not able to call my method in testing method










1















I'm confused why my partial test double is not calling a method correctly. These are my classes:



abstract class Model

public function update(array $attributes)
$this->performUpdate($attributes);


abstract protected function performUpdate(array $attributes);


class Product extends Model

protected function performUpdate(array $attributes)

print_r($attributes);



$mock = Mockery::mock(Product::class)->makePartial();

$mock->update([]); // the 'performUpdate' method never gets called


When the code is run, performUpdate in the Product class is never called. The 'update' method is called as expected, but the real performUpdate method is never called. Instead, it just returns null as if it were not a partial mock. Partial mocks are supposed to defer to the method in the mocked class if no expectation is set up, so why isn't my method getting called?










share|improve this question


























    1















    I'm confused why my partial test double is not calling a method correctly. These are my classes:



    abstract class Model

    public function update(array $attributes)
    $this->performUpdate($attributes);


    abstract protected function performUpdate(array $attributes);


    class Product extends Model

    protected function performUpdate(array $attributes)

    print_r($attributes);



    $mock = Mockery::mock(Product::class)->makePartial();

    $mock->update([]); // the 'performUpdate' method never gets called


    When the code is run, performUpdate in the Product class is never called. The 'update' method is called as expected, but the real performUpdate method is never called. Instead, it just returns null as if it were not a partial mock. Partial mocks are supposed to defer to the method in the mocked class if no expectation is set up, so why isn't my method getting called?










    share|improve this question
























      1












      1








      1








      I'm confused why my partial test double is not calling a method correctly. These are my classes:



      abstract class Model

      public function update(array $attributes)
      $this->performUpdate($attributes);


      abstract protected function performUpdate(array $attributes);


      class Product extends Model

      protected function performUpdate(array $attributes)

      print_r($attributes);



      $mock = Mockery::mock(Product::class)->makePartial();

      $mock->update([]); // the 'performUpdate' method never gets called


      When the code is run, performUpdate in the Product class is never called. The 'update' method is called as expected, but the real performUpdate method is never called. Instead, it just returns null as if it were not a partial mock. Partial mocks are supposed to defer to the method in the mocked class if no expectation is set up, so why isn't my method getting called?










      share|improve this question














      I'm confused why my partial test double is not calling a method correctly. These are my classes:



      abstract class Model

      public function update(array $attributes)
      $this->performUpdate($attributes);


      abstract protected function performUpdate(array $attributes);


      class Product extends Model

      protected function performUpdate(array $attributes)

      print_r($attributes);



      $mock = Mockery::mock(Product::class)->makePartial();

      $mock->update([]); // the 'performUpdate' method never gets called


      When the code is run, performUpdate in the Product class is never called. The 'update' method is called as expected, but the real performUpdate method is never called. Instead, it just returns null as if it were not a partial mock. Partial mocks are supposed to defer to the method in the mocked class if no expectation is set up, so why isn't my method getting called?







      php unit-testing mockery






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 5 at 4:19









      flyingL123flyingL123

      2,96352773




      2,96352773






















          1 Answer
          1






          active

          oldest

          votes


















          0














          You have to use the shouldAllowMockingProtectedMethods when creating the mock. This will resolve the issue of you not seeing the output.






          share|improve this answer

























          • That’s not true. The method is not called. Did you try it yourself?

            – flyingL123
            yesterday











          • Yes I tried it and it works fine. Since you don't return anything from the function performUpdate you're getting null back. If you try the same thing in the console you'll see the text

            – Borisu
            yesterday











          • But I’m not taking about returning anything. Running that code should print an empty array. For me it doesn’t. It does for you? I’ll have to check again.

            – flyingL123
            yesterday











          • Sorry about that, I was testing with a class where the method was public. I've edited the answer to show how to use it with protected methods.

            – Borisu
            yesterday











          • But I’m not mocking the protected method. The protected method is an internal call. Since it’s a partial mock, the call to the public update method should call performUpdate internally as normal, but it’s not.

            – flyingL123
            yesterday










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54995324%2fphp-mockery-partial-test-double-not-calling-method-from-parent-class%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          You have to use the shouldAllowMockingProtectedMethods when creating the mock. This will resolve the issue of you not seeing the output.






          share|improve this answer

























          • That’s not true. The method is not called. Did you try it yourself?

            – flyingL123
            yesterday











          • Yes I tried it and it works fine. Since you don't return anything from the function performUpdate you're getting null back. If you try the same thing in the console you'll see the text

            – Borisu
            yesterday











          • But I’m not taking about returning anything. Running that code should print an empty array. For me it doesn’t. It does for you? I’ll have to check again.

            – flyingL123
            yesterday











          • Sorry about that, I was testing with a class where the method was public. I've edited the answer to show how to use it with protected methods.

            – Borisu
            yesterday











          • But I’m not mocking the protected method. The protected method is an internal call. Since it’s a partial mock, the call to the public update method should call performUpdate internally as normal, but it’s not.

            – flyingL123
            yesterday















          0














          You have to use the shouldAllowMockingProtectedMethods when creating the mock. This will resolve the issue of you not seeing the output.






          share|improve this answer

























          • That’s not true. The method is not called. Did you try it yourself?

            – flyingL123
            yesterday











          • Yes I tried it and it works fine. Since you don't return anything from the function performUpdate you're getting null back. If you try the same thing in the console you'll see the text

            – Borisu
            yesterday











          • But I’m not taking about returning anything. Running that code should print an empty array. For me it doesn’t. It does for you? I’ll have to check again.

            – flyingL123
            yesterday











          • Sorry about that, I was testing with a class where the method was public. I've edited the answer to show how to use it with protected methods.

            – Borisu
            yesterday











          • But I’m not mocking the protected method. The protected method is an internal call. Since it’s a partial mock, the call to the public update method should call performUpdate internally as normal, but it’s not.

            – flyingL123
            yesterday













          0












          0








          0







          You have to use the shouldAllowMockingProtectedMethods when creating the mock. This will resolve the issue of you not seeing the output.






          share|improve this answer















          You have to use the shouldAllowMockingProtectedMethods when creating the mock. This will resolve the issue of you not seeing the output.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited yesterday

























          answered yesterday









          BorisuBorisu

          520210




          520210












          • That’s not true. The method is not called. Did you try it yourself?

            – flyingL123
            yesterday











          • Yes I tried it and it works fine. Since you don't return anything from the function performUpdate you're getting null back. If you try the same thing in the console you'll see the text

            – Borisu
            yesterday











          • But I’m not taking about returning anything. Running that code should print an empty array. For me it doesn’t. It does for you? I’ll have to check again.

            – flyingL123
            yesterday











          • Sorry about that, I was testing with a class where the method was public. I've edited the answer to show how to use it with protected methods.

            – Borisu
            yesterday











          • But I’m not mocking the protected method. The protected method is an internal call. Since it’s a partial mock, the call to the public update method should call performUpdate internally as normal, but it’s not.

            – flyingL123
            yesterday

















          • That’s not true. The method is not called. Did you try it yourself?

            – flyingL123
            yesterday











          • Yes I tried it and it works fine. Since you don't return anything from the function performUpdate you're getting null back. If you try the same thing in the console you'll see the text

            – Borisu
            yesterday











          • But I’m not taking about returning anything. Running that code should print an empty array. For me it doesn’t. It does for you? I’ll have to check again.

            – flyingL123
            yesterday











          • Sorry about that, I was testing with a class where the method was public. I've edited the answer to show how to use it with protected methods.

            – Borisu
            yesterday











          • But I’m not mocking the protected method. The protected method is an internal call. Since it’s a partial mock, the call to the public update method should call performUpdate internally as normal, but it’s not.

            – flyingL123
            yesterday
















          That’s not true. The method is not called. Did you try it yourself?

          – flyingL123
          yesterday





          That’s not true. The method is not called. Did you try it yourself?

          – flyingL123
          yesterday













          Yes I tried it and it works fine. Since you don't return anything from the function performUpdate you're getting null back. If you try the same thing in the console you'll see the text

          – Borisu
          yesterday





          Yes I tried it and it works fine. Since you don't return anything from the function performUpdate you're getting null back. If you try the same thing in the console you'll see the text

          – Borisu
          yesterday













          But I’m not taking about returning anything. Running that code should print an empty array. For me it doesn’t. It does for you? I’ll have to check again.

          – flyingL123
          yesterday





          But I’m not taking about returning anything. Running that code should print an empty array. For me it doesn’t. It does for you? I’ll have to check again.

          – flyingL123
          yesterday













          Sorry about that, I was testing with a class where the method was public. I've edited the answer to show how to use it with protected methods.

          – Borisu
          yesterday





          Sorry about that, I was testing with a class where the method was public. I've edited the answer to show how to use it with protected methods.

          – Borisu
          yesterday













          But I’m not mocking the protected method. The protected method is an internal call. Since it’s a partial mock, the call to the public update method should call performUpdate internally as normal, but it’s not.

          – flyingL123
          yesterday





          But I’m not mocking the protected method. The protected method is an internal call. Since it’s a partial mock, the call to the public update method should call performUpdate internally as normal, but it’s not.

          – flyingL123
          yesterday



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54995324%2fphp-mockery-partial-test-double-not-calling-method-from-parent-class%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

          Understanding generators in Python2019 Community Moderator ElectionGenerator function not working pythonFor loop not executing two timesGenerators - Printing generated valuesWhy can a python generator only be used once?What exactly do generators do?What does the “yield” keyword do?What does “list comprehension” mean? How does it work and how can I use it?sklearn Kfold acces single fold instead of for loopIs a generator the callable? Which is the generator?Apply Border To Range Of Cells Using OpenpyxlCalling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Understanding slice notationUnderstanding Python super() with __init__() methodsDoes Python have a string 'contains' substring method?

          How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page