17 class HashTest extends \PHPUnit\Framework\TestCase
22 private $configHashGeneratorMock;
27 private $dataConfigCollectorMock;
32 private $flagFactoryMock;
37 private $flagResourceMock;
54 $this->flagResourceMock = $this->getMockBuilder(FlagResource::class)
55 ->disableOriginalConstructor()
57 $this->flagFactoryMock = $this->getMockBuilder(FlagFactory::class)
58 ->disableOriginalConstructor()
60 $this->flagMock = $this->getMockBuilder(Flag::class)
61 ->disableOriginalConstructor()
63 $this->deploymentConfigMock = $this->getMockBuilder(DeploymentConfig::class)
64 ->disableOriginalConstructor()
66 $this->configHashGeneratorMock = $this->getMockBuilder(Generator::class)
67 ->disableOriginalConstructor()
69 $this->dataConfigCollectorMock = $this->getMockBuilder(DataCollector::class)
70 ->disableOriginalConstructor()
73 $this->hash =
new Hash(
74 $this->configHashGeneratorMock,
75 $this->dataConfigCollectorMock,
76 $this->flagResourceMock,
77 $this->flagFactoryMock
87 public function testGet($dataFromStorage, $expectedResult)
89 $this->flagMock->expects($this->once())
90 ->method(
'getFlagData')
91 ->willReturn($dataFromStorage);
92 $this->flagFactoryMock->expects($this->once())
95 ->willReturn($this->flagMock);
96 $this->flagResourceMock->expects($this->once())
101 $this->assertSame($expectedResult, $this->hash->get());
110 [[
'section' =>
'hash'], [
'section' =>
'hash']],
122 $section =
'section';
124 $fullConfig = [
'section' =>
$config];
126 $hashes = [$section => $hash];
128 $this->generalRegenerateMocks($fullConfig,
$config, $hash, $hashes);
130 $this->flagResourceMock->expects($this->once())
132 ->with($this->flagMock)
135 $this->hash->regenerate();
145 $section =
'section';
147 $fullConfig = [
'section' =>
$config];
149 $hashes = [$section => $hash];
151 $this->generalRegenerateMocks($fullConfig,
$config, $hash, $hashes, $section);
153 $this->flagResourceMock->expects($this->once())
155 ->with($this->flagMock)
156 ->willThrowException(
new \Exception(
'Some error'));
157 $this->hash->regenerate($section);
168 private function generalRegenerateMocks($fullConfig,
$config, $hash, $hashes, $sectionName =
null)
170 $this->dataConfigCollectorMock->expects($this->once())
171 ->method(
'getConfig')
173 ->willReturn($fullConfig);
174 $this->configHashGeneratorMock->expects($this->once())
178 $this->flagMock->expects($this->once())
179 ->method(
'setFlagData')
180 ->willReturn($hashes);
181 $this->flagFactoryMock->expects($this->exactly(2))
184 ->willReturn($this->flagMock);
185 $this->flagResourceMock->expects($this->exactly(2))
testGet($dataFromStorage, $expectedResult)
testRegenerateWithException()