Skip to content

Commit

Permalink
Use DI for services & remove aliases - resolves #205
Browse files Browse the repository at this point in the history
  • Loading branch information
dvesh3 committed Dec 28, 2022
1 parent e0e9d1e commit dcd0fbe
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
10 changes: 9 additions & 1 deletion src/Newsletter/AddressSource/SegmentAddressSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,22 @@ public function __construct(array $arguments)
} else {
$operator = SegmentManagerInterface::CONDITION_OR;
}
$this->segmentManager = \Pimcore::getContainer()->get(SegmentManagerInterface::class);

$this->sendingParamContainers = $this->setUpSendingParamContainers(
array_filter($arguments['segmentIds']),
$operator,
$arguments['filterFlags']
);
}

/**
* @required
*/
public function setSegmentManager(SegmentManagerInterface $segmentManager): void
{
$this->segmentManager = $segmentManager;
}

/**
* @inheritDoc
*/
Expand Down
5 changes: 3 additions & 2 deletions tests/Model/Activity/ActivityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace CustomerManagementFrameworkBundle\Tests\Model\Activity;
use CustomerManagementFrameworkBundle\ActivityManager\ActivityManagerInterface;
use CustomerManagementFrameworkBundle\ActivityStore\ActivityStoreInterface;
use CustomerManagementFrameworkBundle\Model\Activity\GenericActivity;
use Pimcore\Model\DataObject\Customer;
use Pimcore\Tests\Support\Test\ModelTestCase;
Expand Down Expand Up @@ -36,8 +37,8 @@ protected function createCustomer(): Customer {

public function testTrackActivity() {

$activityManager = \Pimcore::getContainer()->get(ActivityManagerInterface::class);
$activityStore = \Pimcore::getContainer()->get('cmf.activity_store');
$activityManager = $this->tester->grabService(ActivityManagerInterface::class);
$activityStore = $this->tester->grabService(ActivityStoreInterface::class);

$customer = $this->createCustomer();

Expand Down
6 changes: 3 additions & 3 deletions tests/Model/Customer/CustomerListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function tearDown(): void

protected function createSegments()
{
$segmentManager = \Pimcore::getContainer()->get(SegmentManagerInterface::class);
$segmentManager = $this->tester->grabService(SegmentManagerInterface::class);
$segmentManager->resetSegmentsFolder();
foreach ($this->segmentDummyData as $segment) {
$segmentManager->createSegment($segment['name'], $segment['group'], $segment['name']);
Expand All @@ -122,7 +122,7 @@ protected function createSegments()

protected function createCustomers()
{
$segmentManager = \Pimcore::getContainer()->get(SegmentManagerInterface::class);
$segmentManager = $this->tester->grabService(SegmentManagerInterface::class);

foreach ($this->customerDummyData as &$customerData) {

Expand Down Expand Up @@ -351,7 +351,7 @@ public function testDateBetweenFilter()

public function testCustomerSegmentFilter()
{
$segmentManager = \Pimcore::getContainer()->get(SegmentManagerInterface::class);
$segmentManager = $this->tester->grabService(SegmentManagerInterface::class);

//test one filter
$listing = new Customer\Listing();
Expand Down
10 changes: 10 additions & 0 deletions tests/_support/Helper/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,14 @@ public function initializeDefinitions()
$cm = $this->getModule('\\' . ClassManager::class);
$cm->setupClass('Customer', __DIR__ . '/../../../install/class_source/optional/class_Customer_export.json');
}

/**
* @throws \Codeception\Exception\ModuleException
*/
public function grabService(string $serviceId): mixed
{
$pimcoreHelper = $this->getModule('\\' . Pimcore::class);

return $pimcoreHelper->grabService($serviceId);
}
}

0 comments on commit dcd0fbe

Please sign in to comment.