I had written the test case for my function which is fetching data from cms_page table but im getting error when running my unit test cases
this is my error
Error: Call to a member function addFilter() on string i added my model and testcase file here
<?php
/**
* Created By : Pvt. Ltd.
*/
namespace RoyalCmsPageModuleModel;
class CmsPage
{
const url= "home";
/**
* @var MagentoCmsApiPageRepositoryInterface
*/
protected $pageRepositoryInterface;
/**
* @var MagentoFrameworkApiSearchCriteriaBuilder
*/
protected $searchCriteriaBuilder;
/**
* @param MagentoFrameworkViewElementTemplateContext $context
* @param MagentoCmsApiPageRepositoryInterface $pageRepositoryInterface
* @param MagentoFrameworkApiSfearchCriteriaBuilder $searchCriteriaBuilder
* @param array $data
*/
public function construct(
MagentoCmsApiPageRepositoryInterface $pageRepositoryInterface,
MagentoFrameworkApiSearchCriteriaBuilder $searchCriteriaBuilder,
array $data = []
) {
$this->pageRepositoryInterface = $pageRepositoryInterface;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
}
/**
* Return CMS Page Details by URL Key
*
* @param string $urlKey
* @return string
*/
public function getCmsPageDetails(){
$searchCriteria = $this->searchCriteriaBuilder->addFilter('identifier', static::url,'eq')->create();
$pages = $this->pageRepositoryInterface->getList($searchCriteria)->getContent();
return $pages;
}
}
test case
<?php
namespace RoyalCmsPageModuleTestUnitModel;
use MagentoFrameworkTestFrameworkUnitHelperObjectManager;
use RoyalCmsPageModuleModelCmsPage;
class CmsPageTest extends PHPUnitFrameworkTestCase
{
protected $pageRepositoryInterface;
protected $searchCriteriaBuilder;
protected $model;
protected $objectManager;
private function getSimpleMock($orginalClassName)
{
return $this->getMockBuilder($orginalClassName)
->disableOriginalConstructor()
->getMock();
}
public function setUp(): void
{
$pageRepositoryInterface = $this->getSimpleMock(PageRepositoryInterface::class);
$searchCriteriaBuilder = $this->getSimpleMock(SearchCriteriaBuilder::class);
$objectManager = new ObjectManager($this);
$this->model = $objectManager->getObject(
CmsPage::class,
[
'pageRepositoryInterface' => $this->pageRepositoryInterface,
'searchCriteriaBuilder' => $this->searchCriteriaBuilder
]
);
}
public function tearDown(): void
{
}
/**
* this function tests the result of the addition of two numbers
*
*/
public function testCmsPageDetails(): void
{
$result = $this->model->getCmsPageDetails();
$expectedResult = 10.0;
$this->assertEquals($expectedResult, $result);
}
}
hope anyone helps me to understand what mistake i did
Thanks in advance!