magento2.3 – Magento 2.3: unitary write test for Observer

I write a unit test for an invoking observer sales_order_place_after Event.

SampleObserver

SampleObserver class extend  PHPUnit  Framework  TestCase
{
public service __construct (
 Sample  Module  Helper  Credit  Config $ helperCreditConfig,
 Sample  Module  Helper  Credit $ helperCredit,
 Magento  Client  Helper  Session  Current Client $ current client,
 Sample  Module  Api  CreditManagementInterface $ creditManagement
) {
$ this-> helperCreditConfig = $ helperCreditConfig;
$ this-> helperCredit = $ helperCredit;
$ this-> currentCustomer = $ currentCustomer;
$ this-> creditManagement = $ creditManagement;
}

/ **
* @param  Magento  Framework  Event  Observer $ observer
* /
public function execute ( Magento  Framework  Event  Observer $ observer)
{
$ order = $ observer-> getEvent () -> getOrder ();
if ($ this-> currentCustomer-> getCustomerId ()) {
// does a good job with the order
}
}
}

SampleObserverTest

SampleObserverTest Class Expands  PHPUnit  Framework  TestCase
{
public service setUp ()
{
$ objectManager = new ObjectManager ($ this);

$ this-> helperCreditConfigMock = $ this-> createMock ( Sample  Module  Helper  Credit  Config);

$ this-> helperCreditMock = $ this-> createMock ( Sample  Module  Helper  Credit & # 39;);

$ this-> currentCustomerMock = $ this-> getMockBuilder ( Magento  Customer  Helper  Session  CurrentCustomer & # 39;)
-> disableOriginalConstructor ()
-> setMethods (['getCustomerId'])
-> getMock ();

$ this-> creditManagementMock = $ this-> createMock ( Sample  Module  Api  CreditManagementInterface & # 39;);

$ this-> sendOrderToVenuePay = $ objectManager-> getObject (
& # 39; Sample  Module  Observer  SendOrderToVenuePay & # 39;
            [
                'helperCreditConfig' => $this->helperCreditConfigMock,
                'helperCredit' => $this->helperCreditMock,
                'currentCustomer' => $this->currentCustomerMock,
                'creditManagement' => $this->creditManagementMock
            ]
        )
}

public function testExecute ()
{
$ this-> eventMock = $ this-> createPartialMock (
 Magento  Framework  Event :: class,
            ['getOrder']
        )
$ this-> eventObserverMock = $ this-> createMock (
 Magento  Framework  Event  Observer :: class
)
$ this-> eventObserverMock
-> wait ($ this-> any ())
-> method (& # 39; getEvent & # 39;)
-> willReturn ($ this-> eventMock);

$ this-> eventMock
-> wait ($ this-> atLeastOnce ())
-> method (& # 39; getOrder & # 39;)
-> willReturn ($ this-> returnSelf ());

$ this-> currentCustomerMock
-> wait ($ this-> atLeastOnce ())
-> method ("getCustomerId")
-> willReturn ($ this-> any ());
}
}

Next block of code

$ this-> currentCustomerMock
-> wait ($ this-> atLeastOnce ())
-> method ("getCustomerId")
-> willReturn ($ this-> any ());

throws

1) Example  Module  Test  Observer  SampleObserverTest :: testExecute
The wait failed because the name of the method is equal to "getCustomerId" when it is called at least once.
Invocation expected at least once but it never happened.

and next block of code

$ this-> eventMock
-> wait ($ this-> atLeastOnce ())
-> method (& # 39; getOrder & # 39;)
-> willReturn ($ this-> returnSelf ());

throws

1) Example  Module  Test  Observer  SampleObserverTest :: testExecute
The wait failed because the name of the method is equal to "getOrder" when it is called at least once.
Invocation expected at least once but it never happened.

Do you like to help what I'm doing wrong? Since I'm new to PHPUnit, I can not understand it.