30 private $connectionMock;
40 private $metadataPoolMock;
46 $this->resource = $this->getMockBuilder(\
Magento\Framework\
App\ResourceConnection::class)
47 ->disableOriginalConstructor()
50 $this->connectionMock = $this->getMockBuilder(\
Magento\Framework\DB\Adapter\AdapterInterface::class)
51 ->setMethods([
'select',
'fetchOne'])
52 ->disableOriginalConstructor()
53 ->getMockForAbstractClass();
55 $this->select = $this->getMockBuilder(\
Magento\Framework\DB\Select::class)
56 ->setMethods([
'reset',
'from',
'join',
'where',
'group',
'limit'])
57 ->disableOriginalConstructor()
60 $this->metadataPoolMock = $this->getMockBuilder(MetadataPool::class)
61 ->disableOriginalConstructor()
64 $this->metadataPoolMock->expects(self::once())
65 ->method(
'getMetadata')
66 ->with(ProductInterface::class)
67 ->willReturn($this->getMetaDataMock());
69 $this->model =
$helper->getObject(
72 'resource' => $this->resource
75 $refClass = new \ReflectionClass(LockValidator::class);
76 $refProperty = $refClass->getProperty(
'metadataPool');
77 $refProperty->setAccessible(
true);
78 $refProperty->setValue($this->model, $this->metadataPoolMock);
83 $this->validate(
false);
89 private function getMetaDataMock()
91 $metadata = $this->getMockBuilder(EntityMetadata::class)
92 ->disableOriginalConstructor()
95 $metadata->expects(self::once())
96 ->method(
'getLinkField')
97 ->willReturn(
'entity_id');
108 $this->validate(
true);
115 public function validate($exception)
117 $attrTable =
'someAttributeTable';
118 $productTable =
'someProductTable';
122 $bind = [
'attribute_id' => $attributeId,
'attribute_set_id' =>
$attributeSet];
125 $object = $this->getMockBuilder(\
Magento\Framework\Model\AbstractModel::class)
126 ->setMethods([
'getAttributeId',
'__wakeup'])
127 ->disableOriginalConstructor()
129 $object->expects($this->once())->method(
'getAttributeId')->will($this->returnValue($attributeId));
131 $this->resource->expects($this->once())->method(
'getConnection')
132 ->will($this->returnValue($this->connectionMock));
133 $this->resource->expects($this->at(1))->method(
'getTableName')
134 ->with($this->equalTo(
'catalog_product_super_attribute'))
135 ->will($this->returnValue($attrTable));
136 $this->resource->expects($this->at(2))->method(
'getTableName')
137 ->with($this->equalTo(
'catalog_product_entity'))
138 ->will($this->returnValue($productTable));
140 $this->connectionMock->expects($this->once())->method(
'select')
141 ->will($this->returnValue($this->select));
142 $this->connectionMock->expects($this->once())->method(
'fetchOne')
143 ->with($this->equalTo($this->select), $this->equalTo($bind))
144 ->will($this->returnValue($exception));
146 $this->select->expects($this->once())->method(
'reset')
147 ->will($this->returnValue($this->select));
148 $this->select->expects($this->once())->method(
'from')
150 $this->equalTo([
'main_table' => $attrTable]),
151 $this->equalTo([
'psa_count' =>
'COUNT(product_super_attribute_id)'])
153 ->will($this->returnValue($this->select));
154 $this->select->expects($this->once())->method(
'join')
156 $this->equalTo([
'entity' => $productTable]),
157 $this->equalTo(
'main_table.product_id = entity.entity_id')
159 ->will($this->returnValue($this->select));
160 $this->select->expects($this->any())->method(
'where')
161 ->will($this->returnValue($this->select));
162 $this->select->expects($this->once())->method(
'group')
163 ->with($this->equalTo(
'main_table.attribute_id'))
164 ->will($this->returnValue($this->select));
165 $this->select->expects($this->once())->method(
'limit')
166 ->with($this->equalTo(1))
167 ->will($this->returnValue($this->select));