Skip to content

Commit 3cfd10d

Browse files
author
Bohdan Korablov
committed
MAGETWO-64602: Sync config file with DB: Validation
1 parent 420cfb6 commit 3cfd10d

File tree

3 files changed

+145
-1
lines changed

3 files changed

+145
-1
lines changed

app/code/Magento/Deploy/Test/Unit/Console/Command/App/ConfigImport/ImporterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
namespace Magento\Deploy\Test\Unit\Model\DeploymentConfig;
6+
namespace Magento\Deploy\Test\Unit\Console\Command\App\ConfigImport;
77

88
use Magento\Framework\App\DeploymentConfig\ImporterInterface;
99
use Magento\Framework\App\DeploymentConfig;
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Deploy\Test\Unit\Model\DeploymentConfig\Hash;
7+
8+
use Magento\Deploy\Model\DeploymentConfig\Hash\Generator;
9+
use Magento\Framework\Serialize\SerializerInterface;
10+
11+
class GeneratorTest extends \PHPUnit_Framework_TestCase
12+
{
13+
/**
14+
* @var SerializerInterface|\PHPUnit_Framework_MockObject_MockObject
15+
*/
16+
private $serializerMock;
17+
18+
/**
19+
* @var Generator
20+
*/
21+
private $generator;
22+
23+
/**
24+
* @return void
25+
*/
26+
protected function setUp()
27+
{
28+
$this->serializerMock = $this->getMockBuilder(SerializerInterface::class)
29+
->getMockForAbstractClass();
30+
31+
$this->generator = new Generator($this->serializerMock);
32+
}
33+
34+
/**
35+
* @return void
36+
*/
37+
public function testGenerate()
38+
{
39+
$data = 'some config';
40+
$serializedData = 'serialized content';
41+
$hash = '40c185113eb5154ad9aa5a8854f197c818e17f62';
42+
43+
$this->serializerMock->expects($this->once())
44+
->method('serialize')
45+
->with($data)
46+
->willReturn($serializedData);
47+
48+
$this->assertSame($hash, $this->generator->generate($data));
49+
}
50+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Deploy\Test\Unit\Model\DeploymentConfig;
7+
8+
use Magento\Deploy\Model\DeploymentConfig\Hash\Generator as HashGenerator;
9+
use Magento\Deploy\Model\DeploymentConfig\Hash;
10+
use Magento\Deploy\Model\DeploymentConfig\DataCollector;
11+
use Magento\Deploy\Model\DeploymentConfig\Validator;
12+
13+
class ValidatorTest extends \PHPUnit_Framework_TestCase
14+
{
15+
/**
16+
* @var Hash|\PHPUnit_Framework_MockObject_MockObject
17+
*/
18+
private $configHashMock;
19+
20+
/**
21+
* @var HashGenerator|\PHPUnit_Framework_MockObject_MockObject
22+
*/
23+
private $hashGeneratorMock;
24+
25+
/**
26+
* @var DataCollector|\PHPUnit_Framework_MockObject_MockObject
27+
*/
28+
private $dataConfigCollectorMock;
29+
30+
/**
31+
* @var Validator
32+
*/
33+
private $validator;
34+
35+
/**
36+
* @return void
37+
*/
38+
protected function setUp()
39+
{
40+
$this->configHashMock = $this->getMockBuilder(Hash::class)
41+
->disableOriginalConstructor()
42+
->getMock();
43+
$this->hashGeneratorMock = $this->getMockBuilder(HashGenerator::class)
44+
->disableOriginalConstructor()
45+
->getMock();
46+
$this->dataConfigCollectorMock = $this->getMockBuilder(DataCollector::class)
47+
->disableOriginalConstructor()
48+
->getMock();
49+
50+
$this->validator = new Validator(
51+
$this->configHashMock,
52+
$this->hashGeneratorMock,
53+
$this->dataConfigCollectorMock
54+
);
55+
}
56+
57+
/**
58+
* @param string $configData
59+
* @param string $generatedHash
60+
* @param string $savedHash
61+
* @param bool $expectedResult
62+
* @return void
63+
* @dataProvider isValidDataProvider
64+
*/
65+
public function testIsValid($configData, $generatedHash, $savedHash, $expectedResult)
66+
{
67+
$this->dataConfigCollectorMock->expects($this->once())
68+
->method('getConfig')
69+
->willReturn($configData);
70+
$this->hashGeneratorMock->expects($this->any())
71+
->method('generate')
72+
->with($configData)
73+
->willReturn($generatedHash);
74+
$this->configHashMock->expects($this->any())
75+
->method('get')
76+
->willReturn($savedHash);
77+
78+
$this->assertSame($expectedResult, $this->validator->isValid());
79+
}
80+
81+
/**
82+
* @return array
83+
*/
84+
public function isValidDataProvider()
85+
{
86+
return [
87+
['configData' => 'some data', 'generatedHash' => '123', 'savedHash' => '123', 'expectedResult' => true],
88+
['configData' => 'some data', 'generatedHash' => '321', 'savedHash' => '123', 'expectedResult' => false],
89+
['configData' => 'some data', 'generatedHash' => '321', 'savedHash' => null, 'expectedResult' => false],
90+
['configData' => null, 'generatedHash' => '321', 'savedHash' => '123', 'expectedResult' => true],
91+
['configData' => null, 'generatedHash' => '321', 'savedHash' => null, 'expectedResult' => true],
92+
];
93+
}
94+
}

0 commit comments

Comments
 (0)