Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CaseRescoreTest.php
Go to the documentation of this file.
1 <?php
7 
12 use PHPUnit_Framework_MockObject_MockObject as MockObject;
13 
19 class CaseRescoreTest extends \PHPUnit\Framework\TestCase
20 {
21  private static $data = [
22  'caseId' => 100,
23  'score' => 200
24  ];
25 
29  private $objectManager;
30 
34  private $caseRepository;
35 
39  private $caseRescore;
40 
44  private $case;
45 
49  protected function setUp()
50  {
51  $this->case = $this->getMockBuilder(CaseInterface::class)
52  ->disableOriginalConstructor()
53  ->getMock();
54  $this->objectManager = new ObjectManager($this);
55  $this->caseRepository = $this->getMockBuilder(CaseRepositoryInterface::class)
56  ->disableOriginalConstructor()
57  ->getMock();
58 
59  $this->caseRescore = $this->objectManager->getObject(CaseRescore::class, [
60  'caseRepository' => $this->caseRepository
61  ]);
62  }
63 
71  {
72  $this->caseRescore->generate([]);
73  }
74 
82  {
83  $this->caseRepository->expects($this->once())
84  ->method('getByCaseId')
85  ->with(self::$data['caseId'])
86  ->willReturn(null);
87 
88  $this->caseRescore = $this->objectManager->getObject(CaseRescore::class, [
89  'caseRepository' => $this->caseRepository
90  ]);
91 
92  $this->caseRescore->generate(self::$data);
93  }
94 
99  {
100  $this->case->expects($this->once())
101  ->method('getScore')
102  ->willReturn(self::$data['score']);
103 
104  $this->caseRepository->expects($this->once())
105  ->method('getByCaseId')
106  ->with(self::$data['caseId'])
107  ->willReturn($this->case);
108 
109  $this->caseRescore = $this->objectManager->getObject(CaseRescore::class, [
110  'caseRepository' => $this->caseRepository
111  ]);
112 
113  $phrase = __(
114  'Case Update: New score for the order is %1. Previous score was %2.',
115  self::$data['score'],
116  self::$data['score']
117  );
118 
119  $message = $this->caseRescore->generate(self::$data);
120 
121  $this->assertEquals($phrase, $message);
122  }
123 
128  {
129  $this->caseRepository->expects($this->once())
130  ->method('getByCaseId')
131  ->with(self::$data['caseId'])
132  ->willReturn($this->case);
133 
134  $this->caseRescore = $this->objectManager->getObject(CaseRescore::class, [
135  'caseRepository' => $this->caseRepository
136  ]);
137 
138  $phrase = __(
139  'Case Update: New score for the order is %1. Previous score was %2.',
140  self::$data['score'],
141  null
142  );
143 
144  $message = $this->caseRescore->generate(self::$data);
145 
146  $this->assertEquals($phrase, $message);
147  }
148 }
__()
Definition: __.php:13
$message