Skip to content

Commit 4bb3d6f

Browse files
committed
Refactor data providers
With this refactoring, data providers become more concise; each data entry also gets a distinct name making for easier identification of failing tests
1 parent d4cdf05 commit 4bb3d6f

36 files changed

+369
-975
lines changed

tests/Collection/CollectionFunctionalTest.php

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -61,27 +61,14 @@ public function testConstructorOptionTypeChecks(array $options): void
6161
new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName(), $options);
6262
}
6363

64-
public function provideInvalidConstructorOptions()
64+
public function provideInvalidConstructorOptions(): void
6565
{
66-
$options = [];
67-
68-
foreach ($this->getInvalidReadConcernValues() as $value) {
69-
$options[][] = ['readConcern' => $value];
70-
}
71-
72-
foreach ($this->getInvalidReadPreferenceValues() as $value) {
73-
$options[][] = ['readPreference' => $value];
74-
}
75-
76-
foreach ($this->getInvalidArrayValues() as $value) {
77-
$options[][] = ['typeMap' => $value];
78-
}
79-
80-
foreach ($this->getInvalidWriteConcernValues() as $value) {
81-
$options[][] = ['writeConcern' => $value];
82-
}
83-
84-
return $options;
66+
$this->createOptionDataProvider([
67+
'readConcern' => $this->getInvalidReadConcernValues(),
68+
'readPreference' => $this->getInvalidReadPreferenceValues(),
69+
'typeMap' => $this->getInvalidArrayValues(),
70+
'writeConcern' => $this->getInvalidWriteConcernValues(),
71+
]);
8572
}
8673

8774
public function testGetManager(): void

tests/Command/ListCollectionsTest.php

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,13 @@ public function testConstructorOptionTypeChecks(array $options): void
1515
new ListCollections($this->getDatabaseName(), $options);
1616
}
1717

18-
public function provideInvalidConstructorOptions()
18+
public function provideInvalidConstructorOptions(): void
1919
{
20-
$options = [];
21-
22-
foreach ($this->getInvalidBooleanValues() as $value) {
23-
$options[][] = ['authorizedCollections' => $value];
24-
}
25-
26-
foreach ($this->getInvalidDocumentValues() as $value) {
27-
$options[][] = ['filter' => $value];
28-
}
29-
30-
foreach ($this->getInvalidIntegerValues() as $value) {
31-
$options[][] = ['maxTimeMS' => $value];
32-
}
33-
34-
foreach ($this->getInvalidSessionValues() as $value) {
35-
$options[][] = ['session' => $value];
36-
}
37-
38-
return $options;
20+
$this->createOptionDataProvider([
21+
'authorizedCollections' => $this->getInvalidBooleanValues(),
22+
'filter' => $this->getInvalidDocumentValues(),
23+
'maxTimeMS' => $this->getInvalidIntegerValues(),
24+
'session' => $this->getInvalidSessionValues(),
25+
]);
3926
}
4027
}

tests/Command/ListDatabasesTest.php

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,12 @@ public function testConstructorOptionTypeChecks(array $options): void
1717

1818
public function provideInvalidConstructorOptions()
1919
{
20-
$options = [];
21-
22-
foreach ($this->getInvalidBooleanValues() as $value) {
23-
$options[][] = ['authorizedDatabases' => $value];
24-
}
25-
26-
foreach ($this->getInvalidDocumentValues() as $value) {
27-
$options[][] = ['filter' => $value];
28-
}
29-
30-
foreach ($this->getInvalidIntegerValues() as $value) {
31-
$options[][] = ['maxTimeMS' => $value];
32-
}
33-
34-
foreach ($this->getInvalidBooleanValues() as $value) {
35-
$options[][] = ['nameOnly' => $value];
36-
}
37-
38-
foreach ($this->getInvalidSessionValues() as $value) {
39-
$options[][] = ['session' => $value];
40-
}
41-
42-
return $options;
20+
return $this->createOptionDataProvider([
21+
'authorizedDatabases' => $this->getInvalidBooleanValues(),
22+
'filter' => $this->getInvalidDocumentValues(),
23+
'maxTimeMS' => $this->getInvalidIntegerValues(),
24+
'nameOnly' => $this->getInvalidBooleanValues(),
25+
'session' => $this->getInvalidSessionValues(),
26+
]);
4327
}
4428
}

tests/Database/DatabaseFunctionalTest.php

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,12 @@ public function testConstructorOptionTypeChecks(array $options): void
4646

4747
public function provideInvalidConstructorOptions()
4848
{
49-
$options = [];
50-
51-
foreach ($this->getInvalidReadConcernValues() as $value) {
52-
$options[][] = ['readConcern' => $value];
53-
}
54-
55-
foreach ($this->getInvalidReadPreferenceValues() as $value) {
56-
$options[][] = ['readPreference' => $value];
57-
}
58-
59-
foreach ($this->getInvalidArrayValues() as $value) {
60-
$options[][] = ['typeMap' => $value];
61-
}
62-
63-
foreach ($this->getInvalidWriteConcernValues() as $value) {
64-
$options[][] = ['writeConcern' => $value];
65-
}
66-
67-
return $options;
49+
return $this->createOptionDataProvider([
50+
'readConcern' => $this->getInvalidReadConcernValues(),
51+
'readPreference' => $this->getInvalidReadPreferenceValues(),
52+
'typeMap' => $this->getInvalidArrayValues(),
53+
'writeConcern' => $this->getInvalidWriteConcernValues(),
54+
]);
6855
}
6956

7057
public function testGetManager(): void

tests/GridFS/BucketFunctionalTest.php

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -66,37 +66,15 @@ public function testConstructorOptionTypeChecks(array $options): void
6666

6767
public function provideInvalidConstructorOptions()
6868
{
69-
$options = [];
70-
71-
foreach ($this->getInvalidStringValues(true) as $value) {
72-
$options[][] = ['bucketName' => $value];
73-
}
74-
75-
foreach ($this->getInvalidIntegerValues(true) as $value) {
76-
$options[][] = ['chunkSizeBytes' => $value];
77-
}
78-
79-
foreach ($this->getInvalidBooleanValues(true) as $value) {
80-
$options[][] = ['disableMD5' => $value];
81-
}
82-
83-
foreach ($this->getInvalidReadConcernValues() as $value) {
84-
$options[][] = ['readConcern' => $value];
85-
}
86-
87-
foreach ($this->getInvalidReadPreferenceValues() as $value) {
88-
$options[][] = ['readPreference' => $value];
89-
}
90-
91-
foreach ($this->getInvalidArrayValues() as $value) {
92-
$options[][] = ['typeMap' => $value];
93-
}
94-
95-
foreach ($this->getInvalidWriteConcernValues() as $value) {
96-
$options[][] = ['writeConcern' => $value];
97-
}
98-
99-
return $options;
69+
return $this->createOptionDataProvider([
70+
'bucketName' => $this->getInvalidStringValues(true),
71+
'chunkSizeBytes' => $this->getInvalidIntegerValues(true),
72+
'disableMD5' => $this->getInvalidBooleanValues(true),
73+
'readConcern' => $this->getInvalidReadConcernValues(),
74+
'readPreference' => $this->getInvalidReadPreferenceValues(),
75+
'typeMap' => $this->getInvalidArrayValues(),
76+
'writeConcern' => $this->getInvalidWriteConcernValues(),
77+
]);
10078
}
10179

10280
public function testConstructorShouldRequireChunkSizeBytesOptionToBePositive(): void

tests/GridFS/WritableStreamFunctionalTest.php

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,11 @@ public function testConstructorOptionTypeChecks(array $options): void
4242

4343
public function provideInvalidConstructorOptions()
4444
{
45-
$options = [];
46-
47-
foreach ($this->getInvalidIntegerValues(true) as $value) {
48-
$options[][] = ['chunkSizeBytes' => $value];
49-
}
50-
51-
foreach ($this->getInvalidBooleanValues(true) as $value) {
52-
$options[][] = ['disableMD5' => $value];
53-
}
54-
55-
foreach ($this->getInvalidDocumentValues() as $value) {
56-
$options[][] = ['metadata' => $value];
57-
}
58-
59-
return $options;
45+
return $this->createOptionDataProvider([
46+
'chunkSizeBytes' => $this->getInvalidIntegerValues(true),
47+
'disableMD5' => $this->getInvalidBooleanValues(true),
48+
'metadata' => $this->getInvalidDocumentValues(),
49+
]);
6050
}
6151

6252
public function testConstructorShouldRequireChunkSizeBytesOptionToBePositive(): void

tests/Operation/AggregateTest.php

Lines changed: 17 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -26,69 +26,23 @@ public function testConstructorOptionTypeChecks(array $options): void
2626

2727
public function provideInvalidConstructorOptions()
2828
{
29-
$options = [];
30-
31-
foreach ($this->getInvalidBooleanValues() as $value) {
32-
$options[][] = ['allowDiskUse' => $value];
33-
}
34-
35-
foreach ($this->getInvalidIntegerValues() as $value) {
36-
$options[][] = ['batchSize' => $value];
37-
}
38-
39-
foreach ($this->getInvalidBooleanValues() as $value) {
40-
$options[][] = ['bypassDocumentValidation' => $value];
41-
}
42-
43-
foreach ($this->getInvalidDocumentValues() as $value) {
44-
$options[][] = ['collation' => $value];
45-
}
46-
47-
foreach ($this->getInvalidHintValues() as $value) {
48-
$options[][] = ['hint' => $value];
49-
}
50-
51-
foreach ($this->getInvalidDocumentValues() as $value) {
52-
$options[][] = ['let' => $value];
53-
}
54-
55-
foreach ($this->getInvalidBooleanValues() as $value) {
56-
$options[][] = ['explain' => $value];
57-
}
58-
59-
foreach ($this->getInvalidIntegerValues() as $value) {
60-
$options[][] = ['maxAwaitTimeMS' => $value];
61-
}
62-
63-
foreach ($this->getInvalidIntegerValues() as $value) {
64-
$options[][] = ['maxTimeMS' => $value];
65-
}
66-
67-
foreach ($this->getInvalidReadConcernValues() as $value) {
68-
$options[][] = ['readConcern' => $value];
69-
}
70-
71-
foreach ($this->getInvalidReadPreferenceValues() as $value) {
72-
$options[][] = ['readPreference' => $value];
73-
}
74-
75-
foreach ($this->getInvalidSessionValues() as $value) {
76-
$options[][] = ['session' => $value];
77-
}
78-
79-
foreach ($this->getInvalidArrayValues() as $value) {
80-
$options[][] = ['typeMap' => $value];
81-
}
82-
83-
foreach ($this->getInvalidBooleanValues(true) as $value) {
84-
$options[][] = ['useCursor' => $value];
85-
}
86-
87-
foreach ($this->getInvalidWriteConcernValues() as $value) {
88-
$options[][] = ['writeConcern' => $value];
89-
}
90-
91-
return $options;
29+
return $this->createOptionDataProvider([
30+
'allowDiskUse' => $this->getInvalidBooleanValues(),
31+
'batchSize' => $this->getInvalidIntegerValues(),
32+
'bypassDocumentValidation' => $this->getInvalidBooleanValues(),
33+
'collation' => $this->getInvalidDocumentValues(),
34+
'hint' => $this->getInvalidHintValues(),
35+
'let' => $this->getInvalidDocumentValues(),
36+
'explain' => $this->getInvalidBooleanValues(),
37+
'maxAwaitTimeMS' => $this->getInvalidIntegerValues(),
38+
'maxTimeMS' => $this->getInvalidIntegerValues(),
39+
'readConcern' => $this->getInvalidReadConcernValues(),
40+
'readPreference' => $this->getInvalidReadPreferenceValues(),
41+
'session' => $this->getInvalidSessionValues(),
42+
'typeMap' => $this->getInvalidArrayValues(),
43+
'useCursor' => $this->getInvalidBooleanValues(true),
44+
'writeConcern' => $this->getInvalidWriteConcernValues(),
45+
]);
9246
}
9347

9448
public function testConstructorBatchSizeOptionRequiresUseCursor(): void
@@ -103,11 +57,6 @@ public function testConstructorBatchSizeOptionRequiresUseCursor(): void
10357
);
10458
}
10559

106-
private function getInvalidHintValues()
107-
{
108-
return [123, 3.14, true];
109-
}
110-
11160
public function testExplainableCommandDocument(): void
11261
{
11362
$options = [

tests/Operation/BulkWriteTest.php

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -423,24 +423,11 @@ public function testConstructorOptionTypeChecks(array $options): void
423423

424424
public function provideInvalidConstructorOptions()
425425
{
426-
$options = [];
427-
428-
foreach ($this->getInvalidBooleanValues() as $value) {
429-
$options[][] = ['bypassDocumentValidation' => $value];
430-
}
431-
432-
foreach ($this->getInvalidBooleanValues(true) as $value) {
433-
$options[][] = ['ordered' => $value];
434-
}
435-
436-
foreach ($this->getInvalidSessionValues() as $value) {
437-
$options[][] = ['session' => $value];
438-
}
439-
440-
foreach ($this->getInvalidWriteConcernValues() as $value) {
441-
$options[][] = ['writeConcern' => $value];
442-
}
443-
444-
return $options;
426+
return $this->createOptionDataProvider([
427+
'bypassDocumentValidation' => $this->getInvalidBooleanValues(),
428+
'ordered' => $this->getInvalidBooleanValues(true),
429+
'session' => $this->getInvalidSessionValues(),
430+
'writeConcern' => $this->getInvalidWriteConcernValues(),
431+
]);
445432
}
446433
}

tests/Operation/CountDocumentsTest.php

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -23,45 +23,15 @@ public function testConstructorOptionTypeChecks(array $options): void
2323

2424
public function provideInvalidConstructorOptions()
2525
{
26-
$options = [];
27-
28-
foreach ($this->getInvalidDocumentValues() as $value) {
29-
$options[][] = ['collation' => $value];
30-
}
31-
32-
foreach ($this->getInvalidHintValues() as $value) {
33-
$options[][] = ['hint' => $value];
34-
}
35-
36-
foreach ($this->getInvalidIntegerValues() as $value) {
37-
$options[][] = ['limit' => $value];
38-
}
39-
40-
foreach ($this->getInvalidIntegerValues() as $value) {
41-
$options[][] = ['maxTimeMS' => $value];
42-
}
43-
44-
foreach ($this->getInvalidReadConcernValues() as $value) {
45-
$options[][] = ['readConcern' => $value];
46-
}
47-
48-
foreach ($this->getInvalidReadPreferenceValues() as $value) {
49-
$options[][] = ['readPreference' => $value];
50-
}
51-
52-
foreach ($this->getInvalidSessionValues() as $value) {
53-
$options[][] = ['session' => $value];
54-
}
55-
56-
foreach ($this->getInvalidIntegerValues() as $value) {
57-
$options[][] = ['skip' => $value];
58-
}
59-
60-
return $options;
61-
}
62-
63-
private function getInvalidHintValues()
64-
{
65-
return [123, 3.14, true];
26+
return $this->createOptionDataProvider([
27+
'collation' => $this->getInvalidDocumentValues(),
28+
'hint' => $this->getInvalidHintValues(),
29+
'limit' => $this->getInvalidIntegerValues(),
30+
'maxTimeMS' => $this->getInvalidIntegerValues(),
31+
'readConcern' => $this->getInvalidReadConcernValues(),
32+
'readPreference' => $this->getInvalidReadPreferenceValues(),
33+
'session' => $this->getInvalidSessionValues(),
34+
'skip' => $this->getInvalidIntegerValues(),
35+
]);
6636
}
6737
}

0 commit comments

Comments
 (0)