I was wondering what is best practice for Unit test case writing for observers ? I looked for examples in core , and found below file


I found even there are no assertions are performed but when we run test case for it

Time: 1.6 seconds, Memory: 10.00MB

OK (1 test, 3 assertions)

if someone can even point me to reference article it would be helpful


Calling any method with expects once() will increase your invoke count by one. You can find reference in PHPUnit\Framework\TestCase class :

     * Returns a matcher that matches when the method is executed exactly once.
     * @return InvokedCountMatcher
    public static function once()
        return new InvokedCountMatcher(1);

Please check verifyMockObjects function from same file, it increase count of assertion depending on method invoked count.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.