Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
StockTest Class Reference
Inheritance diagram for StockTest:

Public Member Functions

 testSetForm ()
 
 testSetValue ()
 
 testSetName ()
 

Data Fields

const ATTRIBUTE_NAME = 'quantity_and_stock_status'
 

Protected Member Functions

 setUp ()
 

Protected Attributes

 $_factoryElementMock
 
 $_collectionFactoryMock
 
 $_qtyMock
 
 $_factoryTextMock
 
 $_block
 

Detailed Description

@SuppressWarnings(PHPMD.LongVariable)

Definition at line 11 of file StockTest.php.

Member Function Documentation

◆ setUp()

setUp ( )
protected

Definition at line 40 of file StockTest.php.

41  {
42  $this->_factoryElementMock = $this->createMock(\Magento\Framework\Data\Form\Element\Factory::class);
43  $this->_collectionFactoryMock = $this->createMock(
44  \Magento\Framework\Data\Form\Element\CollectionFactory::class
45  );
46  $this->_qtyMock = $this->createPartialMock(
47  \Magento\Framework\Data\Form\Element\Text::class,
48  ['setForm', 'setValue', 'setName']
49  );
50  $this->_factoryTextMock = $this->createMock(\Magento\Framework\Data\Form\Element\TextFactory::class);
51 
52  $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
53  $this->_block = $objectManagerHelper->getObject(
54  \Magento\CatalogInventory\Block\Adminhtml\Form\Field\Stock::class,
55  [
56  'factoryElement' => $this->_factoryElementMock,
57  'factoryCollection' => $this->_collectionFactoryMock,
58  'factoryText' => $this->_factoryTextMock,
59  'data' => ['qty' => $this->_qtyMock, 'name' => self::ATTRIBUTE_NAME]
60  ]
61  );
62  }

◆ testSetForm()

testSetForm ( )

Definition at line 64 of file StockTest.php.

65  {
66  $this->_qtyMock->expects(
67  $this->once()
68  )->method(
69  'setForm'
70  )->with(
71  $this->isInstanceOf(\Magento\Framework\Data\Form\Element\AbstractElement::class)
72  );
73 
74  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
75  $this->_block->setForm(
76  $objectManager->getObject(
77  \Magento\Framework\Data\Form\Element\Text::class,
78  [
79  'factoryElement' => $this->_factoryElementMock,
80  'factoryCollection' => $this->_collectionFactoryMock
81  ]
82  )
83  );
84  }
$objectManager
Definition: bootstrap.php:17

◆ testSetName()

testSetName ( )

Definition at line 94 of file StockTest.php.

95  {
96  $this->_qtyMock->expects($this->once())->method('setName')->with(self::ATTRIBUTE_NAME . '[qty]');
97 
98  $this->_block->setName(self::ATTRIBUTE_NAME);
99  }

◆ testSetValue()

testSetValue ( )

Definition at line 86 of file StockTest.php.

87  {
88  $value = ['qty' => 1, 'is_in_stock' => 0];
89  $this->_qtyMock->expects($this->once())->method('setValue')->with($this->equalTo(1));
90 
91  $this->_block->setValue($value);
92  }
$value
Definition: gender.phtml:16

Field Documentation

◆ $_block

$_block
protected

Definition at line 38 of file StockTest.php.

◆ $_collectionFactoryMock

$_collectionFactoryMock
protected

Definition at line 23 of file StockTest.php.

◆ $_factoryElementMock

$_factoryElementMock
protected

Definition at line 18 of file StockTest.php.

◆ $_factoryTextMock

$_factoryTextMock
protected

Definition at line 33 of file StockTest.php.

◆ $_qtyMock

$_qtyMock
protected

Definition at line 28 of file StockTest.php.

◆ ATTRIBUTE_NAME

const ATTRIBUTE_NAME = 'quantity_and_stock_status'

Definition at line 13 of file StockTest.php.


The documentation for this class was generated from the following file: