- $options->searches = SearchOptionSet::fromValueArray(['cat']);
- $options->exacts = SearchOptionSet::fromValueArray(['dog']);
- $options->tags = SearchOptionSet::fromValueArray(['tag=good']);
- $options->filters = SearchOptionSet::fromMapArray(['is_tree' => '']);
+ $options->searches = SearchOptionSet::fromValueArray(['cat'], TermSearchOption::class);
+ $options->exacts = SearchOptionSet::fromValueArray(['dog'], ExactSearchOption::class);
+ $options->tags = SearchOptionSet::fromValueArray(['tag=good'], TagSearchOption::class);
+ $options->filters = new SearchOptionSet([
+ new FilterSearchOption('', 'is_tree'),
+ new FilterSearchOption('valid', 'beans'),
+ ]);
+
+ $output = $options->toString();
+ foreach (explode(' ', $expected) as $term) {
+ $this->assertStringContainsString($term, $output);
+ }
+ }
+
+ public function test_to_string_handles_negations_as_expected()
+ {
+ $expected = 'cat -"dog" -[tag=good] -{is_tree}';
+ $options = new SearchOptions();
+ $options->searches = new SearchOptionSet([new TermSearchOption('cat')]);
+ $options->exacts = new SearchOptionSet([new ExactSearchOption('dog', true)]);
+ $options->tags = new SearchOptionSet([new TagSearchOption('tag=good', true)]);
+ $options->filters = new SearchOptionSet([
+ new FilterSearchOption('', 'is_tree', true),
+ ]);