CryptKeyGeneratorTest.php 1.36 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
<?php
/***
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace Magento\Setup\Test\Unit\Model;

use Magento\Framework\Math\Random;
use Magento\Setup\Model\CryptKeyGenerator;
use PHPUnit\Framework\TestCase;

/**
 * Testcase for CryptKeyGenerator
 */
class CryptKeyGeneratorTest extends TestCase
{
    /**
     * @var Random|\PHPUnit_Framework_MockObject_MockObject
     */
    private $randomMock;

    /**
     * @var CryptKeyGenerator
     */
    private $cryptKeyGenerator;

    public function setUp()
    {
        $this->randomMock = $this->getMockBuilder(Random::class)
            ->disableOriginalConstructor()
            ->getMock();

        $this->cryptKeyGenerator = new CryptKeyGenerator($this->randomMock);
    }

    public function testStringForHashingIsReadFromRandom()
    {
        $this->randomMock
            ->expects($this->once())
            ->method('getRandomString')
            ->willReturn('');
        
        $this->cryptKeyGenerator->generate();
    }

    public function testReturnsMd5OfRandomString()
    {
        $expected = 'fdb7594e77f1ad5fbb8e6c917b6012ce'; // == 'magento2'

        $this->randomMock
            ->method('getRandomString')
            ->willReturn('magento2');

        $actual = $this->cryptKeyGenerator->generate();

        $this->assertEquals($expected, $actual);
    }
}