<?php

namespace App\Tests\Unit\Service\File\Storage;

use App\Entity\Core\File;
use App\Service\ApiLegacy\ApiLegacyRequestService;
use App\Service\File\Storage\ApiLegacyStorage;
use PHPUnit\Framework\TestCase;

class ApiLegacyStorageTest extends TestCase
{
    public function testRead(): void
    {
        $apiLegacyRequestService = $this->getMockBuilder(ApiLegacyRequestService::class)
            ->disableOriginalConstructor()
            ->getMock();

        $apiLegacyStorageTest = $this
            ->getMockBuilder(ApiLegacyStorage::class)
            ->setConstructorArgs([$apiLegacyRequestService])
            ->setMethodsExcept(['read'])
            ->getMock();

        $file = $this->getMockBuilder(File::class)->getMock();
        $file->method('getId')->willReturn(123);

        $apiLegacyRequestService
            ->expects(self::once())
            ->method('getContent')
            ->with('_internal/secure/files/123')
            ->willReturn('xyz');

        $result = $apiLegacyStorageTest->read($file);

        $this->assertEquals('xyz', $result);
    }

}
