Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MysqlFactoryTest.php
Go to the documentation of this file.
1 <?php
7 
14 
15 class MysqlFactoryTest extends \PHPUnit\Framework\TestCase
16 {
20  private $selectFactoryMock;
21 
25  private $loggerMock;
26 
30  private $objectManagerMock;
31 
35  private $mysqlFactory;
36 
37  protected function setUp()
38  {
39  $objectManager = new ObjectManager($this);
40  $this->objectManagerMock = $this->createMock(ObjectManagerInterface::class);
41  $this->mysqlFactory = $objectManager->getObject(
42  MysqlFactory::class,
43  [
44  'objectManager' => $this->objectManagerMock
45  ]
46  );
47  }
48 
56  public function testCreate(
57  array $objectManagerArguments,
58  array $config,
59  LoggerInterface $logger = null,
60  SelectFactory $selectFactory = null
61  ) {
62  $this->objectManagerMock->expects($this->once())
63  ->method('create')
64  ->with(
65  Mysql::class,
66  $objectManagerArguments
67  );
68  $this->mysqlFactory->create(
69  Mysql::class,
70  $config,
71  $logger,
72  $selectFactory
73  );
74  }
75 
79  public function createDataProvider()
80  {
81  $this->loggerMock = $this->getMockForAbstractClass(LoggerInterface::class);
82  $this->selectFactoryMock = $this->createMock(SelectFactory::class);
83  return [
84  [
85  [
86  'config' => ['foo' => 'bar'],
87  'logger' => $this->loggerMock,
88  'selectFactory' => $this->selectFactoryMock
89  ],
90  ['foo' => 'bar'],
91  $this->loggerMock,
92  $this->selectFactoryMock
93  ],
94  [
95  [
96  'config' => ['foo' => 'bar'],
97  'logger' => $this->loggerMock
98  ],
99  ['foo' => 'bar'],
100  $this->loggerMock,
101  null
102  ],
103  [
104  [
105  'config' => ['foo' => 'bar'],
106  'selectFactory' => $this->selectFactoryMock
107  ],
108  ['foo' => 'bar'],
109  null,
110  $this->selectFactoryMock
111  ],
112  ];
113  }
114 
119  public function testCreateInvalidClass()
120  {
121  $this->mysqlFactory->create(
122  \stdClass::class,
123  []
124  );
125  }
126 }
$objectManager
Definition: bootstrap.php:17
$config
Definition: fraud_order.php:17
$logger
testCreate(array $objectManagerArguments, array $config, LoggerInterface $logger=null, SelectFactory $selectFactory=null)