|
23 | 23 | use function array_merge;
|
24 | 24 | use function call_user_func;
|
25 | 25 | use function current;
|
| 26 | +use function escapeshellarg; |
26 | 27 | use function exec;
|
27 | 28 | use function fclose;
|
28 | 29 | use function fopen;
|
|
39 | 40 | use function strncasecmp;
|
40 | 41 | use function substr;
|
41 | 42 |
|
42 |
| -use const PHP_EOL; |
| 43 | +use const PHP_BINARY; |
43 | 44 | use const PHP_OS;
|
44 | 45 |
|
45 | 46 | /**
|
@@ -853,21 +854,33 @@ public function testDanglingOpenWritableStream(): void
|
853 | 854 | $this->markTestSkipped('Test does not apply to Windows');
|
854 | 855 | }
|
855 | 856 |
|
856 |
| - $path = __DIR__ . '/../../vendor/autoload.php'; |
857 |
| - $command = <<<CMD |
858 |
| -php -r "require '$path'; \\\$stream = (new MongoDB\Client)->test->selectGridFSBucket()->openUploadStream('filename', ['disableMD5' => true]);" 2>&1 |
859 |
| -CMD; |
| 857 | + $code = <<<'PHP' |
| 858 | + require '%s'; |
| 859 | + $client = new \MongoDB\Client(getenv('MONGODB_URI') ?: 'mongodb://127.0.0.1:27017/?serverSelectionTimeoutMS=100'); |
| 860 | + $database = $client->selectDatabase(getenv('MONGODB_DATABASE') ?: 'phplib_test'); |
| 861 | + $gridfs = $database->selectGridFSBucket(); |
| 862 | + $stream = $gridfs->openUploadStream('hello.txt', ['disableMD5' => true]); |
| 863 | + fwrite($stream, 'Hello MongoDB!'); |
| 864 | + PHP; |
860 | 865 |
|
861 | 866 | @exec(
|
862 |
| - $command, |
| 867 | + implode(' ', [ |
| 868 | + PHP_BINARY, |
| 869 | + '-r', |
| 870 | + escapeshellarg(sprintf($code, __DIR__ . '/../../vendor/autoload.php')), |
| 871 | + '2>&1', |
| 872 | + ]), |
863 | 873 | $output,
|
864 | 874 | $return,
|
865 | 875 | );
|
866 | 876 |
|
| 877 | + $this->assertSame([], $output); |
867 | 878 | $this->assertSame(0, $return);
|
868 |
| - $output = implode(PHP_EOL, $output); |
869 | 879 |
|
870 |
| - $this->assertSame('', $output); |
| 880 | + $fileDocument = $this->filesCollection->findOne(['filename' => 'hello.txt']); |
| 881 | + |
| 882 | + $this->assertNotNull($fileDocument); |
| 883 | + $this->assertSame(14, $fileDocument->length); |
871 | 884 | }
|
872 | 885 |
|
873 | 886 | /**
|
|
0 commit comments