Skip to content

Commit ada4bfb

Browse files
committed
#1823: Cover GetAssetByIdInterface with integration test - added integration test file and mock class
1 parent bfe916e commit ada4bfb

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\AdobeStockAsset\Test\Integration\Model;
9+
10+
use Magento\AdobeStockAssetApi\Api\GetAssetByIdInterface;
11+
use Magento\AdobeStockAssetApi\Api\GetAssetListInterface;
12+
use Magento\Framework\Api\Search\DocumentInterface;
13+
use Magento\TestFramework\Helper\Bootstrap;
14+
use PHPUnit\Framework\TestCase;
15+
16+
class GetAssetByIdTest extends TestCase
17+
{
18+
/**
19+
* @var GetAssetByIdInterface
20+
*/
21+
private $getAssetById;
22+
23+
protected function setUp(): void
24+
{
25+
Bootstrap::getObjectManager()->configure([
26+
'preferences' => [
27+
GetAssetListInterface::class => GetAssetListMock::class
28+
]
29+
]);
30+
31+
$this->getAssetById = Bootstrap::getObjectManager()->get(GetAssetByIdInterface::class);
32+
}
33+
34+
public function testExecute(): void
35+
{
36+
/** @var DocumentInterface $searchResults */
37+
$searchResults = $this->getAssetById->execute(123455678);
38+
39+
$this->assertInstanceOf(DocumentInterface::class, $searchResults);
40+
$this->assertNotEmpty($searchResults);
41+
$this->assertEquals(123455678, $searchResults->getId());
42+
}
43+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\AdobeStockAsset\Test\Integration\Model;
9+
10+
use Magento\AdobeStockAsset\Model\GetAssetList;
11+
use Magento\Framework\Api\AttributeValue;
12+
use Magento\Framework\Api\Search\Document;
13+
use Magento\Framework\Api\Search\SearchCriteriaInterface;
14+
use Magento\Framework\Api\Search\SearchResult;
15+
use Magento\Framework\Api\Search\SearchResultInterface;
16+
17+
class GetAssetListMock extends GetAssetList
18+
{
19+
/**
20+
* Search for images based on search criteria
21+
*
22+
* @param SearchCriteriaInterface $searchCriteria
23+
* @return SearchResultInterface
24+
*/
25+
public function execute(SearchCriteriaInterface $searchCriteria): SearchResultInterface
26+
{
27+
$items = [
28+
new Document(
29+
[
30+
'id' => 123455678,
31+
'custom_attributes' => [
32+
'id_field_name' => new AttributeValue(
33+
['attribute_code' => 'id_field_name']
34+
)
35+
]
36+
]
37+
)
38+
];
39+
$searchResult = new SearchResult();
40+
$searchResult->setSearchCriteria($searchCriteria);
41+
$searchResult->setItems($items);
42+
$searchResult->setTotalCount(1);
43+
44+
return $searchResult;
45+
}
46+
}

0 commit comments

Comments
 (0)