Skip to main content
Tweeted twitter.com/StackMagento/status/759475622724984836
edited tags
Link
Source Link

Unit Test or Integration Test for this kind of functions?

I have the following resolve function in one of my classes:

public function __construct( 
   \Magento\Catalog\Api\CategoryRepositoryInterface $categoryRepository,
   \Magento\Framework\Webapi\ServiceInputProcessor $serviceInputProcessor)
    {
        $this->categoryRepository = $categoryRepository;
        $this->serviceInputProcessor = $serviceInputProcessor;
    }

public function resolve($value, array $args, ResolveInfo $info)
{
    $inputParams = $this->serviceInputProcessor->process(\Magento\Catalog\Api\CategoryRepositoryInterface:class, 'save', $args);
    $result = $this->categoryRepository->save($inputParams[0]);
    return $result;
}

In order to test it I have created the following test case:

public function testResolve()
    {
        $categoryRepoMock = $this->getMockBuilder(\Magento\Catalog\Model\CategoryRepository::class)
            ->disableOriginalConstructor()
            ->getMock();

        $serviceInputProcessorMock = $this->getMockBuilder(\Magento\Framework\Webapi\ServiceInputProcessor::class)
            ->disableOriginalConstructor()
            ->getMock();

        $field = new AddCategoryField($categoryRepoMock, $serviceInputProcessorMock);

        // do asserts here
    }

What could I assert there in order to do a proper unit testing?

Should I do unit testing at all?

I am not invoking any my own function, so maybe I can omit unit testing and perform only integration tests?