Skip to content

Commit 3724afc

Browse files
authored
PHPLIB-1514 Make data providers static (#1404)
1 parent ae90e89 commit 3724afc

File tree

75 files changed

+568
-537
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+568
-537
lines changed

rector.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use Rector\DeadCode\Rector\ClassLike\RemoveAnnotationRector;
55
use Rector\Php70\Rector\StmtsAwareInterface\IfIssetToCoalescingRector;
66
use Rector\Php80\Rector\Switch_\ChangeSwitchToMatchRector;
7+
use Rector\PHPUnit\PHPUnit100\Rector\Class_\StaticDataProviderClassMethodRector;
78
use Rector\Set\ValueObject\LevelSetList;
89

910
return static function (RectorConfig $rectorConfig): void {
@@ -18,6 +19,7 @@
1819
$rectorConfig->sets([LevelSetList::UP_TO_PHP_74]);
1920

2021
$rectorConfig->rule(ChangeSwitchToMatchRector::class);
22+
$rectorConfig->rule(StaticDataProviderClassMethodRector::class);
2123

2224
// phpcs:disable Squiz.Arrays.ArrayDeclaration.KeySpecified
2325
$rectorConfig->skip([

tests/Builder/FieldPathTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function testRejectDollarPrefix(string $fieldPathClass): void
3535
Expression::{$fieldPathClass}('$foo');
3636
}
3737

38-
public function provideFieldPath(): Generator
38+
public static function provideFieldPath(): Generator
3939
{
4040
yield 'double' => ['doubleFieldPath', Expression\ResolvesToDouble::class];
4141
yield 'string' => ['stringFieldPath', Expression\ResolvesToString::class];

tests/Builder/Type/CombinedFieldQueryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function testRejectDuplicateOperator(array $fieldQueries): void
8787
]);
8888
}
8989

90-
public function provideDuplicateOperator(): Generator
90+
public static function provideDuplicateOperator(): Generator
9191
{
9292
yield 'array and FieldQuery' => [
9393
[

tests/Builder/Type/OutputWindowTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function testRejectInvalidDocuments(array $documents): void
7373
);
7474
}
7575

76-
public function provideInvalidDocuments(): Generator
76+
public static function provideInvalidDocuments(): Generator
7777
{
7878
yield 'too few' => [[1]];
7979
yield 'too many' => [[1, 2, 3]];
@@ -98,7 +98,7 @@ public function testRejectInvalidRange(array $range): void
9898
);
9999
}
100100

101-
public function provideInvalidRange(): Generator
101+
public static function provideInvalidRange(): Generator
102102
{
103103
yield 'too few' => [[1]];
104104
yield 'too many' => [[1, 2, 3]];

tests/Builder/Type/QueryObjectTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function testCreateQueryObjectFromArray(array $value, int $expectedCount
5757
$this->assertCount($expectedCount, $queryObject->queries);
5858
}
5959

60-
public function provideQueryObjectValue(): Generator
60+
public static function provideQueryObjectValue(): Generator
6161
{
6262
yield 'int' => [['foo' => 1]];
6363
yield 'float' => [['foo' => 1.1]];

tests/Builder/VariableTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function testSystemVariables($factory): void
3535
$this->assertStringStartsNotWith('$$', $variable->name);
3636
}
3737

38-
public function provideVariableBuilders(): Generator
38+
public static function provideVariableBuilders(): Generator
3939
{
4040
yield 'now' => [fn () => Variable::now()];
4141
yield 'clusterTime' => [fn () => Variable::clusterTime()];

tests/ClientTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,29 +42,29 @@ public function testConstructorDriverOptionTypeChecks(array $driverOptions, stri
4242
new Client(static::getUri(), [], $driverOptions);
4343
}
4444

45-
public function provideInvalidConstructorDriverOptions()
45+
public static function provideInvalidConstructorDriverOptions()
4646
{
4747
$options = [];
4848

49-
foreach ($this->getInvalidObjectValues() as $value) {
49+
foreach (self::getInvalidObjectValues() as $value) {
5050
$options[][] = ['builderEncoder' => $value];
5151
}
5252

53-
foreach ($this->getInvalidArrayValues(true) as $value) {
53+
foreach (self::getInvalidArrayValues(true) as $value) {
5454
$options[][] = ['typeMap' => $value];
5555
}
5656

5757
$options[][] = ['autoEncryption' => ['keyVaultClient' => 'foo']];
5858

59-
foreach ($this->getInvalidStringValues() as $value) {
59+
foreach (self::getInvalidStringValues() as $value) {
6060
$options[][] = ['driver' => ['name' => $value]];
6161
}
6262

63-
foreach ($this->getInvalidStringValues() as $value) {
63+
foreach (self::getInvalidStringValues() as $value) {
6464
$options[][] = ['driver' => ['version' => $value]];
6565
}
6666

67-
foreach ($this->getInvalidStringValues() as $value) {
67+
foreach (self::getInvalidStringValues() as $value) {
6868
$options[] = [
6969
'driverOptions' => ['driver' => ['platform' => $value]],
7070
'exception' => DriverInvalidArgumentException::class,

tests/Collection/CodecCollectionFunctionalTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public function testBulkWrite($expected, $options): void
151151
);
152152
}
153153

154-
public function provideFindOneAndModifyOptions(): Generator
154+
public static function provideFindOneAndModifyOptions(): Generator
155155
{
156156
yield 'Default codec' => [
157157
'expected' => TestObject::createDecodedForFixture(1),

tests/Collection/CollectionFunctionalTest.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function testConstructorCollectionNameArgument($collectionName, string $e
4949
new Collection($this->manager, $this->getDatabaseName(), $collectionName);
5050
}
5151

52-
public function provideInvalidDatabaseAndCollectionNames()
52+
public static function provideInvalidDatabaseAndCollectionNames()
5353
{
5454
return [
5555
[null, TypeError::class],
@@ -64,15 +64,15 @@ public function testConstructorOptionTypeChecks(array $options): void
6464
new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName(), $options);
6565
}
6666

67-
public function provideInvalidConstructorOptions(): array
67+
public static function provideInvalidConstructorOptions(): array
6868
{
69-
return $this->createOptionDataProvider([
70-
'builderEncoder' => $this->getInvalidObjectValues(),
71-
'codec' => $this->getInvalidDocumentCodecValues(),
72-
'readConcern' => $this->getInvalidReadConcernValues(),
73-
'readPreference' => $this->getInvalidReadPreferenceValues(),
74-
'typeMap' => $this->getInvalidArrayValues(),
75-
'writeConcern' => $this->getInvalidWriteConcernValues(),
69+
return self::createOptionDataProvider([
70+
'builderEncoder' => self::getInvalidObjectValues(),
71+
'codec' => self::getInvalidDocumentCodecValues(),
72+
'readConcern' => self::getInvalidReadConcernValues(),
73+
'readPreference' => self::getInvalidReadPreferenceValues(),
74+
'typeMap' => self::getInvalidArrayValues(),
75+
'writeConcern' => self::getInvalidWriteConcernValues(),
7676
]);
7777
}
7878

@@ -210,7 +210,7 @@ public function testDistinctWithTypeMap(array $typeMap, array $expectedDocuments
210210
$this->assertEquals($expectedDocuments, $values);
211211
}
212212

213-
public function provideTypeMapOptionsAndExpectedDocuments()
213+
public static function provideTypeMapOptionsAndExpectedDocuments()
214214
{
215215
return [
216216
'No type map' => [
@@ -448,7 +448,7 @@ public function testMapReduce(): void
448448
}
449449
}
450450

451-
public function collectionMethodClosures()
451+
public static function collectionMethodClosures()
452452
{
453453
return [
454454
'read-only aggregate' => [
@@ -716,18 +716,18 @@ function($collection, $session, $options = []) {
716716
];
717717
}
718718

719-
public function collectionReadMethodClosures(): array
719+
public static function collectionReadMethodClosures(): array
720720
{
721721
return array_filter(
722-
$this->collectionMethodClosures(),
722+
self::collectionMethodClosures(),
723723
fn ($rw) => str_contains($rw[1], 'r'),
724724
);
725725
}
726726

727-
public function collectionWriteMethodClosures(): array
727+
public static function collectionWriteMethodClosures(): array
728728
{
729729
return array_filter(
730-
$this->collectionMethodClosures(),
730+
self::collectionMethodClosures(),
731731
fn ($rw) => str_contains($rw[1], 'w'),
732732
);
733733
}

tests/Command/ListCollectionsTest.php

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

18-
public function provideInvalidConstructorOptions(): array
18+
public static function provideInvalidConstructorOptions(): array
1919
{
20-
return $this->createOptionDataProvider([
21-
'authorizedCollections' => $this->getInvalidBooleanValues(),
22-
'filter' => $this->getInvalidDocumentValues(),
23-
'maxTimeMS' => $this->getInvalidIntegerValues(),
24-
'session' => $this->getInvalidSessionValues(),
20+
return self::createOptionDataProvider([
21+
'authorizedCollections' => self::getInvalidBooleanValues(),
22+
'filter' => self::getInvalidDocumentValues(),
23+
'maxTimeMS' => self::getInvalidIntegerValues(),
24+
'session' => self::getInvalidSessionValues(),
2525
]);
2626
}
2727
}

tests/Command/ListDatabasesTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ public function testConstructorOptionTypeChecks(array $options): void
1515
new ListDatabases($options);
1616
}
1717

18-
public function provideInvalidConstructorOptions()
18+
public static function provideInvalidConstructorOptions()
1919
{
20-
return $this->createOptionDataProvider([
21-
'authorizedDatabases' => $this->getInvalidBooleanValues(),
22-
'filter' => $this->getInvalidDocumentValues(),
23-
'maxTimeMS' => $this->getInvalidIntegerValues(),
24-
'nameOnly' => $this->getInvalidBooleanValues(),
25-
'session' => $this->getInvalidSessionValues(),
20+
return self::createOptionDataProvider([
21+
'authorizedDatabases' => self::getInvalidBooleanValues(),
22+
'filter' => self::getInvalidDocumentValues(),
23+
'maxTimeMS' => self::getInvalidIntegerValues(),
24+
'nameOnly' => self::getInvalidBooleanValues(),
25+
'session' => self::getInvalidSessionValues(),
2626
]);
2727
}
2828
}

tests/Database/DatabaseFunctionalTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testConstructorDatabaseNameArgument($databaseName, string $expec
3030
new Database($this->manager, $databaseName);
3131
}
3232

33-
public function provideInvalidDatabaseNames()
33+
public static function provideInvalidDatabaseNames()
3434
{
3535
return [
3636
[null, TypeError::class],
@@ -45,13 +45,13 @@ public function testConstructorOptionTypeChecks(array $options): void
4545
new Database($this->manager, $this->getDatabaseName(), $options);
4646
}
4747

48-
public function provideInvalidConstructorOptions()
48+
public static function provideInvalidConstructorOptions()
4949
{
50-
return $this->createOptionDataProvider([
51-
'readConcern' => $this->getInvalidReadConcernValues(),
52-
'readPreference' => $this->getInvalidReadPreferenceValues(),
53-
'typeMap' => $this->getInvalidArrayValues(),
54-
'writeConcern' => $this->getInvalidWriteConcernValues(),
50+
return self::createOptionDataProvider([
51+
'readConcern' => self::getInvalidReadConcernValues(),
52+
'readPreference' => self::getInvalidReadPreferenceValues(),
53+
'typeMap' => self::getInvalidArrayValues(),
54+
'writeConcern' => self::getInvalidWriteConcernValues(),
5555
]);
5656
}
5757

tests/Exception/InvalidArgumentExceptionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function testExpectedTypeFormatting($expectedType, $typeString): void
1515
$this->assertStringContainsString($typeString, $e->getMessage());
1616
}
1717

18-
public function provideExpectedTypes()
18+
public static function provideExpectedTypes()
1919
{
2020
yield 'expectedType is a string' => [
2121
'array',

tests/FunctionsTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function testApplyTypeMapToDocument($document, array $typeMap, $expectedD
3232
$this->assertEquals($expectedDocument, apply_type_map_to_document($document, $typeMap));
3333
}
3434

35-
public function provideDocumentAndTypeMap()
35+
public static function provideDocumentAndTypeMap()
3636
{
3737
return [
3838
[
@@ -102,7 +102,7 @@ public function testDocumentToArray($document, array $expectedArray): void
102102
$this->assertSame($expectedArray, document_to_array($document));
103103
}
104104

105-
public function provideDocumentsAndExpectedArrays(): array
105+
public static function provideDocumentsAndExpectedArrays(): array
106106
{
107107
return [
108108
'array' => [['x' => 1], ['x' => 1]],
@@ -122,13 +122,13 @@ public function testDocumentToArrayArgumentTypeCheck($document): void
122122
document_to_array($document);
123123
}
124124

125-
public function provideInvalidDocumentValuesForChecks(): array
125+
public static function provideInvalidDocumentValuesForChecks(): array
126126
{
127127
// PackedArray is intentionally left out, as document_to_array is used to convert aggregation pipelines
128-
return $this->wrapValuesForDataProvider([123, 3.14, 'foo', true]);
128+
return self::wrapValuesForDataProvider([123, 3.14, 'foo', true]);
129129
}
130130

131-
public function provideDocumentCasts(): array
131+
public static function provideDocumentCasts(): array
132132
{
133133
// phpcs:disable SlevomatCodingStandard.ControlStructures.JumpStatementsSpacing
134134
// phpcs:disable Squiz.Functions.MultiLineFunctionDeclaration
@@ -180,7 +180,7 @@ public function testCreateFieldPathTypeMap(array $expected, array $typeMap, $fie
180180
$this->assertEquals($expected, create_field_path_type_map($typeMap, $fieldPath));
181181
}
182182

183-
public function provideTypeMapValues()
183+
public static function provideTypeMapValues()
184184
{
185185
return [
186186
'No root type' => [
@@ -256,7 +256,7 @@ public function testIsPipeline($expected, $pipeline, $allowEmpty = false): void
256256
$this->assertSame($expected, is_pipeline($pipeline, $allowEmpty));
257257
}
258258

259-
public function providePipelines(): array
259+
public static function providePipelines(): array
260260
{
261261
$valid = [
262262
['$match' => ['foo' => 'bar']],
@@ -320,7 +320,7 @@ public function testIsBuilderPipeline($expected, $pipeline): void
320320
$this->assertSame($expected, is_builder_pipeline($pipeline));
321321
}
322322

323-
public function provideStagePipelines(): iterable
323+
public static function provideStagePipelines(): iterable
324324
{
325325
yield 'empty array' => [false, []];
326326
yield 'array of arrays' => [false, [['$match' => ['x' => 1]]]];
@@ -335,7 +335,7 @@ public function testIsWriteConcernAcknowledged($expected, WriteConcern $writeCon
335335
$this->assertSame($expected, is_write_concern_acknowledged($writeConcern));
336336
}
337337

338-
public function provideWriteConcerns(): array
338+
public static function provideWriteConcerns(): array
339339
{
340340
// Note: WriteConcern constructor prohibits w=-1 or w=0 and journal=true
341341
return [

0 commit comments

Comments
 (0)