EducationNotationUpdaterTest.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace App\Tests\Unit\Service\Elasticsearch;
  3. use App\Service\Elasticsearch\EducationNotationUpdater;
  4. use FOS\ElasticaBundle\Persister\ObjectPersister;
  5. use PHPUnit\Framework\TestCase;
  6. class TestableEducationNotationUpdater extends EducationNotationUpdater
  7. {
  8. // To avoid the bug when mocking classes with only one method;
  9. // can be removed when the tested class will have at least 2 methods
  10. public function foo(): void
  11. {
  12. }
  13. }
  14. class EducationNotationUpdaterTest extends TestCase
  15. {
  16. private ObjectPersister $objectPersister;
  17. public function setUp(): void
  18. {
  19. $this->objectPersister = $this->getMockBuilder(ObjectPersister::class)->disableOriginalConstructor()->getMock();
  20. }
  21. /**
  22. * @see EducationNotationUpdater::update()
  23. */
  24. public function testUpdate(): void
  25. {
  26. $educationNotationUpdater = $this->getMockBuilder(TestableEducationNotationUpdater::class)
  27. ->setConstructorArgs([$this->objectPersister])
  28. ->setMethodsExcept(['update'])
  29. ->getMock();
  30. $educationNotations = ['foo'];
  31. $this->objectPersister->expects(self::once())->method('replaceMany')->with($educationNotations);
  32. $educationNotationUpdater->update($educationNotations);
  33. }
  34. }