ConnectorTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Analytics\Test\Unit\Model;
  7. use Magento\Analytics\Model\Connector;
  8. use Magento\Framework\ObjectManagerInterface;
  9. use Magento\Analytics\Model\Connector\SignUpCommand;
  10. class ConnectorTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @var ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
  14. */
  15. private $objectManagerMock;
  16. /**
  17. * @var Connector
  18. */
  19. private $connector;
  20. /**
  21. * @var SignUpCommand|\PHPUnit_Framework_MockObject_MockObject
  22. */
  23. private $signUpCommandMock;
  24. /**
  25. * @var array
  26. */
  27. private $commands;
  28. protected function setUp()
  29. {
  30. $this->objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class)
  31. ->disableOriginalConstructor()
  32. ->getMock();
  33. $this->signUpCommandMock = $this->getMockBuilder(SignUpCommand::class)
  34. ->disableOriginalConstructor()
  35. ->getMock();
  36. $this->commands = ['signUp' => SignUpCommand::class];
  37. $this->connector = new Connector($this->commands, $this->objectManagerMock);
  38. }
  39. public function testExecute()
  40. {
  41. $commandName = 'signUp';
  42. $this->objectManagerMock->expects($this->once())
  43. ->method('create')
  44. ->with($this->commands[$commandName])
  45. ->willReturn($this->signUpCommandMock);
  46. $this->signUpCommandMock->expects($this->once())
  47. ->method('execute')
  48. ->willReturn(true);
  49. $this->assertTrue($this->connector->execute($commandName));
  50. }
  51. /**
  52. * @expectedException \Magento\Framework\Exception\NotFoundException
  53. */
  54. public function testExecuteCommandNotFound()
  55. {
  56. $commandName = 'register';
  57. $this->connector->execute($commandName);
  58. }
  59. }