Question

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

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange
scroll top