<?php

namespace App\Tests\Unit\Service\Elasticsearch;

use App\Service\Elasticsearch\EducationNotationUpdater;
use FOS\ElasticaBundle\Persister\ObjectPersister;
use PHPUnit\Framework\TestCase;

class TestableEducationNotationUpdater extends EducationNotationUpdater {
    // To avoid the bug when mocking classes with only one method;
    // can be removed when the tested class will have at least 2 methods
    public function foo(): void
    {}
}

class EducationNotationUpdaterTest extends TestCase
{
    private ObjectPersister $objectPersister;

    public function setUp(): void {
        $this->objectPersister = $this->getMockBuilder(ObjectPersister::class)->disableOriginalConstructor()->getMock();
    }

    /**
     * @see EducationNotationUpdater::update()
     */
    public function testUpdate(): void {
        $educationNotationUpdater = $this->getMockBuilder(TestableEducationNotationUpdater::class)
            ->setConstructorArgs([$this->objectPersister])
            ->setMethodsExcept(['update'])
            ->getMock();

        $educationNotations = ['foo'];

        $this->objectPersister->expects(self::once())->method('replaceMany')->with($educationNotations);

        $educationNotationUpdater->update($educationNotations);
    }
}
