123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- declare(strict_types=1);
- namespace Magento\Framework\Amqp\Test\Unit\Connection;
- use Magento\Framework\Amqp\Connection\Factory;
- use Magento\Framework\Amqp\Connection\FactoryOptions;
- use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
- use PhpAmqpLib\Connection\AMQPSSLConnection;
- use PhpAmqpLib\Connection\AMQPStreamConnection;
- /**
- * Tests \Magento\Framework\Amqp\Connection\Factory.
- */
- class FactoryTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * @var Factory
- */
- private $object;
- /**
- * @var ObjectManager
- */
- private $objectManager;
- /**
- * @var \Magento\Framework\App\ObjectManager
- */
- private $objectManagerInterface;
- /**
- * @var FactoryOptions|\PHPUnit_Framework_MockObject_MockObject
- */
- private $optionsMock;
- /**
- * @inheritdoc
- */
- protected function setUp()
- {
- $this->objectManager = new ObjectManager($this);
- $className = \Magento\Framework\ObjectManagerInterface::class;
- $this->objectManagerInterface = $this->createMock($className);
- $this->optionsMock = $this->getMockBuilder(FactoryOptions::class)
- ->disableOriginalConstructor()
- ->setMethods(
- [
- 'isSslEnabled',
- 'getHost',
- 'getPort',
- 'getUsername',
- 'getPassword',
- 'getVirtualHost',
- 'getSslOptions',
- ]
- )
- ->getMock();
- $this->object = $this->objectManager->getObject(Factory::class);
- }
- /**
- * @param bool $sslEnabled
- * @param string $connectionClass
- * @return void
- * @dataProvider connectionDataProvider
- */
- public function testSSLConnection($sslEnabled, $connectionClass)
- {
- $this->optionsMock->expects($this->exactly(2))
- ->method('isSslEnabled')
- ->willReturn($sslEnabled);
- $this->optionsMock->expects($this->once())
- ->method('getHost')
- ->willReturn('127.0.0.1');
- $this->optionsMock->expects($this->once())
- ->method('getPort')
- ->willReturn('5672');
- $this->optionsMock->expects($this->once())
- ->method('getUsername')
- ->willReturn('guest');
- $this->optionsMock->expects($this->once())
- ->method('getPassword')
- ->willReturn('guest');
- $this->optionsMock->expects($this->exactly(2))
- ->method('getVirtualHost')
- ->willReturn('/');
- $this->optionsMock->expects($this->any())
- ->method('getSslOptions')
- ->willReturn(null);
- $this->objectManagerInterface->expects($this->any())
- ->method('create')
- ->with($connectionClass)
- ->willReturn($this->createMock($connectionClass));
- \Magento\Framework\App\ObjectManager::setInstance($this->objectManagerInterface);
- $connection = $this->object->create($this->optionsMock);
- $this->assertInstanceOf($connectionClass, $connection);
- }
- /**
- * @return array
- */
- public function connectionDataProvider()
- {
- return [
- [
- 'ssl_enabled' => true,
- 'connection_class' => AMQPSSLConnection::class,
- ],
- [
- 'ssl_enabled' => false,
- 'connection_class' => AMQPStreamConnection::class,
- ],
- ];
- }
- protected function tearDown()
- {
- $this->objectManager->setBackwardCompatibleProperty(
- null,
- '_instance',
- null,
- \Magento\Framework\App\ObjectManager::class
- );
- }
- }
|