22
33namespace MongoDB \Tests \SpecTests ;
44
5- use MongoDB \Driver \Command ;
65use MongoDB \Driver \Cursor ;
76use MongoDB \Tests \CommandObserver ;
8- use stdClass ;
97
10- use function basename ;
118use function current ;
129use function explode ;
13- use function file_get_contents ;
14- use function glob ;
1510use function parse_url ;
1611
1712/**
@@ -32,101 +27,7 @@ public function setUp(): void
3227 }
3328
3429 /**
35- * Assert that the expected and actual command documents match.
36- *
37- * @param stdClass $expected Expected command document
38- * @param stdClass $actual Actual command document
39- */
40- public static function assertCommandMatches (stdClass $ expected , stdClass $ actual ): void
41- {
42- foreach ($ expected as $ key => $ value ) {
43- if ($ value === null ) {
44- static ::assertObjectNotHasAttribute ($ key , $ actual );
45- unset($ expected ->{$ key });
46- }
47- }
48-
49- static ::assertDocumentsMatch ($ expected , $ actual );
50- }
51-
52- /**
53- * Execute an individual test case from the specification.
54- *
55- * @dataProvider provideTests
56- * @param stdClass $test Individual "tests[]" document
57- * @param array $runOn Top-level "runOn" array with server requirements
58- * @param array $data Top-level "data" array to initialize collection
59- * @param string $databaseName Name of database under test
60- * @param string $collectionName Name of collection under test
61- */
62- public function testAtlasDataLake (stdClass $ test , ?array $ runOn , array $ data , ?string $ databaseName = null , ?string $ collectionName = null ): void
63- {
64- if (isset ($ runOn )) {
65- $ this ->checkServerRequirements ($ runOn );
66- }
67-
68- if (isset ($ test ->skipReason )) {
69- $ this ->markTestSkipped ($ test ->skipReason );
70- }
71-
72- $ databaseName ??= $ this ->getDatabaseName ();
73- $ collectionName ??= $ this ->getCollectionName ();
74-
75- $ context = Context::fromCrud ($ test , $ databaseName , $ collectionName );
76- $ this ->setContext ($ context );
77-
78- /* Note: Atlas Data Lake is read-only, so do not attempt to drop the
79- * collection under test or insert data fixtures. Necesarry data
80- * fixtures are already specified in the mongohoused configuration. */
81-
82- if (isset ($ test ->failPoint )) {
83- throw new LogicException ('ADL tests are not expected to configure fail points ' );
84- }
85-
86- if (isset ($ test ->expectations )) {
87- $ commandExpectations = CommandExpectations::fromCrud ($ context ->getClient (), (array ) $ test ->expectations );
88- $ commandExpectations ->startMonitoring ();
89- }
90-
91- foreach ($ test ->operations as $ operation ) {
92- Operation::fromCrud ($ operation )->assert ($ this , $ context );
93- }
94-
95- if (isset ($ commandExpectations )) {
96- $ commandExpectations ->stopMonitoring ();
97- $ commandExpectations ->assert ($ this , $ context );
98- }
99-
100- if (isset ($ test ->outcome ->collection ->data )) {
101- throw new LogicException ('ADL tests are not expected to assert collection data ' );
102- }
103- }
104-
105- public function provideTests ()
106- {
107- $ testArgs = [];
108-
109- foreach (glob (__DIR__ . '/atlas_data_lake/*.json ' ) as $ filename ) {
110- $ json = $ this ->decodeJson (file_get_contents ($ filename ));
111- $ group = basename ($ filename , '.json ' );
112- $ runOn = $ json ->runOn ?? null ;
113- $ data = $ json ->data ?? [];
114- // phpcs:disable Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
115- $ databaseName = $ json ->database_name ?? null ;
116- $ collectionName = $ json ->collection_name ?? null ;
117- // phpcs:enable Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
118-
119- foreach ($ json ->tests as $ test ) {
120- $ name = $ group . ': ' . $ test ->description ;
121- $ testArgs [$ name ] = [$ test , $ runOn , $ data , $ databaseName , $ collectionName ];
122- }
123- }
124-
125- return $ testArgs ;
126- }
127-
128- /**
129- * Prose test 1: Connect without authentication
30+ * Prose test 1: killCursors command
13031 */
13132 public function testKillCursors (): void
13233 {
@@ -235,16 +136,4 @@ public function testConnectwithSCRAMSHA256(): void
235136 $ this ->assertInstanceOf (Cursor::class, $ cursor );
236137 $ this ->assertCommandSucceeded (current ($ cursor ->toArray ()));
237138 }
238-
239- private function isAtlasDataLake (): bool
240- {
241- $ cursor = $ this ->manager ->executeCommand (
242- $ this ->getDatabaseName (),
243- new Command (['buildInfo ' => 1 ]),
244- );
245-
246- $ document = current ($ cursor ->toArray ());
247-
248- return ! empty ($ document ->dataLake );
249- }
250139}
0 commit comments