Initial commit: CloudOps infrastructure platform
This commit is contained in:
@@ -0,0 +1,183 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Mautic\PluginBundle\Tests\Integration;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use GuzzleHttp\RequestOptions;
|
||||
use Mautic\PluginBundle\Integration\AbstractIntegration;
|
||||
use PHPUnit\Framework\Assert;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
class AbstractIntegrationTest extends AbstractIntegrationTestCase
|
||||
{
|
||||
public function testPopulatedLeadDataReturnsIntAndNotDncEntityForMauticContactIsContactableByEmail(): void
|
||||
{
|
||||
/**
|
||||
* @var MockObject&AbstractIntegration
|
||||
*/
|
||||
$integration = $this->getMockBuilder(AbstractIntegration::class)
|
||||
->setConstructorArgs([
|
||||
$this->dispatcher,
|
||||
$this->cache,
|
||||
$this->em,
|
||||
$this->request,
|
||||
$this->router,
|
||||
$this->translator,
|
||||
$this->logger,
|
||||
$this->encryptionHelper,
|
||||
$this->leadModel,
|
||||
$this->companyModel,
|
||||
$this->pathsHelper,
|
||||
$this->notificationModel,
|
||||
$this->fieldModel,
|
||||
$this->integrationEntityModel,
|
||||
$this->doNotContact,
|
||||
$this->fieldsWithUniqueIdentifier,
|
||||
])
|
||||
->onlyMethods(['getName', 'getAuthenticationType', 'getAvailableLeadFields'])
|
||||
->getMock();
|
||||
|
||||
$integration->method('getAvailableLeadFields')
|
||||
->willReturn(
|
||||
[
|
||||
'dnc' => [
|
||||
'type' => 'bool',
|
||||
'required' => false,
|
||||
'label' => 'DNC',
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
['dnc' => 0],
|
||||
$integration->populateLeadData(
|
||||
['id' => 1],
|
||||
[
|
||||
'leadFields' => [
|
||||
'dnc' => 'mauticContactIsContactableByEmail',
|
||||
],
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[] $parameters
|
||||
* @param mixed[] $settings
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('requestProvider')]
|
||||
public function testMakeRequest(string $uri, array $parameters, string $method, array $settings, object $assertRequest): void
|
||||
{
|
||||
/**
|
||||
* @var MockObject&AbstractIntegration
|
||||
*/
|
||||
$integration = $this->getMockBuilder(AbstractIntegration::class)
|
||||
->setConstructorArgs([
|
||||
$this->dispatcher,
|
||||
$this->cache,
|
||||
$this->em,
|
||||
$this->request,
|
||||
$this->router,
|
||||
$this->translator,
|
||||
$this->logger,
|
||||
$this->encryptionHelper,
|
||||
$this->leadModel,
|
||||
$this->companyModel,
|
||||
$this->pathsHelper,
|
||||
$this->notificationModel,
|
||||
$this->fieldModel,
|
||||
$this->integrationEntityModel,
|
||||
$this->doNotContact,
|
||||
$this->fieldsWithUniqueIdentifier,
|
||||
])
|
||||
->onlyMethods(['getName', 'getAuthenticationType', 'makeHttpClient'])
|
||||
->getMock();
|
||||
|
||||
$integration->method('makeHttpClient')
|
||||
->willReturn(
|
||||
new class($assertRequest) extends Client {
|
||||
public function __construct(
|
||||
private object $assertRequest,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[] $options
|
||||
*/
|
||||
public function request(string $method, $uri = '', array $options = []): ResponseInterface
|
||||
{
|
||||
$this->assertRequest->assert($method, $uri, $options);
|
||||
|
||||
return new Response();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
$this->assertEquals([], $integration->makeRequest($uri, $parameters, $method, $settings));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return iterable<mixed[]>
|
||||
*/
|
||||
public static function requestProvider(): iterable
|
||||
{
|
||||
// Test with JSON.
|
||||
yield [
|
||||
'https://some.uri',
|
||||
['this will be' => 'encoded to json string'],
|
||||
'POST',
|
||||
[
|
||||
'ignore_event_dispatch' => true,
|
||||
'encode_parameters' => 'json',
|
||||
],
|
||||
new class {
|
||||
/**
|
||||
* @param mixed[] $options
|
||||
*/
|
||||
public function assert(string $method, string $uri = '', array $options = []): void
|
||||
{
|
||||
Assert::assertSame('POST', $method);
|
||||
Assert::assertSame('https://some.uri', $uri);
|
||||
Assert::assertSame(
|
||||
[
|
||||
RequestOptions::BODY => '{"this will be":"encoded to json string"}',
|
||||
'headers' => ['Content-Type' => 'application/json'],
|
||||
'timeout' => 10,
|
||||
],
|
||||
$options
|
||||
);
|
||||
}
|
||||
},
|
||||
];
|
||||
|
||||
// Test with form params.
|
||||
yield [
|
||||
'https://some.uri',
|
||||
['this will be' => 'encoded to form array'],
|
||||
'POST',
|
||||
['ignore_event_dispatch' => true],
|
||||
new class {
|
||||
/**
|
||||
* @param mixed[] $options
|
||||
*/
|
||||
public function assert(string $method, string $uri = '', array $options = []): void
|
||||
{
|
||||
Assert::assertSame('POST', $method);
|
||||
Assert::assertSame('https://some.uri', $uri);
|
||||
Assert::assertSame(
|
||||
[
|
||||
RequestOptions::FORM_PARAMS => ['this will be' => 'encoded to form array'],
|
||||
'headers' => [],
|
||||
'timeout' => 10,
|
||||
],
|
||||
$options
|
||||
);
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace Mautic\PluginBundle\Tests\Integration;
|
||||
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Mautic\CoreBundle\Helper\CacheStorageHelper;
|
||||
use Mautic\CoreBundle\Helper\EncryptionHelper;
|
||||
use Mautic\CoreBundle\Helper\PathsHelper;
|
||||
use Mautic\CoreBundle\Model\NotificationModel;
|
||||
use Mautic\LeadBundle\Field\FieldsWithUniqueIdentifier;
|
||||
use Mautic\LeadBundle\Model\CompanyModel;
|
||||
use Mautic\LeadBundle\Model\DoNotContact;
|
||||
use Mautic\LeadBundle\Model\FieldModel;
|
||||
use Mautic\LeadBundle\Model\LeadModel;
|
||||
use Mautic\PluginBundle\Model\IntegrationEntityModel;
|
||||
use Monolog\Logger;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
use Symfony\Component\Routing\Router;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
class AbstractIntegrationTestCase extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var EventDispatcherInterface&MockObject
|
||||
*/
|
||||
protected $dispatcher;
|
||||
|
||||
/**
|
||||
* @var CacheStorageHelper&MockObject
|
||||
*/
|
||||
protected $cache;
|
||||
|
||||
/**
|
||||
* @var EntityManager&MockObject
|
||||
*/
|
||||
protected $em;
|
||||
|
||||
/**
|
||||
* @var Session&MockObject
|
||||
*/
|
||||
protected $session;
|
||||
|
||||
/**
|
||||
* @var RequestStack&MockObject
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* @var Router&MockObject
|
||||
*/
|
||||
protected $router;
|
||||
|
||||
/**
|
||||
* @var TranslatorInterface&MockObject
|
||||
*/
|
||||
protected $translator;
|
||||
|
||||
/**
|
||||
* @var Logger&MockObject
|
||||
*/
|
||||
protected $logger;
|
||||
|
||||
/**
|
||||
* @var EncryptionHelper&MockObject
|
||||
*/
|
||||
protected $encryptionHelper;
|
||||
|
||||
/**
|
||||
* @var LeadModel&MockObject
|
||||
*/
|
||||
protected $leadModel;
|
||||
|
||||
/**
|
||||
* @var CompanyModel&MockObject
|
||||
*/
|
||||
protected $companyModel;
|
||||
|
||||
/**
|
||||
* @var PathsHelper&MockObject
|
||||
*/
|
||||
protected $pathsHelper;
|
||||
|
||||
/**
|
||||
* @var NotificationModel&MockObject
|
||||
*/
|
||||
protected $notificationModel;
|
||||
|
||||
/**
|
||||
* @var FieldModel&MockObject
|
||||
*/
|
||||
protected $fieldModel;
|
||||
|
||||
/**
|
||||
* @var IntegrationEntityModel&MockObject
|
||||
*/
|
||||
protected $integrationEntityModel;
|
||||
|
||||
/**
|
||||
* @var DoNotContact&MockObject
|
||||
*/
|
||||
protected $doNotContact;
|
||||
|
||||
/**
|
||||
* @var MockObject&FieldsWithUniqueIdentifier
|
||||
*/
|
||||
protected MockObject $fieldsWithUniqueIdentifier;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->dispatcher = $this->createMock(EventDispatcherInterface::class);
|
||||
$this->cache = $this->createMock(CacheStorageHelper::class);
|
||||
$this->em = $this->createMock(EntityManager::class);
|
||||
$this->session = $this->createMock(Session::class);
|
||||
$this->request = $this->createMock(RequestStack::class);
|
||||
$this->router = $this->createMock(Router::class);
|
||||
$this->translator = $this->createMock(TranslatorInterface::class);
|
||||
$this->logger = $this->createMock(Logger::class);
|
||||
$this->encryptionHelper = $this->createMock(EncryptionHelper::class);
|
||||
$this->leadModel = $this->createMock(LeadModel::class);
|
||||
$this->companyModel = $this->createMock(CompanyModel::class);
|
||||
$this->pathsHelper = $this->createMock(PathsHelper::class);
|
||||
$this->notificationModel = $this->createMock(NotificationModel::class);
|
||||
$this->fieldModel = $this->createMock(FieldModel::class);
|
||||
$this->integrationEntityModel = $this->createMock(IntegrationEntityModel::class);
|
||||
$this->doNotContact = $this->createMock(DoNotContact::class);
|
||||
$this->fieldsWithUniqueIdentifier = $this->createMock(FieldsWithUniqueIdentifier::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Mautic\PluginBundle\Tests\Integration;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
|
||||
class ClientFactory
|
||||
{
|
||||
private Client $httpClient;
|
||||
|
||||
public function __construct(Client $httpClient)
|
||||
{
|
||||
$this->httpClient = $httpClient;
|
||||
}
|
||||
|
||||
public function __invoke(): Client
|
||||
{
|
||||
return $this->httpClient;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user