That is my methodology, for which I need to write a unit check:
personal $productRepository;
public operate __construct(
ProductRepositoryInterface $productRepository
)
{
$this->productRepository = $productRepository;
}
public operate getProductName(int $productEntityId) : string
{
$myProduct = $this->productRepository->getById($productEntityId);
return (string) $myProduct->getName();
}
and my check:
/**
* @dataProvider productEntityIds
* @param $productEntityId
*/
public operate testGetProductName($productEntityId)
{
$this->assertInternalType('string', $this->myCustomClass->getProductName($productEntityId));
//assertIsString().
}
public operate productEntityIds()
{
return [
[1]
[2],
[3],
[5],
['myString']
];
}
Once I run my check, I’m receiving the next error message:
Error: Name to a member operate getName() on null
If I name the tactic( getProductName()
), in a cronjob or an observer I efficiently acquired the product title. However If name it from the phpunit check , I’m receiving that error. Does anybody know why ?
Thanks