Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CryptKeyGeneratorTest.php
Go to the documentation of this file.
1 <?php
2 /***
3  * Copyright © Magento, Inc. All rights reserved.
4  * See COPYING.txt for license details.
5  */
6 
8 
11 use PHPUnit\Framework\TestCase;
12 
16 class CryptKeyGeneratorTest extends TestCase
17 {
21  private $randomMock;
22 
26  private $cryptKeyGenerator;
27 
28  public function setUp()
29  {
30  $this->randomMock = $this->getMockBuilder(Random::class)
31  ->disableOriginalConstructor()
32  ->getMock();
33 
34  $this->cryptKeyGenerator = new CryptKeyGenerator($this->randomMock);
35  }
36 
38  {
39  $this->randomMock
40  ->expects($this->once())
41  ->method('getRandomString')
42  ->willReturn('');
43 
44  $this->cryptKeyGenerator->generate();
45  }
46 
47  public function testReturnsMd5OfRandomString()
48  {
49  $expected = 'fdb7594e77f1ad5fbb8e6c917b6012ce'; // == 'magento2'
50 
51  $this->randomMock
52  ->method('getRandomString')
53  ->willReturn('magento2');
54 
55  $actual = $this->cryptKeyGenerator->generate();
56 
57  $this->assertEquals($expected, $actual);
58  }
59 }