customersFactoryMock = $this->createPartialMock( \Magento\Customer\Model\ResourceModel\Customer\CollectionFactory::class, ['create'] ); $this->model = new \Magento\Customer\Model\CustomerManagement( $this->customersFactoryMock ); } public function testGetCount() { $customersMock = $this->createMock(\Magento\Customer\Model\ResourceModel\Customer\Collection::class); $this->customersFactoryMock ->expects($this->once()) ->method('create') ->willReturn($customersMock); $customersMock ->expects($this->once()) ->method('getSize') ->willReturn('expected'); $this->assertEquals( 'expected', $this->model->getCount() ); } }