use PHPUnit_Framework_MockObject_MockObject; // Create a mock object for MyClass $mock = $this->getMockBuilder(MyClass::class)->getMock(); // Set the return value for addNumbers method to 10 $mock->expects($this->any()) ->method('addNumbers') ->will($this->returnValue(10)); // Call addNumbers method on the mock object $result = $mock->addNumbers(); // Assert that the result is 10 $this->assertEquals(10, $result);
use PHPUnit_Framework_MockObject_MockObject; // Create a mock object for Database $mock = $this->getMockBuilder(Database::class)->getMock(); // Expect the insertData method to be called with parameters 'John' and 'Doe' $mock->expects($this->once()) ->method('insertData') ->with('John', 'Doe'); // Call the method that will call insertData method on the mock object $myObj->insertPersonData($mock);In both examples, we use PHPUnit_Framework_MockObject_MockObject to create a mock object for a specific class and specify the behavior of a method. We then use the execute method to trigger the behavior of the mock object when the specific method is called. The PHPUnit_Framework_MockObject_MockObject is a class in the PHPUnit testing framework library.