Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
GroupRegistryTest.php
Go to the documentation of this file.
1 <?php
7 
11 class GroupRegistryTest extends \PHPUnit\Framework\TestCase
12 {
16  private $unit;
17 
21  private $groupFactory;
22 
23  protected function setUp()
24  {
25  $this->groupFactory = $this->getMockBuilder(\Magento\Customer\Model\GroupFactory::class)
26  ->disableOriginalConstructor()
27  ->setMethods(['create'])
28  ->getMock();
29  $this->unit = new \Magento\Customer\Model\GroupRegistry($this->groupFactory);
30  }
31 
37  public function testRetrieve()
38  {
39  $groupId = 1;
40  $group = $this->getMockBuilder(\Magento\Customer\Model\Group::class)
41  ->setMethods(['load', 'getId', '__wakeup'])
42  ->disableOriginalConstructor()
43  ->getMock();
44  $group->expects($this->once())
45  ->method('load')
46  ->with($groupId)
47  ->will($this->returnValue($group));
48  $group->expects($this->exactly(2))
49  ->method('getId')
50  ->will($this->returnValue($groupId));
51  $this->groupFactory->expects($this->once())
52  ->method('create')
53  ->will($this->returnValue($group));
54  $actual = $this->unit->retrieve($groupId);
55  $this->assertEquals($group, $actual);
56  $actualCached = $this->unit->retrieve($groupId);
57  $this->assertSame($group, $actualCached);
58  }
59 
66  public function testRetrieveException()
67  {
68  $groupId = 1;
69  $group = $this->getMockBuilder(\Magento\Customer\Model\Group::class)
70  ->setMethods(['load', 'getId', '__wakeup'])
71  ->disableOriginalConstructor()
72  ->getMock();
73  $group->expects($this->once())
74  ->method('load')
75  ->with($groupId)
76  ->will($this->returnValue($group));
77  $group->expects($this->once())
78  ->method('getId')
79  ->will($this->returnValue(null));
80  $this->groupFactory->expects($this->once())
81  ->method('create')
82  ->will($this->returnValue($group));
83  $this->unit->retrieve($groupId);
84  }
85 
91  public function testRemove()
92  {
93  $groupId = 1;
94  $group = $this->getMockBuilder(\Magento\Customer\Model\Group::class)
95  ->disableOriginalConstructor()
96  ->setMethods(['load', 'getId', '__wakeup'])
97  ->getMock();
98  $group->expects($this->exactly(2))
99  ->method('load')
100  ->with($groupId)
101  ->will($this->returnValue($group));
102  $group->expects($this->exactly(4))
103  ->method('getId')
104  ->will($this->returnValue($groupId));
105  $this->groupFactory->expects($this->exactly(2))
106  ->method('create')
107  ->will($this->returnValue($group));
108  $actual = $this->unit->retrieve($groupId);
109  $this->assertSame($group, $actual);
110  $this->unit->remove($groupId);
111  $actual = $this->unit->retrieve($groupId);
112  $this->assertSame($group, $actual);
113  }
114 }
$group
Definition: sections.phtml:16