I am new at unit testing and TDD. Looking at the Magento 2 source, method I would like to use in my module. I also looked at the unit tests directory. My question is: what is exactly tested with testGetCount method? Can anyone explain it to me?
Magento\Catalog\Model\categoryManagement
public function getCount()
{
$categories = $this->categoriesFactory->create();
/** @var \Magento\Catalog\Model\ResourceModel\Category\Collection $categories */
$categories->addAttributeToFilter('parent_id', ['gt' => 0]);
return $categories->getSize();
}
Magento\Catalog\Test\Unit\Model\categoryManagementTest
public function testGetCount()
{
$categoriesMock = $this->getMock('\Magento\Catalog\Model\ResourceModel\Category\Collection', [], [], '', false);
$this->categoriesFactoryMock
->expects($this->once())
->method('create')
->willReturn($categoriesMock);
$categoriesMock
->expects($this->once())
->method('addAttributeToFilter')
->with('parent_id', ['gt' => 0])
->willReturnSelf();
$categoriesMock
->expects($this->once())
->method('getSize')
->willReturn('expected');
$this->assertEquals(
'expected',
$this->model->getCount()
);
}