Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
UpdateCommandTest.php
Go to the documentation of this file.
1 <?php
7 
14 use Psr\Log\LoggerInterface;
17 
18 class UpdateCommandTest extends \PHPUnit\Framework\TestCase
19 {
23  private $updateCommand;
24 
28  private $analyticsTokenMock;
29 
33  private $httpClientMock;
34 
38  public $configMock;
39 
43  private $loggerMock;
44 
48  private $flagManagerMock;
49 
53  private $responseResolverMock;
54 
55  protected function setUp()
56  {
57  $this->analyticsTokenMock = $this->getMockBuilder(AnalyticsToken::class)
58  ->disableOriginalConstructor()
59  ->getMock();
60 
61  $this->httpClientMock = $this->getMockBuilder(ClientInterface::class)
62  ->disableOriginalConstructor()
63  ->getMock();
64 
65  $this->configMock = $this->getMockBuilder(ScopeConfigInterface::class)
66  ->disableOriginalConstructor()
67  ->getMock();
68 
69  $this->loggerMock = $this->getMockBuilder(LoggerInterface::class)
70  ->disableOriginalConstructor()
71  ->getMock();
72 
73  $this->flagManagerMock = $this->getMockBuilder(FlagManager::class)
74  ->disableOriginalConstructor()
75  ->getMock();
76 
77  $this->responseResolverMock = $this->getMockBuilder(ResponseResolver::class)
78  ->disableOriginalConstructor()
79  ->getMock();
80 
81  $this->updateCommand = new UpdateCommand(
82  $this->analyticsTokenMock,
83  $this->httpClientMock,
84  $this->configMock,
85  $this->loggerMock,
86  $this->flagManagerMock,
87  $this->responseResolverMock
88  );
89  }
90 
91  public function testExecuteSuccess()
92  {
93  $url = "old.localhost.com";
94  $configVal = "Config val";
95  $token = "Secret token!";
96  $this->analyticsTokenMock->expects($this->once())
97  ->method('isTokenExist')
98  ->willReturn(true);
99 
100  $this->configMock->expects($this->any())
101  ->method('getValue')
102  ->willReturn($configVal);
103 
104  $this->flagManagerMock->expects($this->once())
105  ->method('getFlagData')
107  ->willReturn($url);
108 
109  $this->analyticsTokenMock->expects($this->once())
110  ->method('getToken')
111  ->willReturn($token);
112 
113  $this->httpClientMock->expects($this->once())
114  ->method('request')
115  ->with(
117  $configVal,
118  [
119  'url' => $url,
120  'new-url' => $configVal,
121  'access-token' => $token
122  ]
123  )->willReturn(new \Zend_Http_Response(200, []));
124 
125  $this->responseResolverMock->expects($this->once())
126  ->method('getResult')
127  ->willReturn(true);
128 
129  $this->assertTrue($this->updateCommand->execute());
130  }
131 
132  public function testExecuteWithoutToken()
133  {
134  $this->analyticsTokenMock->expects($this->once())
135  ->method('isTokenExist')
136  ->willReturn(false);
137 
138  $this->assertFalse($this->updateCommand->execute());
139  }
140 }