@gilbert
To test a parent call method in a class using phpspec, you can follow these steps:
Here's an example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
use MyNamespaceMyClass; use ParentNamespaceParentClass; class MyClassSpec extends ObjectBehavior { function it_calls_parent_method() { $parentMock = $this->getParentBehavior(ParentClass::class)->getMock(); $this->beAnInstanceOf(MyClass::class, [$parentMock]); // Set up expectations on the mock object $parentMock->methodToTest()->shouldBeCalled(); // Call the method on the class that calls the parent method $this->methodToTest(); // Assert that the parent method was called with the expected arguments $parentMock->shouldHaveReceived('methodToTest'); } } |
In this example, we create a mock object of the parent class using getParentBehavior()
and set up an expectation on the methodToTest()
method. Then, we call the method on our class that eventually calls the parent method, and finally assert that the parent method was called with the expected arguments using shouldHaveReceived()
.