Skip to content

Commit a235884

Browse files
authored
Merge pull request #61 from bartoszherba/issue-47
Remove Helper classes and replace appropriate code with new implementation
2 parents b0f6a0d + a9ec0c4 commit a235884

File tree

4 files changed

+26
-71
lines changed

4 files changed

+26
-71
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ install:
3333
before_script:
3434
- sh -c "if [ '$TEST_SUITE' = 'configurator' ]; then ./Test/Integration/setup-magento.sh $MAGE_VERSION; fi"
3535
script:
36-
- sh -c "if [ '$TEST_SUITE' = 'phpcs' ]; then php vendor/bin/phpcs --standard=PSR2 Model/ Console/ Test/ Helper/; fi"
37-
- sh -c "if [ '$TEST_SUITE' = 'phpcs' ]; then php vendor/bin/phpmd Model/,Console/,Test/,Helper/ text cleancode,codesize,controversial,design,naming,unusedcode; fi"
38-
- sh -c "if [ '$TEST_SUITE' = 'phpcs' ]; then php vendor/bin/phpcpd Model/ Console/ Test/ Helper/; fi"
36+
- sh -c "if [ '$TEST_SUITE' = 'phpcs' ]; then php vendor/bin/phpcs --standard=PSR2 Model/ Console/ Test/; fi"
37+
- sh -c "if [ '$TEST_SUITE' = 'phpcs' ]; then php vendor/bin/phpmd Model/,Console/,Test/ text cleancode,codesize,controversial,design,naming,unusedcode; fi"
38+
- sh -c "if [ '$TEST_SUITE' = 'phpcs' ]; then php vendor/bin/phpcpd Model/ Console/ Test/; fi"
3939
- sh -c "if [ '$TEST_SUITE' = 'unit' ]; then php vendor/bin/phpunit --coverage-clover build/logs/clover.xml Test/Unit/; fi"
4040
- sh -c "if [ '$TEST_SUITE' = 'configurator' ]; then ./Test/Integration/run-configurator.sh; fi"
4141
notifications:

Component/Pages.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
namespace CtiDigital\Configurator\Component;
44

5-
use CtiDigital\Configurator\Helper\Component;
65
use CtiDigital\Configurator\Exception\ComponentException;
76
use CtiDigital\Configurator\Api\LoggerInterface;
87
use Magento\Cms\Api\Data\PageInterfaceFactory;
98
use Magento\Cms\Api\PageRepositoryInterface;
9+
use Magento\Framework\Exception\NoSuchEntityException;
1010
use Magento\Framework\ObjectManagerInterface;
11+
use Magento\Store\Api\StoreRepositoryInterface;
1112
use Magento\Store\Model\StoreManagerInterface;
1213

1314
/**
@@ -33,28 +34,31 @@ class Pages extends YamlComponentAbstract
3334
/** @var StoreManagerInterface */
3435
protected $storeManager;
3536

36-
/** @var Component */
37-
protected $componentHelper;
38-
37+
/**
38+
* @var StoreRepositoryInterface
39+
*/
40+
private $storeRepository;
3941

4042
/**
4143
* Pages constructor.
44+
*
4245
* @param LoggerInterface $log
4346
* @param ObjectManagerInterface $objectManager
4447
* @param PageRepositoryInterface $pageRepository
4548
* @param PageInterfaceFactory $pageFactory
46-
* @param Component $componentHelper
49+
* @param StoreRepositoryInterface $storeRepository
4750
*/
4851
public function __construct(
4952
LoggerInterface $log,
5053
ObjectManagerInterface $objectManager,
5154
PageRepositoryInterface $pageRepository,
5255
PageInterfaceFactory $pageFactory,
53-
Component $componentHelper
56+
StoreRepositoryInterface $storeRepository
5457
) {
5558
$this->pageFactory = $pageFactory;
5659
$this->pageRepository = $pageRepository;
57-
$this->componentHelper = $componentHelper;
60+
$this->storeRepository = $storeRepository;
61+
5862
parent::__construct($log, $objectManager);
5963
}
6064

@@ -91,7 +95,7 @@ protected function processPage($identifier, $data)
9195
foreach ($data['page'] as $pageData) {
9296
if (isset($pageData['stores'])) {
9397
foreach ($pageData['stores'] as $storeCode) {
94-
$store = $this->componentHelper->getStoreByCode($storeCode);
98+
$store = $this->storeRepository->get($storeCode);
9599
$pageId = $this->pageFactory->create()->checkIdentifier($identifier, $store->getId());
96100
}
97101
} else {
@@ -152,7 +156,7 @@ protected function processPage($identifier, $data)
152156

153157
$stores = array();
154158
foreach ($pageData['stores'] as $code) {
155-
$stores[] = $this->componentHelper->getStoreByCode($code)->getId();
159+
$stores[] = $store = $this->storeRepository->get($code)->getId();
156160
}
157161

158162
$page->setStores($stores);
@@ -168,7 +172,7 @@ protected function processPage($identifier, $data)
168172
}
169173

170174
}
171-
} catch (ComponentException $e) {
175+
} catch (NoSuchEntityException $e) {
172176
$this->log->logError($e->getMessage());
173177
}
174178

Helper/Component.php

Lines changed: 0 additions & 54 deletions
This file was deleted.

Test/Unit/Component/PagesTest.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,29 @@
55
use CtiDigital\Configurator\Component\Pages;
66
use Magento\Cms\Api\PageRepositoryInterface;
77
use Magento\Cms\Api\Data\PageInterfaceFactory;
8-
use CtiDigital\Configurator\Helper\Component;
8+
use Magento\Store\Api\StoreRepositoryInterface;
9+
use Magento\Store\Model\StoreRepository;
910

1011
class PagesTest extends ComponentAbstractTestCase
1112
{
12-
1313
protected function componentSetUp()
1414
{
15+
/** @var PageRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject $pageRepository */
1516
$pageRepository = $this->getMock(PageRepositoryInterface::class);
17+
/** @var PageInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject $pageFactory */
1618
$pageFactory = $this->getMock(PageInterfaceFactory::class);
17-
$componentHelper = $this->getMock(Component::class, [], [], '', false);
19+
/** @var StoreRepository|\PHPUnit_Framework_MockObject_MockObject $storeRepository */
20+
$storeRepository = $this->getMockBuilder(StoreRepositoryInterface::class)
21+
->disableOriginalConstructor()
22+
->getMock();
1823

1924
$this->component =
2025
new Pages(
2126
$this->logInterface,
2227
$this->objectManager,
2328
$pageRepository,
2429
$pageFactory,
25-
$componentHelper
30+
$storeRepository
2631
);
2732

2833
$this->className = Pages::class;

0 commit comments

Comments
 (0)