Skip to content

Commit adbd8f1

Browse files
committed
Validate closing behavior with global stream wrpper alias
1 parent 6943eda commit adbd8f1

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

tests/GridFS/BucketFunctionalTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,49 @@ public function testDanglingOpenWritableStream(): void
894894
$this->assertSame(14, $fileDocument->length);
895895
}
896896

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+
897940
public function testResolveStreamContextForRead(): void
898941
{
899942
$stream = $this->bucket->openUploadStream('filename');

0 commit comments

Comments
 (0)