0

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

 magento/module-sales/Test/Unit/Observer/AssignOrderToCustomerObserverTest.php

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

0

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.

New contributor
Pooja Pardeshi is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

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.