Skip to content

Commit 2bf64a9

Browse files
committed
Update TopologyDescription tests
1 parent d1c99f6 commit 2bf64a9

8 files changed

+59
-88
lines changed

tests/apm/monitoring-topologyChanged-001.phpt

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@ $m = create_test_manager();
1212

1313
class MySubscriber implements MongoDB\Driver\Monitoring\SDAMSubscriber
1414
{
15+
private $topologyDescription;
16+
1517
public function topologyChanged(MongoDB\Driver\Monitoring\TopologyChangedEvent $event)
1618
{
17-
echo "- getTopologyId() returns an object: ", is_object( $event->getTopologyId() ) ? 'yes' : 'no', "\n";
18-
19-
$topologyDescription = $event->getNewDescription();
20-
echo "- topologyDescription->getType() type returns a string: ", is_string( $topologyDescription->getType() ) ? 'yes' : 'no', "\n";
21-
echo "- topologyDescription->getServers() returns an array: ", is_array( $topologyDescription->getServers() ) ? 'yes' : 'no', "\n";
19+
if (! $this->topologyDescription) {
20+
echo "- getTopologyId() returns an object: ", is_object( $event->getTopologyId() ) ? 'yes' : 'no', "\n";
21+
22+
$this->topologyDescription = $event->getNewDescription();
23+
echo "- topologyDescription->getType() type returns a string: ", is_string( $this->topologyDescription->getType() ) ? 'yes' : 'no', "\n";
24+
echo "- topologyDescription->getServers() returns an array: ", is_array( $this->topologyDescription->getServers() ) ? 'yes' : 'no', "\n";
25+
}
2226
}
2327
}
2428

@@ -35,10 +39,4 @@ $m->executeCommand(DATABASE_NAME, $command);
3539
- getTopologyId() returns an object: yes
3640
- topologyDescription->getType() type returns a string: yes
3741
- topologyDescription->getServers() returns an array: yes
38-
- getTopologyId() returns an object: yes
39-
- topologyDescription->getType() type returns a string: yes
40-
- topologyDescription->getServers() returns an array: yes
41-
- getTopologyId() returns an object: yes
42-
- topologyDescription->getType() type returns a string: yes
43-
- topologyDescription->getServers() returns an array: yes
4442
===DONE===

tests/topologyDescription/topologyDescription-debug-001.phpt

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,19 @@ $manager = create_test_manager();
1111

1212
class MySubscriber implements MongoDB\Driver\Monitoring\SDAMSubscriber
1313
{
14+
private $topologyDescription;
15+
1416
public function topologyChanged(MongoDB\Driver\Monitoring\TopologyChangedEvent $event)
1517
{
16-
$topologyDescription = $event->getNewDescription();
17-
var_dump($topologyDescription);
18+
if (! $this->topologyDescription) {
19+
$this->topologyDescription = $event->getNewDescription();
20+
var_dump($this->topologyDescription);
21+
}
1822
}
1923
}
2024

2125
$subscriber = new MySubscriber;
22-
MongoDB\Driver\Monitoring\addSubscriber($subscriber);
26+
$manager->addSubscriber($subscriber);
2327

2428
$command = new MongoDB\Driver\Command(['ping' => 1]);
2529
$manager->executeCommand(DATABASE_NAME, $command);
@@ -31,10 +35,4 @@ $manager->executeCommand(DATABASE_NAME, $command);
3135
object(MongoDB\Driver\TopologyDescription)#%d (%d) {
3236
%a
3337
}
34-
object(MongoDB\Driver\TopologyDescription)#%d (%d) {
35-
%a
36-
}
37-
object(MongoDB\Driver\TopologyDescription)#%d (%d) {
38-
%a
39-
}
4038
===DONE===

tests/topologyDescription/topologyDescription-getServers-001.phpt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,19 @@ $manager = create_test_manager();
1111

1212
class MySubscriber implements MongoDB\Driver\Monitoring\SDAMSubscriber
1313
{
14+
private $topologyDescription;
15+
1416
public function topologyChanged(MongoDB\Driver\Monitoring\TopologyChangedEvent $event)
1517
{
16-
$topologyDescription = $event->getNewDescription();
17-
var_dump($topologyDescription->getServers());
18+
if (! $this->topologyDescription) {
19+
$this->topologyDescription = $event->getNewDescription();
20+
var_dump($this->topologyDescription->getServers());
21+
}
1822
}
1923
}
2024

2125
$subscriber = new MySubscriber;
22-
MongoDB\Driver\Monitoring\addSubscriber($subscriber);
26+
$manager->addSubscriber($subscriber);
2327

2428
$command = new MongoDB\Driver\Command(['ping' => 1]);
2529
$manager->executeCommand(DATABASE_NAME, $command);
@@ -30,8 +34,4 @@ $manager->executeCommand(DATABASE_NAME, $command);
3034
--EXPECTF--
3135
array(%d) {%A
3236
}
33-
array(%d) {%A
34-
}
35-
array(%d) {%A
36-
}
3737
===DONE===

tests/topologyDescription/topologyDescription-getType-001.phpt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ $manager = create_test_manager();
1111

1212
class MySubscriber implements MongoDB\Driver\Monitoring\SDAMSubscriber
1313
{
14+
private $topologyDescription;
15+
1416
public function topologyChanged(MongoDB\Driver\Monitoring\TopologyChangedEvent $event)
1517
{
1618
$expected_types = array(
@@ -21,13 +23,15 @@ class MySubscriber implements MongoDB\Driver\Monitoring\SDAMSubscriber
2123
MongoDB\Driver\TopologyDescription::TYPE_REPLICA_SET_WITH_PRIMARY
2224
);
2325

24-
$topologyDescription = $event->getNewDescription();
25-
var_dump(in_array($topologyDescription->getType(), $expected_types));
26+
if (! $this->topologyDescription) {
27+
$this->topologyDescription = $event->getNewDescription();
28+
var_dump(in_array($this->topologyDescription->getType(), $expected_types));
29+
}
2630
}
2731
}
2832

2933
$subscriber = new MySubscriber;
30-
MongoDB\Driver\Monitoring\addSubscriber($subscriber);
34+
$manager->addSubscriber($subscriber);
3135

3236
$command = new MongoDB\Driver\Command(['ping' => 1]);
3337
$manager->executeCommand(DATABASE_NAME, $command);
@@ -37,6 +41,4 @@ $manager->executeCommand(DATABASE_NAME, $command);
3741
<?php exit(0); ?>
3842
--EXPECTF--
3943
bool(true)
40-
bool(true)
41-
bool(true)
4244
===DONE===

tests/topologyDescription/topologyDescription-hasReadableServer-001.phpt

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,19 @@ $manager = create_test_manager();
1111

1212
class MySubscriber implements MongoDB\Driver\Monitoring\SDAMSubscriber
1313
{
14+
private $topologyDescription;
15+
1416
public function topologyChanged(MongoDB\Driver\Monitoring\TopologyChangedEvent $event)
1517
{
16-
$expected_types = array(
17-
MongoDB\Driver\TopologyDescription::TYPE_UNKNOWN,
18-
MongoDB\Driver\TopologyDescription::TYPE_SINGLE,
19-
MongoDB\Driver\TopologyDescription::TYPE_SHARDED,
20-
MongoDB\Driver\TopologyDescription::TYPE_REPLICA_SET_NO_PRIMARY,
21-
MongoDB\Driver\TopologyDescription::TYPE_REPLICA_SET_WITH_PRIMARY
22-
);
23-
24-
$topologyDescription = $event->getNewDescription();
25-
var_dump($topologyDescription->hasReadableServer());
18+
if (! $this->topologyDescription) {
19+
$this->topologyDescription = $event->getNewDescription();
20+
var_dump($this->topologyDescription->hasReadableServer());
21+
}
2622
}
2723
}
2824

2925
$subscriber = new MySubscriber;
30-
MongoDB\Driver\Monitoring\addSubscriber($subscriber);
26+
$manager->addSubscriber($subscriber);
3127

3228
$command = new MongoDB\Driver\Command(['ping' => 1]);
3329
$manager->executeCommand(DATABASE_NAME, $command);
@@ -37,6 +33,4 @@ $manager->executeCommand(DATABASE_NAME, $command);
3733
<?php exit(0); ?>
3834
--EXPECTF--
3935
bool(%s)
40-
bool(%s)
41-
bool(%s)
4236
===DONE===

tests/topologyDescription/topologyDescription-hasReadableServer-002.phpt

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,20 @@ $manager = create_test_manager();
1111

1212
class MySubscriber implements MongoDB\Driver\Monitoring\SDAMSubscriber
1313
{
14+
private $topologyDescription;
15+
1416
public function topologyChanged(MongoDB\Driver\Monitoring\TopologyChangedEvent $event)
1517
{
16-
$expected_types = array(
17-
MongoDB\Driver\TopologyDescription::TYPE_UNKNOWN,
18-
MongoDB\Driver\TopologyDescription::TYPE_SINGLE,
19-
MongoDB\Driver\TopologyDescription::TYPE_SHARDED,
20-
MongoDB\Driver\TopologyDescription::TYPE_REPLICA_SET_NO_PRIMARY,
21-
MongoDB\Driver\TopologyDescription::TYPE_REPLICA_SET_WITH_PRIMARY
22-
);
23-
24-
$topologyDescription = $event->getNewDescription();
25-
$rp = new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_PRIMARY);
26-
27-
var_dump($topologyDescription->hasReadableServer($rp));
18+
if (! $this->topologyDescription) {
19+
$this->topologyDescription = $event->getNewDescription();
20+
$rp = new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_PRIMARY);
21+
var_dump($this->topologyDescription->hasReadableServer($rp));
22+
}
2823
}
2924
}
3025

3126
$subscriber = new MySubscriber;
32-
MongoDB\Driver\Monitoring\addSubscriber($subscriber);
27+
$manager->addSubscriber($subscriber);
3328

3429
$command = new MongoDB\Driver\Command(['ping' => 1]);
3530
$manager->executeCommand(DATABASE_NAME, $command);
@@ -39,6 +34,4 @@ $manager->executeCommand(DATABASE_NAME, $command);
3934
<?php exit(0); ?>
4035
--EXPECTF--
4136
bool(%s)
42-
bool(%s)
43-
bool(%s)
4437
===DONE===

tests/topologyDescription/topologyDescription-hasWritableServer-001.phpt

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,19 @@ $manager = create_test_manager();
1111

1212
class MySubscriber implements MongoDB\Driver\Monitoring\SDAMSubscriber
1313
{
14+
private $topologyDescription;
15+
1416
public function topologyChanged(MongoDB\Driver\Monitoring\TopologyChangedEvent $event)
1517
{
16-
$expected_types = array(
17-
MongoDB\Driver\TopologyDescription::TYPE_UNKNOWN,
18-
MongoDB\Driver\TopologyDescription::TYPE_SINGLE,
19-
MongoDB\Driver\TopologyDescription::TYPE_SHARDED,
20-
MongoDB\Driver\TopologyDescription::TYPE_REPLICA_SET_NO_PRIMARY,
21-
MongoDB\Driver\TopologyDescription::TYPE_REPLICA_SET_WITH_PRIMARY
22-
);
23-
24-
$topologyDescription = $event->getNewDescription();
25-
var_dump($topologyDescription->hasWritableServer());
18+
if (! $this->topologyDescription) {
19+
$this->topologyDescription = $event->getNewDescription();
20+
var_dump($this->topologyDescription->hasWritableServer());
21+
}
2622
}
2723
}
2824

2925
$subscriber = new MySubscriber;
30-
MongoDB\Driver\Monitoring\addSubscriber($subscriber);
26+
$manager->addSubscriber($subscriber);;
3127

3228
$command = new MongoDB\Driver\Command(['ping' => 1]);
3329
$manager->executeCommand(DATABASE_NAME, $command);
@@ -37,6 +33,4 @@ $manager->executeCommand(DATABASE_NAME, $command);
3733
<?php exit(0); ?>
3834
--EXPECTF--
3935
bool(%s)
40-
bool(%s)
41-
bool(%s)
4236
===DONE===

tests/topologyDescription/topologyDescription-var_export-001.phpt

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,19 @@ $manager = create_test_manager();
1111

1212
class MySubscriber implements MongoDB\Driver\Monitoring\SDAMSubscriber
1313
{
14+
private $topologyDescription;
15+
1416
public function topologyChanged(MongoDB\Driver\Monitoring\TopologyChangedEvent $event)
1517
{
16-
$topologyDescription = $event->getNewDescription();
17-
echo var_export($topologyDescription, true), "\n";
18+
if (! $this->topologyDescription) {
19+
$this->topologyDescription = $event->getNewDescription();
20+
echo var_export($this->topologyDescription, true), "\n";
21+
}
1822
}
1923
}
2024

2125
$subscriber = new MySubscriber;
22-
MongoDB\Driver\Monitoring\addSubscriber($subscriber);
26+
$manager->addSubscriber($subscriber);
2327

2428
$command = new MongoDB\Driver\Command(['ping' => 1]);
2529
$manager->executeCommand(DATABASE_NAME, $command);
@@ -34,16 +38,4 @@ MongoDB\Driver\TopologyDescription::__set_state(array(
3438
),
3539
'type' => '%s',
3640
))
37-
MongoDB\Driver\TopologyDescription::__set_state(array(
38-
'servers' =>
39-
array (%A
40-
),
41-
'type' => '%s',
42-
))
43-
MongoDB\Driver\TopologyDescription::__set_state(array(
44-
'servers' =>
45-
array (%A
46-
),
47-
'type' => '%s',
48-
))
4941
===DONE===

0 commit comments

Comments
 (0)