|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Exception; |
| 4 | + |
| 5 | +use MongoDB\Collection; |
| 6 | +use MongoDB\Driver\Command; |
| 7 | +use MongoDB\Driver\Exception\ServerException; |
| 8 | +use MongoDB\Exception\AtlasSearchNotSupportedException; |
| 9 | +use MongoDB\Tests\Collection\FunctionalTestCase; |
| 10 | + |
| 11 | +class AtlasSearchNotSupportedExceptionTest extends FunctionalTestCase |
| 12 | +{ |
| 13 | + public function testListSearchIndexesNotSupportedException(): void |
| 14 | + { |
| 15 | + if (self::isAtlas()) { |
| 16 | + self::markTestSkipped('Atlas Search is supported on Atlas'); |
| 17 | + } |
| 18 | + |
| 19 | + $collection = new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName()); |
| 20 | + |
| 21 | + $this->expectException(AtlasSearchNotSupportedException::class); |
| 22 | + |
| 23 | + $collection->listSearchIndexes(); |
| 24 | + } |
| 25 | + |
| 26 | + public function testCreateSearchIndexNotSupportedException(): void |
| 27 | + { |
| 28 | + if (self::isAtlas()) { |
| 29 | + self::markTestSkipped('Atlas Search is supported on Atlas'); |
| 30 | + } |
| 31 | + |
| 32 | + $collection = new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName()); |
| 33 | + |
| 34 | + $this->expectException(AtlasSearchNotSupportedException::class); |
| 35 | + |
| 36 | + $collection->createSearchIndex(['mappings' => ['dynamic' => false]], ['name' => 'test-search-index']); |
| 37 | + } |
| 38 | + |
| 39 | + public function testOtherStageNotFound(): void |
| 40 | + { |
| 41 | + $collection = new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName()); |
| 42 | + |
| 43 | + try { |
| 44 | + $collection->aggregate([ |
| 45 | + ['$searchStageNotExisting' => ['text' => ['query' => 'test', 'path' => 'field']]], |
| 46 | + ]); |
| 47 | + self::fail('Expected ServerException was not thrown'); |
| 48 | + } catch (ServerException $exception) { |
| 49 | + self::assertNotInstanceOf(AtlasSearchNotSupportedException::class, $exception, $exception); |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + public function testOtherCommandNotFound(): void |
| 54 | + { |
| 55 | + try { |
| 56 | + $this->manager->executeCommand($this->getDatabaseName(), new Command(['nonExistingCommand' => 1])); |
| 57 | + self::fail('Expected ServerException was not thrown'); |
| 58 | + } catch (ServerException $exception) { |
| 59 | + self::assertFalse(AtlasSearchNotSupportedException::isAtlasSearchNotSupportedError($exception)); |
| 60 | + } |
| 61 | + } |
| 62 | +} |
0 commit comments