2
0

ExportPaliSynonymsSetPathTest.php 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. use App\Services\OpenSearchService;
  3. it('points the index at the given synonyms file', function () {
  4. $this->mock(OpenSearchService::class)
  5. ->shouldReceive('updatePaliSynonymsPath')
  6. ->once()
  7. ->with('aaa.txt')
  8. ->andReturn(['path' => '/srv/opensearch/synonyms/aaa.txt', 'settings' => ['acknowledged' => true]]);
  9. $this->artisan('export:pali.synonyms.set-path', ['--name' => 'aaa.txt'])
  10. ->expectsOutputToContain('/srv/opensearch/synonyms/aaa.txt')
  11. ->assertSuccessful();
  12. });
  13. it('fails when OpenSearch rejects the update', function () {
  14. $this->mock(OpenSearchService::class)
  15. ->shouldReceive('updatePaliSynonymsPath')
  16. ->once()
  17. ->andThrow(new Exception('Index [wikipali] does not exist.'));
  18. $this->artisan('export:pali.synonyms.set-path', ['--name' => 'aaa.txt'])
  19. ->assertFailed();
  20. });
  21. it('rejects a name that is missing or contains a path', function (?string $name) {
  22. $this->mock(OpenSearchService::class)->shouldNotReceive('updatePaliSynonymsPath');
  23. $this->artisan('export:pali.synonyms.set-path', $name === null ? [] : ['--name' => $name])
  24. ->assertFailed();
  25. })->with([null, '', '../etc/passwd', 'dir/aaa.txt', '.hidden']);