EducationNotationUpdaterTest.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  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() {}
  10. }
  11. class EducationNotationUpdaterTest extends TestCase
  12. {
  13. private ObjectPersister $objectPersister;
  14. public function setUp(): void {
  15. $this->objectPersister = $this->getMockBuilder(ObjectPersister::class)->disableOriginalConstructor()->getMock();
  16. }
  17. public function testUpdate(): void {
  18. $educationNotationUpdater = $this->getMockBuilder(TestableEducationNotationUpdater::class)
  19. ->setConstructorArgs([$this->objectPersister])
  20. ->setMethodsExcept(['update'])
  21. ->getMock();
  22. $educationNotations = ['foo'];
  23. $this->objectPersister->expects(self::once())->method('replaceMany')->with($educationNotations);
  24. $educationNotationUpdater->update($educationNotations);
  25. }
  26. }