EducationNotationUpdaterTest.php 1.2 KB

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