@@ -894,6 +894,49 @@ public function testDanglingOpenWritableStream(): void
894
894
$ this ->assertSame (14 , $ fileDocument ->length );
895
895
}
896
896
897
+ public function testDanglingOpenWritableStreamWithGlobalStreamWrapperAlias (): void
898
+ {
899
+ if (! strncasecmp (PHP_OS , 'WIN ' , 3 )) {
900
+ $ this ->markTestSkipped ('Test does not apply to Windows ' );
901
+ }
902
+
903
+ $ code = <<<'PHP'
904
+ require '%s';
905
+ require '%s';
906
+ $client = MongoDB\Tests\FunctionalTestCase::createTestClient();
907
+ $database = $client->selectDatabase(getenv('MONGODB_DATABASE') ?: 'phplib_test');
908
+ $database->selectGridFSBucket()->registerGlobalStreamWrapperAlias('default');
909
+ $stream = fopen('gridfs://default/hello.txt', 'w');
910
+ fwrite($stream, 'Hello MongoDB!');
911
+ PHP;
912
+
913
+ @exec (
914
+ implode (' ' , [
915
+ PHP_BINARY ,
916
+ '-r ' ,
917
+ escapeshellarg (
918
+ sprintf (
919
+ $ code ,
920
+ __DIR__ . '/../../vendor/autoload.php ' ,
921
+ // Include the PHPUnit autoload file to ensure PHPUnit classes can be loaded
922
+ __DIR__ . '/../../vendor/bin/.phpunit/phpunit/vendor/autoload.php ' ,
923
+ ),
924
+ ),
925
+ '2>&1 ' ,
926
+ ]),
927
+ $ output ,
928
+ $ return ,
929
+ );
930
+
931
+ $ this ->assertSame ([], $ output );
932
+ $ this ->assertSame (0 , $ return );
933
+
934
+ $ fileDocument = $ this ->filesCollection ->findOne (['filename ' => 'hello.txt ' ]);
935
+
936
+ $ this ->assertNotNull ($ fileDocument );
937
+ $ this ->assertSame (14 , $ fileDocument ->length );
938
+ }
939
+
897
940
public function testResolveStreamContextForRead (): void
898
941
{
899
942
$ stream = $ this ->bucket ->openUploadStream ('filename ' );
0 commit comments