ExchangeRepositoryTest.php 1.79 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace Magento\Framework\MessageQueue\Test\Unit\Bulk;

/**
 * Unit test for ExchangeRepository.
 */
class ExchangeRepositoryTest extends \PHPUnit\Framework\TestCase
{
    /**
     * @var \Magento\Framework\MessageQueue\Bulk\ExchangeFactoryInterface|\PHPUnit_Framework_MockObject_MockObject
     */
    private $exchangeFactory;

    /**
     * @var \Magento\Framework\MessageQueue\Bulk\ExchangeRepository
     */
    private $exchangeRepository;

    /**
     * Set up.
     *
     * @return void
     */
    protected function setUp()
    {
        $this->exchangeFactory = $this
            ->getMockBuilder(\Magento\Framework\MessageQueue\Bulk\ExchangeFactoryInterface::class)
            ->disableOriginalConstructor()->getMock();

        $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
        $this->exchangeRepository = $objectManager->getObject(
            \Magento\Framework\MessageQueue\Bulk\ExchangeRepository::class
        );
        $objectManager->setBackwardCompatibleProperty(
            $this->exchangeRepository,
            'exchangeFactory',
            $this->exchangeFactory
        );
    }

    /**
     * Test for getByConnectionName method.
     *
     * @return void
     */
    public function testGetByConnectionName()
    {
        $connectionName = 'amqp';
        $exchange = $this
            ->getMockBuilder(\Magento\Framework\Amqp\Bulk\Exchange::class)
            ->disableOriginalConstructor()->getMock();
        $this->exchangeFactory->expects($this->once())->method('create')->with($connectionName)->willReturn($exchange);
        $this->assertEquals($exchange, $this->exchangeRepository->getByConnectionName($connectionName));
    }
}