Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CatalogAttributeDeleteAfterObserverTest.php
Go to the documentation of this file.
1 <?php
7 
8 class CatalogAttributeDeleteAfterObserverTest extends \PHPUnit\Framework\TestCase
9 {
13  protected $model;
14 
19 
20  protected function setUp()
21  {
22  $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
23  $this->initMocks();
24 
25  $this->model = $helper->getObject(
26  \Magento\SalesRule\Observer\CatalogAttributeDeleteAfterObserver::class,
27  [
28  'checkSalesRulesAvailability' => $this->checkSalesRulesAvailability
29  ]
30  );
31  }
32 
33  protected function initMocks()
34  {
35  $this->checkSalesRulesAvailability = $this->createMock(
36  \Magento\SalesRule\Observer\CheckSalesRulesAvailability::class
37  );
38  }
39 
41  {
42  $attributeCode = 'attributeCode';
43  $observer = $this->createMock(\Magento\Framework\Event\Observer::class);
44  $event = $this->createPartialMock(\Magento\Framework\Event::class, ['getAttribute', '__wakeup']);
45  $attribute = $this->createPartialMock(
46  \Magento\Catalog\Model\ResourceModel\Eav\Attribute::class,
47  ['dataHasChangedFor', 'getIsUsedForPromoRules', 'getAttributeCode', '__wakeup']
48  );
49 
50  $observer->expects($this->once())
51  ->method('getEvent')
52  ->will($this->returnValue($event));
53  $event->expects($this->any())
54  ->method('getAttribute')
55  ->will($this->returnValue($attribute));
56  $attribute->expects($this->any())
57  ->method('getIsUsedForPromoRules')
58  ->will($this->returnValue(true));
59  $attribute->expects($this->any())
60  ->method('getAttributeCode')
61  ->will($this->returnValue($attributeCode));
62 
63  $this->checkSalesRulesAvailability
64  ->expects($this->once())
65  ->method('checkSalesRulesAvailability')
66  ->willReturn('true');
67 
68  $this->assertEquals($this->model, $this->model->execute($observer));
69  }
70 }
$helper
Definition: iframe.phtml:13
$attributeCode
Definition: extend.phtml:12