Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ConsumerInstanceTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class ConsumerInstanceTest extends \PHPUnit\Framework\TestCase
11 {
15  private $validator;
16 
20  protected function setUp()
21  {
22  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
23  $this->validator = $objectManager->getObject(ConsumerInstanceValidator::class);
24  }
25 
30  public function testValidateValid($configData)
31  {
32  $this->validator->validate($configData);
33  }
34 
38  public function validConfigDataProvider()
39  {
40  return [
41  'valid' => [
42  [
43  'consumer1' => [
44  'name' => 'consumer1',
45  'queue' => 'queue1',
46  'consumerInstance' => \Magento\Framework\MessageQueue\BatchConsumer::class,
47  'handlers' => [
48  ['type' => 'handlerClassOne', 'method' => 'handlerMethodOne'],
49  ['type' => 'handlerClassTwo', 'method' => 'handlerMethodTwo'],
50  ],
51  'connection' => 'connection1',
52  'maxMessages' => '100',
53  ]
54  ]
55  ]
56  ];
57  }
58 
64  public function testValidateInvalid($configData, $expectedExceptionMessage)
65  {
66  $this->expectException('\LogicException');
67  $this->expectExceptionMessage($expectedExceptionMessage);
68  $this->validator->validate($configData);
69  }
70 
74  public function invalidConfigDataProvider()
75  {
76  return [
77  'invalid, consumerInstance not implementing consumer interface' => [
78  [
79  'consumer1' => [
80  'name' => 'consumer1',
81  'queue' => 'queue1',
82  'consumerInstance' => ConsumerInstanceTest::class,
83  'handlers' => [['type' => 'handlerClassOne', 'method' => 'handlerMethodOne']],
84  'connection' => 'connection1',
85  'maxMessages' => '100',
86  ]
87  ],
88  // @codingStandardsIgnoreStart
89  "'Magento\\Framework\\MessageQueue\\Test\\Unit\\Consumer\\Config\\Validator\\ConsumerInstanceTest'"
90  . " cannot be specified as 'consumerInstance' for 'consumer1' consumer, unless it implements"
91  . " 'Magento\\Framework\\MessageQueue\\ConsumerInterface' interface"
92  // @codingStandardsIgnoreEnd
93  ],
94  'invalid, consumerInstance class does not exist' => [
95  [
96  'consumer1' => [
97  'name' => 'consumer1',
98  'queue' => 'queue1',
99  'consumerInstance' => 'consumerClass1',
100  'handlers' => [
101  [['type' => 'handlerClassOne', 'method' => 'handlerMethodOne']]
102  ],
103  'connection' => 'connection1',
104  'maxMessages' => '100',
105  ]
106  ],
107  "'consumerClass1' does not exist and thus cannot be used as 'consumerInstance'"
108  . " for 'consumer1' consumer."
109  ]
110  ];
111  }
112 }
$objectManager
Definition: bootstrap.php:17