Equivalent of SimpleTest “partial mocks” in PHPUnit?

前端 未结 3 1650
轮回少年
轮回少年 2021-02-06 22:54

I\'m trying to migrate a bunch of tests from SimpleTest to PHPUnit and I was wondering if there is an equivalent for SimpleTest\'s partial mocks.

Update: I can\'t seem t

3条回答
  •  后悔当初
    2021-02-06 23:47

    PHPUnit_Framework_TestCase::getMock is deprecated since phpunit 5.4. We can use setMethods instead.

    setMethods(array $methods) can be called on the Mock Builder object to specify the methods that are to be replaced with a configurable test double. The behavior of the other methods is not changed. If you call setMethods(null), then no methods will be replaced.

    https://phpunit.de/manual/current/en/test-doubles.html

    $observer = $this->getMockBuilder(Observer::class)
                     ->setMethods(['update'])
                     ->getMock();
    

    Note that the above getMock is PHPUnit_Framework_MockObject_MockBuilder::getMock. (phpunit5.6)

提交回复
热议问题