Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CaptchaFactoryTest.php
Go to the documentation of this file.
1 <?php
7 
8 class CaptchaFactoryTest extends \PHPUnit\Framework\TestCase
9 {
12 
14  protected $_model;
15 
16  protected function setUp()
17  {
18  $this->_objectManagerMock = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
19  $this->_model = new \Magento\Captcha\Model\CaptchaFactory($this->_objectManagerMock);
20  }
21 
22  public function testCreatePositive()
23  {
24  $captchaType = 'default';
25 
26  $defaultCaptchaMock = $this->createMock(\Magento\Captcha\Model\DefaultModel::class);
27 
28  $this->_objectManagerMock->expects(
29  $this->once()
30  )->method(
31  'create'
32  )->with(
33  $this->equalTo('Magento\Captcha\Model\\' . ucfirst($captchaType))
34  )->will(
35  $this->returnValue($defaultCaptchaMock)
36  );
37 
38  $this->assertEquals($defaultCaptchaMock, $this->_model->create($captchaType, 'form_id'));
39  }
40 
41  public function testCreateNegative()
42  {
43  $captchaType = 'wrong_instance';
44 
45  $defaultCaptchaMock = $this->createMock(\stdClass::class);
46 
47  $this->_objectManagerMock->expects(
48  $this->once()
49  )->method(
50  'create'
51  )->with(
52  $this->equalTo('Magento\Captcha\Model\\' . ucfirst($captchaType))
53  )->will(
54  $this->returnValue($defaultCaptchaMock)
55  );
56 
57  $this->expectException('InvalidArgumentException');
58  $this->expectExceptionMessage('Magento\Captcha\Model\\' . ucfirst($captchaType) .
59  ' does not implement \Magento\Captcha\Model\CaptchaInterface');
60 
61  $this->assertEquals($defaultCaptchaMock, $this->_model->create($captchaType, 'form_id'));
62  }
63 }