cancel
Showing results for 
Search instead for 
Did you mean: 

What is tested in category testGetCount() method ?

What is tested in category testGetCount() method ?

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()
        );
    }

 

1 REPLY 1

Re: What is tested in category testGetCount() method ?

If anyone does not know, why this test is necessary why not remove it in next version of Magento??  Does anyone test at all Magento 2 modules? I would like any response (not any for 2 weeks ) or am I ignored in this forum?