<?php
/**
 * Copyright 2017 Adobe
 * All Rights Reserved.
 */
declare(strict_types=1);

namespace Magento\Config\Test\Unit\App\Config\Source;

use Magento\Config\App\Config\Source\InitialSnapshotConfigSource;
use Magento\Framework\DataObject;
use Magento\Framework\DataObjectFactory;
use Magento\Framework\FlagManager;
use PHPUnit\Framework\MockObject\MockObject as Mock;
use PHPUnit\Framework\TestCase;

/**
 * @inheritdoc
 */
class InitialSnapshotConfigSourceTest extends TestCase
{
    /**
     * @var InitialSnapshotConfigSource
     */
    private $model;

    /**
     * @var FlagManager|Mock
     */
    private $flagManagerMock;

    /**
     * @var DataObjectFactory|Mock
     */
    private $dataObjectFactoryMock;

    /**
     * @var DataObject|Mock
     */
    private $dataObjectMock;

    /**
     * @inheritdoc
     */
    protected function setUp(): void
    {
        $this->flagManagerMock = $this->createMock(FlagManager::class);
        $this->dataObjectFactoryMock = $this->createPartialMock(DataObjectFactory::class, ['create']);

        $this->dataObjectMock = $this->createMock(DataObject::class);

        $this->dataObjectFactoryMock->expects($this->any())
            ->method('create')
            ->willReturn($this->dataObjectMock);

        $this->model = new InitialSnapshotConfigSource(
            $this->flagManagerMock,
            $this->dataObjectFactoryMock
        );
    }

    public function testGet()
    {
        $this->flagManagerMock->expects($this->exactly(2))
            ->method('getFlagData')
            ->with('system_config_snapshot')
            ->willReturnOnConsecutiveCalls(
                ['some' => 'data'],
                'data'
            );
        $this->dataObjectMock->expects($this->exactly(2))
            ->method('getData')
            ->willReturnOnConsecutiveCalls(
                ['some' => 'data'],
                'data'
            );

        $this->assertSame(['some' => 'data'], $this->model->get());
        $this->assertSame('data', $this->model->get('some/path'));
    }
}
