Skip to content

Commit 353290f

Browse files
authored
Merge pull request #149 from magento-commerce/fix/update-magento-source
updated logic to fetch magento edition
2 parents afea900 + e3633cc commit 353290f

File tree

2 files changed

+34
-49
lines changed

2 files changed

+34
-49
lines changed

app/code/Meta/BusinessExtension/Helper/FBEHelper.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Magento\Framework\App\Helper\AbstractHelper;
2525
use Magento\Framework\App\Helper\Context;
2626
use Magento\Framework\App\ProductMetadataInterface;
27+
use Magento\Framework\App\ProductMetadata as FrameworkProductMetaData;
2728
use Magento\Framework\App\ResourceConnection;
2829
use Magento\Framework\HTTP\Client\Curl;
2930
use Magento\Framework\Module\ModuleListInterface;
@@ -84,6 +85,11 @@ class FBEHelper extends AbstractHelper
8485
*/
8586
private $systemConfig;
8687

88+
/**
89+
* @var ProductMetadataInterface
90+
*/
91+
private $productMetadata;
92+
8793
/**
8894
* FBEHelper constructor
8995
*
@@ -95,6 +101,7 @@ class FBEHelper extends AbstractHelper
95101
* @param ResourceConnection $resourceConnection
96102
* @param ModuleListInterface $moduleList
97103
* @param SystemConfig $systemConfig
104+
* @param ProductMetadataInterface $productMetadata
98105
*/
99106
public function __construct(
100107
Context $context,
@@ -104,7 +111,8 @@ public function __construct(
104111
Curl $curl,
105112
ResourceConnection $resourceConnection,
106113
ModuleListInterface $moduleList,
107-
SystemConfig $systemConfig
114+
SystemConfig $systemConfig,
115+
ProductMetadataInterface $productMetadata
108116
) {
109117
parent::__construct($context);
110118
$this->objectManager = $objectManager;
@@ -114,16 +122,17 @@ public function __construct(
114122
$this->resourceConnection = $resourceConnection;
115123
$this->moduleList = $moduleList;
116124
$this->systemConfig = $systemConfig;
125+
$this->productMetadata = $productMetadata;
117126
}
118127

119128
/**
120129
* Get magento version
121130
*
122-
* @return mixed
131+
* @return string
123132
*/
124-
public function getMagentoVersion()
133+
public function getMagentoVersion(): string
125134
{
126-
return $this->objectManager->get(ProductMetadataInterface::class)->getVersion();
135+
return $this->productMetadata->getVersion();
127136
}
128137

129138
/**
@@ -141,9 +150,9 @@ public function getPluginVersion()
141150
*
142151
* @return string
143152
*/
144-
public function getSource()
153+
public function getSource(): string
145154
{
146-
return 'magento2';
155+
return $this->productMetadata->getEdition() == FrameworkProductMetaData::EDITION_NAME ? 'magento_opensource' : 'adobe_commerce';
147156
}
148157

149158
/**

app/code/Meta/BusinessExtension/Test/Unit/Helper/FBEHelperTest.php

Lines changed: 19 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,7 @@ class FBEHelperTest extends TestCase
3535
/**
3636
* @var FBEHelper
3737
*/
38-
private $fbeHelper;
39-
40-
/**
41-
* @var MockObject
42-
*/
43-
private $systemConfig;
44-
45-
/**
46-
* @var MockObject
47-
*/
48-
private $context;
38+
private FBEHelper $fbeHelper;
4939

5040
/**
5141
* @var MockObject
@@ -55,27 +45,12 @@ class FBEHelperTest extends TestCase
5545
/**
5646
* @var MockObject
5747
*/
58-
private $logger;
59-
60-
/**
61-
* @var MockObject
62-
*/
63-
private $storeManager;
64-
65-
/**
66-
* @var MockObject
67-
*/
68-
private $curl;
69-
70-
/**
71-
* @var MockObject
72-
*/
73-
private $resourceConnection;
48+
private $moduleList;
7449

7550
/**
76-
* @var MockObject
51+
* @var ProductMetadataInterface|MockObject
7752
*/
78-
private $moduleList;
53+
private $productMetaData;
7954

8055
/**
8156
* Used to reset or change values after running a test
@@ -93,23 +68,25 @@ public function tearDown(): void
9368
*/
9469
public function setUp(): void
9570
{
96-
$this->context = $this->createMock(Context::class);
71+
$context = $this->createMock(Context::class);
9772
$this->objectManagerInterface = $this->createMock(ObjectManagerInterface::class);
98-
$this->logger = $this->createMock(Logger::class);
99-
$this->storeManager = $this->createMock(StoreManagerInterface::class);
100-
$this->curl = $this->createMock(Curl::class);
101-
$this->resourceConnection = $this->createMock(ResourceConnection::class);
73+
$logger = $this->createMock(Logger::class);
74+
$storeManager = $this->createMock(StoreManagerInterface::class);
75+
$curl = $this->createMock(Curl::class);
76+
$resourceConnection = $this->createMock(ResourceConnection::class);
10277
$this->moduleList = $this->createMock(ModuleListInterface::class);
103-
$this->systemConfig = $this->createMock(Config::class);
78+
$systemConfig = $this->createMock(Config::class);
79+
$this->productMetaData = $this->createMock(ProductMetadataInterface::class);
10480
$this->fbeHelper = new FBEHelper(
105-
$this->context,
81+
$context,
10682
$this->objectManagerInterface,
107-
$this->logger,
108-
$this->storeManager,
109-
$this->curl,
110-
$this->resourceConnection,
83+
$logger,
84+
$storeManager,
85+
$curl,
86+
$resourceConnection,
11187
$this->moduleList,
112-
$this->systemConfig
88+
$systemConfig,
89+
$this->productMetaData
11390
);
11491
}
11592

@@ -132,8 +109,7 @@ public function testCorrectPartnerAgent()
132109
->disableOriginalConstructor()
133110
->setMethods(['getVersion', 'getEdition', 'getName'])
134111
->getMock();
135-
$productMetadata->method('getVersion')->willReturn($magentoVersion);
136-
$productMetadata->method('getVersion')->willReturn($magentoVersion);
112+
$this->productMetaData->expects($this->once())->method('getVersion')->willReturn($magentoVersion);
137113
$this->objectManagerInterface->method('get')->willReturn($productMetadata);
138114
$this->assertEquals(
139115
sprintf('%s-%s-%s', $source, $magentoVersion, $pluginVersion),

0 commit comments

Comments
 (0)