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

          Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

          2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

          Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme