Initial commit: CloudOps infrastructure platform
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Mautic\MessengerBundle\Tests\Message;
|
||||
|
||||
use Mautic\MessengerBundle\Message\EmailHitNotification;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class EmailHitNotificationTest extends TestCase
|
||||
{
|
||||
public function testConstruct(): void
|
||||
{
|
||||
$request = new Request();
|
||||
$request->query->set('testMe', 'Hit me once');
|
||||
|
||||
$message = new EmailHitNotification('statid', $request);
|
||||
|
||||
$this->assertArrayHasKey('testMe', $message->getRequest()->query->all());
|
||||
$this->assertEquals($request, $message->getRequest());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Mautic\MessengerBundle\Tests\Message;
|
||||
|
||||
use Mautic\MessengerBundle\Message\PageHitNotification;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class PageHitNotificationTest extends TestCase
|
||||
{
|
||||
public function testConstruct(): void
|
||||
{
|
||||
$request = new Request();
|
||||
$request->query->set('testMe', 'Hit me once');
|
||||
|
||||
$message = new PageHitNotification(78, $request, false, false, 3, 1);
|
||||
|
||||
$this->assertArrayHasKey('testMe', $message->getRequest()->query->all());
|
||||
$this->assertEquals($request, $message->getRequest());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace Mautic\MessengerBundle\Tests\MessageHandler;
|
||||
|
||||
use Doctrine\DBAL\Exception\RetryableException;
|
||||
use Mautic\CoreBundle\Helper\CoreParametersHelper;
|
||||
use Mautic\EmailBundle\Model\EmailModel;
|
||||
use Mautic\MessengerBundle\Message\EmailHitNotification;
|
||||
use Mautic\MessengerBundle\MessageHandler\EmailHitNotificationHandler;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Messenger\Exception\RecoverableMessageHandlingException;
|
||||
|
||||
class EmailHitNotificationHandlerTest extends TestCase
|
||||
{
|
||||
public function testInvoke(): void
|
||||
{
|
||||
$hitId = sha1((string) random_int(0, 1_000_000));
|
||||
$request = new Request();
|
||||
$request->query->set('testMe', 'I am here');
|
||||
|
||||
/** @var MockObject|EmailModel $emailModelMock */
|
||||
$emailModelMock = $this->createMock(EmailModel::class);
|
||||
$emailModelMock
|
||||
->expects($this->exactly(1))
|
||||
->method('hitEmail')
|
||||
->with($hitId, $request);
|
||||
|
||||
/** @var MockObject&CoreParametersHelper $parametersHelper */
|
||||
$parametersHelper = $this->createMock(CoreParametersHelper::class);
|
||||
$parametersHelper->method('get')
|
||||
->willReturn('sync://');
|
||||
|
||||
$message = new EmailHitNotification($hitId, $request);
|
||||
|
||||
$handler = new EmailHitNotificationHandler($emailModelMock, $parametersHelper);
|
||||
$handler->__invoke($message);
|
||||
}
|
||||
|
||||
public function testInvokeThrowsRecoverableExceptionOnDBLock(): void
|
||||
{
|
||||
$hitId = sha1((string) random_int(0, 1_000_000));
|
||||
$request = new Request();
|
||||
$request->query->set('testMe', 'I am here');
|
||||
|
||||
/** @var MockObject|EmailModel $emailModelMock */
|
||||
$emailModelMock = $this->createMock(EmailModel::class);
|
||||
$emailModelMock
|
||||
->expects($this->exactly(1))
|
||||
->method('hitEmail')
|
||||
->willThrowException($this->createMock(RetryableException::class));
|
||||
|
||||
/** @var MockObject&CoreParametersHelper $parametersHelper */
|
||||
$parametersHelper = $this->createMock(CoreParametersHelper::class);
|
||||
$parametersHelper->method('get')
|
||||
->willReturn('sync://');
|
||||
|
||||
$message = new EmailHitNotification($hitId, $request);
|
||||
|
||||
$handler = new EmailHitNotificationHandler($emailModelMock, $parametersHelper);
|
||||
$this->expectException(RecoverableMessageHandlingException::class);
|
||||
$handler->__invoke($message);
|
||||
}
|
||||
|
||||
public function testInvokeLogsUnrecoverableException(): void
|
||||
{
|
||||
$hitId = sha1((string) random_int(0, 1_000_000));
|
||||
$request = new Request();
|
||||
$request->query->set('testMe', 'I am here');
|
||||
|
||||
/** @var MockObject|EmailModel $emailModelMock */
|
||||
$emailModelMock = $this->createMock(EmailModel::class);
|
||||
$emailModelMock
|
||||
->expects($this->exactly(1))
|
||||
->method('hitEmail')
|
||||
->willThrowException(new \InvalidArgumentException('got my argument?'));
|
||||
|
||||
/** @var MockObject&CoreParametersHelper $parametersHelper */
|
||||
$parametersHelper = $this->createMock(CoreParametersHelper::class);
|
||||
$parametersHelper->method('get')
|
||||
->willReturn('sync://');
|
||||
|
||||
$message = new EmailHitNotification($hitId, $request);
|
||||
$handler = new EmailHitNotificationHandler($emailModelMock, $parametersHelper);
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('got my argument?');
|
||||
$handler->__invoke($message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace Mautic\MessengerBundle\Tests\MessageHandler;
|
||||
|
||||
use Mautic\LeadBundle\Entity\Lead;
|
||||
use Mautic\LeadBundle\Entity\LeadRepository;
|
||||
use Mautic\MessengerBundle\Message\PageHitNotification;
|
||||
use Mautic\MessengerBundle\MessageHandler\PageHitNotificationHandler;
|
||||
use Mautic\PageBundle\Entity\Hit;
|
||||
use Mautic\PageBundle\Entity\HitRepository;
|
||||
use Mautic\PageBundle\Entity\Page;
|
||||
use Mautic\PageBundle\Entity\PageRepository;
|
||||
use Mautic\PageBundle\Entity\Redirect;
|
||||
use Mautic\PageBundle\Entity\RedirectRepository;
|
||||
use Mautic\PageBundle\Model\PageModel;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class PageHitNotificationHandlerTest extends TestCase
|
||||
{
|
||||
public function testInvoke(): void
|
||||
{
|
||||
[$hitId, $pageId, $leadId, $redirectId] = [random_int(1, 1000), random_int(1, 1000), random_int(1, 1000), random_int(1, 1000)];
|
||||
|
||||
$redirectObject = new Redirect();
|
||||
$redirectObject->setRedirectId((string) $redirectId);
|
||||
|
||||
[$hitObject, $pageObject, $leadObject] = [
|
||||
(new Hit())->setCode(7),
|
||||
(new Page())->setAlias('james_bond'),
|
||||
(new Lead())->setId($leadId),
|
||||
];
|
||||
|
||||
$hitRepoMock = $this->createMock(HitRepository::class);
|
||||
$hitRepoMock
|
||||
->expects($this->once())
|
||||
->method('find')
|
||||
->with($hitId)
|
||||
->willReturn($hitObject);
|
||||
|
||||
$pageRepoMock = $this->createMock(PageRepository::class);
|
||||
$pageRepoMock->expects($this->once())
|
||||
->method('find')
|
||||
->with($pageId)
|
||||
->willReturn($pageObject);
|
||||
|
||||
$redirectRepoMock = $this->createMock(RedirectRepository::class);
|
||||
$redirectRepoMock
|
||||
->expects($this->never())
|
||||
->method('find')
|
||||
->with($redirectId)
|
||||
->willReturn($redirectObject);
|
||||
|
||||
$leadRepoMock = $this->createMock(LeadRepository::class);
|
||||
$leadRepoMock
|
||||
->expects($this->once())
|
||||
->method('find')
|
||||
->with($leadId)
|
||||
->willReturn($leadObject);
|
||||
|
||||
$request = new Request();
|
||||
$request->query->set('testMe', 'I am here');
|
||||
|
||||
/** @var MockObject|PageModel $pageModelMock */
|
||||
$pageModelMock = $this->createMock(PageModel::class);
|
||||
$pageModelMock
|
||||
->expects($this->exactly(1))
|
||||
->method('processPageHit')
|
||||
->with($hitObject, $pageObject, $request, $leadObject, false, false);
|
||||
|
||||
$message = new PageHitNotification($hitId, $request, false, false, $pageId, $leadId);
|
||||
|
||||
/** @var MockObject|LoggerInterface $loggerMock */
|
||||
$loggerMock = $this->createMock(LoggerInterface::class);
|
||||
|
||||
$handler = new PageHitNotificationHandler(
|
||||
$pageRepoMock, $hitRepoMock, $leadRepoMock, $loggerMock, $redirectRepoMock, $pageModelMock
|
||||
);
|
||||
|
||||
$handler->__invoke($message);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user