Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPLIB-1514 Make data providers static #1404

Merged
merged 5 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Rector\DeadCode\Rector\ClassLike\RemoveAnnotationRector;
use Rector\Php70\Rector\StmtsAwareInterface\IfIssetToCoalescingRector;
use Rector\Php80\Rector\Switch_\ChangeSwitchToMatchRector;
use Rector\PHPUnit\PHPUnit100\Rector\Class_\StaticDataProviderClassMethodRector;
use Rector\Set\ValueObject\LevelSetList;

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

$rectorConfig->rule(ChangeSwitchToMatchRector::class);
$rectorConfig->rule(StaticDataProviderClassMethodRector::class);

// phpcs:disable Squiz.Arrays.ArrayDeclaration.KeySpecified
$rectorConfig->skip([
Expand Down
2 changes: 1 addition & 1 deletion tests/Builder/FieldPathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function testRejectDollarPrefix(string $fieldPathClass): void
Expression::{$fieldPathClass}('$foo');
}

public function provideFieldPath(): Generator
public static function provideFieldPath(): Generator
{
yield 'double' => ['doubleFieldPath', Expression\ResolvesToDouble::class];
yield 'string' => ['stringFieldPath', Expression\ResolvesToString::class];
Expand Down
2 changes: 1 addition & 1 deletion tests/Builder/Type/CombinedFieldQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function testRejectDuplicateOperator(array $fieldQueries): void
]);
}

public function provideDuplicateOperator(): Generator
public static function provideDuplicateOperator(): Generator
{
yield 'array and FieldQuery' => [
[
Expand Down
4 changes: 2 additions & 2 deletions tests/Builder/Type/OutputWindowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function testRejectInvalidDocuments(array $documents): void
);
}

public function provideInvalidDocuments(): Generator
public static function provideInvalidDocuments(): Generator
{
yield 'too few' => [[1]];
yield 'too many' => [[1, 2, 3]];
Expand All @@ -98,7 +98,7 @@ public function testRejectInvalidRange(array $range): void
);
}

public function provideInvalidRange(): Generator
public static function provideInvalidRange(): Generator
{
yield 'too few' => [[1]];
yield 'too many' => [[1, 2, 3]];
Expand Down
2 changes: 1 addition & 1 deletion tests/Builder/Type/QueryObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function testCreateQueryObjectFromArray(array $value, int $expectedCount
$this->assertCount($expectedCount, $queryObject->queries);
}

public function provideQueryObjectValue(): Generator
public static function provideQueryObjectValue(): Generator
{
yield 'int' => [['foo' => 1]];
yield 'float' => [['foo' => 1.1]];
Expand Down
2 changes: 1 addition & 1 deletion tests/Builder/VariableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function testSystemVariables($factory): void
$this->assertStringStartsNotWith('$$', $variable->name);
}

public function provideVariableBuilders(): Generator
public static function provideVariableBuilders(): Generator
{
yield 'now' => [fn () => Variable::now()];
yield 'clusterTime' => [fn () => Variable::clusterTime()];
Expand Down
12 changes: 6 additions & 6 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,29 @@ public function testConstructorDriverOptionTypeChecks(array $driverOptions, stri
new Client(static::getUri(), [], $driverOptions);
}

public function provideInvalidConstructorDriverOptions()
public static function provideInvalidConstructorDriverOptions()
{
$options = [];

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

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

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

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

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

foreach ($this->getInvalidStringValues() as $value) {
foreach (self::getInvalidStringValues() as $value) {
$options[] = [
'driverOptions' => ['driver' => ['platform' => $value]],
'exception' => DriverInvalidArgumentException::class,
Expand Down
2 changes: 1 addition & 1 deletion tests/Collection/CodecCollectionFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function testBulkWrite($expected, $options): void
);
}

public function provideFindOneAndModifyOptions(): Generator
public static function provideFindOneAndModifyOptions(): Generator
{
yield 'Default codec' => [
'expected' => TestObject::createDecodedForFixture(1),
Expand Down
30 changes: 15 additions & 15 deletions tests/Collection/CollectionFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function testConstructorCollectionNameArgument($collectionName, string $e
new Collection($this->manager, $this->getDatabaseName(), $collectionName);
}

public function provideInvalidDatabaseAndCollectionNames()
public static function provideInvalidDatabaseAndCollectionNames()
{
return [
[null, TypeError::class],
Expand All @@ -64,15 +64,15 @@ public function testConstructorOptionTypeChecks(array $options): void
new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName(), $options);
}

public function provideInvalidConstructorOptions(): array
public static function provideInvalidConstructorOptions(): array
{
return $this->createOptionDataProvider([
'builderEncoder' => $this->getInvalidObjectValues(),
'codec' => $this->getInvalidDocumentCodecValues(),
'readConcern' => $this->getInvalidReadConcernValues(),
'readPreference' => $this->getInvalidReadPreferenceValues(),
'typeMap' => $this->getInvalidArrayValues(),
'writeConcern' => $this->getInvalidWriteConcernValues(),
return self::createOptionDataProvider([
'builderEncoder' => self::getInvalidObjectValues(),
'codec' => self::getInvalidDocumentCodecValues(),
'readConcern' => self::getInvalidReadConcernValues(),
'readPreference' => self::getInvalidReadPreferenceValues(),
'typeMap' => self::getInvalidArrayValues(),
'writeConcern' => self::getInvalidWriteConcernValues(),
]);
}

Expand Down Expand Up @@ -210,7 +210,7 @@ public function testDistinctWithTypeMap(array $typeMap, array $expectedDocuments
$this->assertEquals($expectedDocuments, $values);
}

public function provideTypeMapOptionsAndExpectedDocuments()
public static function provideTypeMapOptionsAndExpectedDocuments()
{
return [
'No type map' => [
Expand Down Expand Up @@ -448,7 +448,7 @@ public function testMapReduce(): void
}
}

public function collectionMethodClosures()
public static function collectionMethodClosures()
{
return [
'read-only aggregate' => [
Expand Down Expand Up @@ -716,18 +716,18 @@ function($collection, $session, $options = []) {
];
}

public function collectionReadMethodClosures(): array
public static function collectionReadMethodClosures(): array
{
return array_filter(
$this->collectionMethodClosures(),
self::collectionMethodClosures(),
fn ($rw) => str_contains($rw[1], 'r'),
);
}

public function collectionWriteMethodClosures(): array
public static function collectionWriteMethodClosures(): array
{
return array_filter(
$this->collectionMethodClosures(),
self::collectionMethodClosures(),
fn ($rw) => str_contains($rw[1], 'w'),
);
}
Expand Down
12 changes: 6 additions & 6 deletions tests/Command/ListCollectionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ public function testConstructorOptionTypeChecks(array $options): void
new ListCollections($this->getDatabaseName(), $options);
}

public function provideInvalidConstructorOptions(): array
public static function provideInvalidConstructorOptions(): array
{
return $this->createOptionDataProvider([
'authorizedCollections' => $this->getInvalidBooleanValues(),
'filter' => $this->getInvalidDocumentValues(),
'maxTimeMS' => $this->getInvalidIntegerValues(),
'session' => $this->getInvalidSessionValues(),
return self::createOptionDataProvider([
'authorizedCollections' => self::getInvalidBooleanValues(),
'filter' => self::getInvalidDocumentValues(),
'maxTimeMS' => self::getInvalidIntegerValues(),
'session' => self::getInvalidSessionValues(),
]);
}
}
14 changes: 7 additions & 7 deletions tests/Command/ListDatabasesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ public function testConstructorOptionTypeChecks(array $options): void
new ListDatabases($options);
}

public function provideInvalidConstructorOptions()
public static function provideInvalidConstructorOptions()
{
return $this->createOptionDataProvider([
'authorizedDatabases' => $this->getInvalidBooleanValues(),
'filter' => $this->getInvalidDocumentValues(),
'maxTimeMS' => $this->getInvalidIntegerValues(),
'nameOnly' => $this->getInvalidBooleanValues(),
'session' => $this->getInvalidSessionValues(),
return self::createOptionDataProvider([
'authorizedDatabases' => self::getInvalidBooleanValues(),
'filter' => self::getInvalidDocumentValues(),
'maxTimeMS' => self::getInvalidIntegerValues(),
'nameOnly' => self::getInvalidBooleanValues(),
'session' => self::getInvalidSessionValues(),
]);
}
}
14 changes: 7 additions & 7 deletions tests/Database/DatabaseFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function testConstructorDatabaseNameArgument($databaseName, string $expec
new Database($this->manager, $databaseName);
}

public function provideInvalidDatabaseNames()
public static function provideInvalidDatabaseNames()
{
return [
[null, TypeError::class],
Expand All @@ -45,13 +45,13 @@ public function testConstructorOptionTypeChecks(array $options): void
new Database($this->manager, $this->getDatabaseName(), $options);
}

public function provideInvalidConstructorOptions()
public static function provideInvalidConstructorOptions()
{
return $this->createOptionDataProvider([
'readConcern' => $this->getInvalidReadConcernValues(),
'readPreference' => $this->getInvalidReadPreferenceValues(),
'typeMap' => $this->getInvalidArrayValues(),
'writeConcern' => $this->getInvalidWriteConcernValues(),
return self::createOptionDataProvider([
'readConcern' => self::getInvalidReadConcernValues(),
'readPreference' => self::getInvalidReadPreferenceValues(),
'typeMap' => self::getInvalidArrayValues(),
'writeConcern' => self::getInvalidWriteConcernValues(),
]);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Exception/InvalidArgumentExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function testExpectedTypeFormatting($expectedType, $typeString): void
$this->assertStringContainsString($typeString, $e->getMessage());
}

public function provideExpectedTypes()
public static function provideExpectedTypes()
{
yield 'expectedType is a string' => [
'array',
Expand Down
18 changes: 9 additions & 9 deletions tests/FunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function testApplyTypeMapToDocument($document, array $typeMap, $expectedD
$this->assertEquals($expectedDocument, apply_type_map_to_document($document, $typeMap));
}

public function provideDocumentAndTypeMap()
public static function provideDocumentAndTypeMap()
{
return [
[
Expand Down Expand Up @@ -102,7 +102,7 @@ public function testDocumentToArray($document, array $expectedArray): void
$this->assertSame($expectedArray, document_to_array($document));
}

public function provideDocumentsAndExpectedArrays(): array
public static function provideDocumentsAndExpectedArrays(): array
{
return [
'array' => [['x' => 1], ['x' => 1]],
Expand All @@ -122,13 +122,13 @@ public function testDocumentToArrayArgumentTypeCheck($document): void
document_to_array($document);
}

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

public function provideDocumentCasts(): array
public static function provideDocumentCasts(): array
{
// phpcs:disable SlevomatCodingStandard.ControlStructures.JumpStatementsSpacing
// phpcs:disable Squiz.Functions.MultiLineFunctionDeclaration
Expand Down Expand Up @@ -180,7 +180,7 @@ public function testCreateFieldPathTypeMap(array $expected, array $typeMap, $fie
$this->assertEquals($expected, create_field_path_type_map($typeMap, $fieldPath));
}

public function provideTypeMapValues()
public static function provideTypeMapValues()
{
return [
'No root type' => [
Expand Down Expand Up @@ -256,7 +256,7 @@ public function testIsPipeline($expected, $pipeline, $allowEmpty = false): void
$this->assertSame($expected, is_pipeline($pipeline, $allowEmpty));
}

public function providePipelines(): array
public static function providePipelines(): array
{
$valid = [
['$match' => ['foo' => 'bar']],
Expand Down Expand Up @@ -320,7 +320,7 @@ public function testIsBuilderPipeline($expected, $pipeline): void
$this->assertSame($expected, is_builder_pipeline($pipeline));
}

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

public function provideWriteConcerns(): array
public static function provideWriteConcerns(): array
{
// Note: WriteConcern constructor prohibits w=-1 or w=0 and journal=true
return [
Expand Down
Loading