1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of Phiremock. |
4
|
|
|
* |
5
|
|
|
* Phiremock is free software: you can redistribute it and/or modify |
6
|
|
|
* it under the terms of the GNU Lesser General Public License as published by |
7
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
8
|
|
|
* (at your option) any later version. |
9
|
|
|
* |
10
|
|
|
* Phiremock is distributed in the hope that it will be useful, |
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13
|
|
|
* GNU General Public License for more details. |
14
|
|
|
* |
15
|
|
|
* You should have received a copy of the GNU General Public License |
16
|
|
|
* along with Phiremock. If not, see <http://www.gnu.org/licenses/>. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace Mcustiel\Phiremock\Server\Actions; |
20
|
|
|
|
21
|
|
|
use Mcustiel\Phiremock\Server\Model\ExpectationStorage; |
22
|
|
|
use Psr\Http\Message\ResponseInterface; |
23
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
24
|
|
|
use Psr\Log\LoggerInterface; |
25
|
|
|
|
26
|
|
|
class ReloadPreconfiguredExpectationsAction implements ActionInterface |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var ExpectationStorage |
30
|
|
|
*/ |
31
|
|
|
private $expectationStorage; |
32
|
|
|
/** |
33
|
|
|
* @var ExpectationStorage |
34
|
|
|
*/ |
35
|
|
|
private $expectationBackup; |
36
|
|
|
/** |
37
|
|
|
* @var LoggerInterface |
38
|
|
|
*/ |
39
|
|
|
private $logger; |
40
|
|
|
|
41
|
|
|
public function __construct( |
42
|
|
|
ExpectationStorage $expectationStorage, |
43
|
|
|
ExpectationStorage $expectationBackup, |
44
|
|
|
LoggerInterface $logger |
45
|
|
|
) { |
46
|
|
|
$this->expectationStorage = $expectationStorage; |
47
|
|
|
$this->expectationBackup = $expectationBackup; |
48
|
|
|
$this->logger = $logger; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function execute(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface |
52
|
|
|
{ |
53
|
|
|
$this->expectationStorage->clearExpectations(); |
54
|
|
|
foreach ($this->expectationBackup->listExpectations() as $expectation) { |
55
|
|
|
$this->expectationStorage->addExpectation($expectation); |
56
|
|
|
} |
57
|
|
|
$this->logger->debug('Pre-defined expectations are restored, scenarios and requests history are cleared.'); |
58
|
|
|
|
59
|
|
|
return $response->withStatus(200); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|