1--TEST--
2PHPC-1163: Unacknowledged write concern should omit implicit session
3--SKIPIF--
4<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5<?php skip_if_not_live(); ?>
6<?php skip_if_server_version('<', '3.4'); ?>
7<?php skip_if_not_clean(); ?>
8--FILE--
9<?php
10require_once __DIR__ . "/../utils/basic.inc";
11
12class Test implements MongoDB\Driver\Monitoring\CommandSubscriber
13{
14    public function run()
15    {
16        $manager = new MongoDB\Driver\Manager(URI, ['w' => 0]);
17
18        MongoDB\Driver\Monitoring\addSubscriber($this);
19
20        $bulk = new MongoDB\Driver\BulkWrite;
21        $bulk->insert(['x' => 1]);
22
23        echo "Testing executeBulkWrite\n";
24        $manager->executeBulkWrite(NS, $bulk);
25
26        $command = new MongoDB\Driver\Command([
27            'insert' => COLLECTION_NAME,
28            'documents' => [['x' => 1]],
29        ]);
30
31        /* Note: executeCommand() and executeReadCommand() are not tested
32         * because they do not inherit the client-level write concern. */
33
34        echo "\nTesting executeWriteCommand\n";
35        $manager->executeWriteCommand(DATABASE_NAME, $command);
36
37        /* We can safely re-use the insert command with executeReadWriteCommand
38         * because there is no readConcern to inherit. */
39        echo "\nTesting executeReadWriteCommand\n";
40        $manager->executeReadWriteCommand(DATABASE_NAME, $command);
41
42        MongoDB\Driver\Monitoring\removeSubscriber($this);
43    }
44
45    public function commandStarted(MongoDB\Driver\Monitoring\CommandStartedEvent $event)
46    {
47        if ($event->getCommandName() === 'insert') {
48            $command = $event->getCommand();
49            $hasSession = isset($command->lsid);
50            $writeConcern = isset($command->writeConcern) ? $command->writeConcern: null;
51
52            printf("insert command write concern: %s\n", json_encode($writeConcern));
53            printf("insert command has session: %s\n", $hasSession ? 'yes' : 'no');
54        }
55    }
56
57    public function commandSucceeded(MongoDB\Driver\Monitoring\CommandSucceededEvent $event)
58    {
59    }
60
61    public function commandFailed(MongoDB\Driver\Monitoring\CommandFailedEvent $event)
62    {
63    }
64}
65
66(new Test)->run();
67
68?>
69===DONE===
70<?php exit(0); ?>
71--EXPECT--
72Testing executeBulkWrite
73insert command write concern: {"w":0}
74insert command has session: no
75
76Testing executeWriteCommand
77insert command write concern: {"w":0}
78insert command has session: no
79
80Testing executeReadWriteCommand
81insert command write concern: {"w":0}
82insert command has session: no
83===DONE===
84