forked from mautic/mautic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request mautic#13086 from dadarya0/remove_unnecessary_quer…
…ies_to_integration_entity_table Remove unnecessary queries to integration entity table
- Loading branch information
Showing
2 changed files
with
111 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
app/bundles/PluginBundle/Tests/EventListener/LeadSubscriberTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Mautic\PluginBundle\Tests\EventListener; | ||
|
||
use Mautic\LeadBundle\Entity\Lead; | ||
use Mautic\LeadBundle\Event\LeadEvent; | ||
use Mautic\PluginBundle\Entity\Integration; | ||
use Mautic\PluginBundle\Entity\IntegrationEntityRepository; | ||
use Mautic\PluginBundle\Entity\IntegrationRepository; | ||
use Mautic\PluginBundle\EventListener\LeadSubscriber; | ||
use Mautic\PluginBundle\Model\PluginModel; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class LeadSubscriberTest extends TestCase | ||
{ | ||
private LeadSubscriber $subscriber; | ||
|
||
/** | ||
* @var LeadEvent|MockObject | ||
*/ | ||
private $leadEvent; | ||
|
||
/** | ||
* @var IntegrationEntityRepository|MockObject | ||
*/ | ||
private $integrationEntityRepository; | ||
|
||
/** | ||
* @var IntegrationRepository|MockObject | ||
*/ | ||
private $integrationRepository; | ||
|
||
protected function setUp(): void | ||
{ | ||
$pluginModel = $this->createMock(PluginModel::class); | ||
$this->integrationRepository = $this->createMock(IntegrationRepository::class); | ||
$this->leadEvent = $this->createMock(LeadEvent::class); | ||
$this->integrationEntityRepository = $this->createMock(IntegrationEntityRepository::class); | ||
$this->subscriber = new LeadSubscriber( | ||
$pluginModel, | ||
$this->integrationRepository | ||
); | ||
|
||
$pluginModel->expects($this->once()) | ||
->method('getIntegrationEntityRepository') | ||
->willReturn($this->integrationEntityRepository); | ||
|
||
$this->leadEvent->expects($this->once()) | ||
->method('getLead') | ||
->willReturn(new Lead()); | ||
} | ||
|
||
public function testOnLeadSaveWithoutActiveIntegration(): void | ||
{ | ||
$this->integrationRepository->expects($this->once()) | ||
->method('getIntegrations') | ||
->willReturn([]); | ||
|
||
$this->integrationEntityRepository->expects($this->never()) | ||
->method('updateErrorLeads'); | ||
|
||
$this->subscriber->onLeadSave($this->leadEvent); | ||
} | ||
|
||
public function testOnLeadSaveWithActiveIntegration(): void | ||
{ | ||
$integration = new Integration(); | ||
$integration->setIsPublished(true); | ||
$integration->setApiKeys(['key' => 'some']); | ||
$integration->setSupportedFeatures(['push_lead']); | ||
|
||
$this->integrationRepository->expects($this->once()) | ||
->method('getIntegrations') | ||
->willReturn([$integration]); | ||
|
||
$this->integrationEntityRepository->expects($this->once()) | ||
->method('updateErrorLeads'); | ||
|
||
$this->subscriber->onLeadSave($this->leadEvent); | ||
} | ||
} |