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

Remove occurrences of "$this" in data providers #2510

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Documents\User;
use GeoJson\Geometry\Geometry;
use MongoDB\BSON\UTCDateTime;
use PHPUnit\Framework\MockObject\MockObject;

class MatchStageTest extends BaseTestCase
{
Expand Down Expand Up @@ -77,19 +76,19 @@ public function provideProxiedExprMethods(): array
'type()' => ['type', [7]],
'all()' => ['all', [['value1', 'value2']]],
'mod()' => ['mod', [2, 0]],
'geoIntersects()' => ['geoIntersects', [$this->getMockGeometry()]],
'geoWithin()' => ['geoWithin', [$this->getMockGeometry()]],
'geoIntersects()' => ['geoIntersects', [self::createGeometry()]],
'geoWithin()' => ['geoWithin', [self::createGeometry()]],
'geoWithinBox()' => ['geoWithinBox', [1, 2, 3, 4]],
'geoWithinCenter()' => ['geoWithinCenter', [1, 2, 3]],
'geoWithinCenterSphere()' => ['geoWithinCenterSphere', [1, 2, 3]],
'geoWithinPolygon()' => ['geoWithinPolygon', [[0, 0], [1, 1], [1, 0]]],
'addAnd() array' => ['addAnd', [[]]],
'addAnd() Expr' => ['addAnd', [$this->getMockQueryExpr()]],
'addAnd() Expr' => ['addAnd', [self::createExpr()]],
'addOr() array' => ['addOr', [[]]],
'addOr() Expr' => ['addOr', [$this->getMockQueryExpr()]],
'addOr() Expr' => ['addOr', [self::createExpr()]],
'addNor() array' => ['addNor', [[]]],
'addNor() Expr' => ['addNor', [$this->getMockQueryExpr()]],
'not()' => ['not', [$this->getMockQueryExpr()]],
'addNor() Expr' => ['addNor', [self::createExpr()]],
'not()' => ['not', [self::createExpr()]],
'language()' => ['language', ['en']],
'text()' => ['text', ['foo']],
];
Expand All @@ -116,9 +115,14 @@ public function testTypeConversion(): void
);
}

/** @return MockObject&Geometry */
private function getMockGeometry()
private static function createGeometry(): Geometry
{
return $this->createMock(Geometry::class);
return new class extends Geometry {
};
}

private static function createExpr(): Expr
{
return new Expr(static::createTestDocumentManager());
}
}
12 changes: 6 additions & 6 deletions tests/Doctrine/ODM/MongoDB/Tests/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ abstract class BaseTestCase extends TestCase

public function setUp(): void
{
$this->dm = $this->createTestDocumentManager();
$this->dm = static::createTestDocumentManager();
$this->uow = $this->dm->getUnitOfWork();
}

Expand Down Expand Up @@ -64,7 +64,7 @@ public function tearDown(): void
}
}

protected function getConfiguration(): Configuration
protected static function getConfiguration(): Configuration
{
$config = new Configuration();

Expand All @@ -75,7 +75,7 @@ protected function getConfiguration(): Configuration
$config->setPersistentCollectionDir(__DIR__ . '/../../../../PersistentCollections');
$config->setPersistentCollectionNamespace('PersistentCollections');
$config->setDefaultDB(DOCTRINE_MONGODB_DATABASE);
$config->setMetadataDriverImpl($this->createMetadataDriverImpl());
$config->setMetadataDriverImpl(static::createMetadataDriverImpl());

$config->addFilter('testFilter', Filter::class);
$config->addFilter('testFilter2', Filter::class);
Expand All @@ -100,14 +100,14 @@ public static function assertArraySubset(array $subset, array $array, bool $chec
}
}

protected function createMetadataDriverImpl(): MappingDriver
protected static function createMetadataDriverImpl(): MappingDriver
{
return AnnotationDriver::create(__DIR__ . '/../../../../Documents');
}

protected function createTestDocumentManager(): DocumentManager
protected static function createTestDocumentManager(): DocumentManager
{
$config = $this->getConfiguration();
$config = static::getConfiguration();
$client = new Client(getenv('DOCTRINE_MONGODB_SERVER') ?: DOCTRINE_MONGODB_SERVER, [], ['typeMap' => ['root' => 'array', 'document' => 'array']]);

return DocumentManager::create($client, $config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function testDefaultDatabase(): void
self::assertEquals('test_default', $this->dm->getDocumentDatabase(DefaultDatabaseTest::class)->getDatabaseName());
}

protected function getConfiguration(): Configuration
protected static function getConfiguration(): Configuration
{
$config = parent::getConfiguration();

Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/ODM/MongoDB/Tests/Functional/EnumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function testQueryWithMappedNonEnumFieldIsPassedToTypeDirectly(): void
self::assertSame(['_id' => 'C'], $qb->getQuery()->debug('query'));
}

protected function createMetadataDriverImpl(): MappingDriver
protected static function createMetadataDriverImpl(): MappingDriver
{
return AttributeDriver::create(__DIR__ . '/../../../Documents');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function testUpsert(): void
self::assertEquals('test', $thread->permalink);
}

protected function createMetadataDriverImpl(): MappingDriver
protected static function createMetadataDriverImpl(): MappingDriver
{
return new XmlDriver(__DIR__ . '/GH774');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@

abstract class AbstractMappingDriverTestCase extends BaseTestCase
{
abstract protected function loadDriver(): MappingDriver;
abstract protected static function loadDriver(): MappingDriver;

protected function createMetadataDriverImpl(): MappingDriver
protected static function createMetadataDriverImpl(): MappingDriver
{
return $this->loadDriver();
return static::loadDriver();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class AnnotationDriverTest extends AbstractAnnotationDriverTestCase
{
protected function loadDriver(): MappingDriver
protected static function loadDriver(): MappingDriver
{
$reader = new AnnotationReader();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/** @requires PHP >= 8.0 */
class AttributeDriverTest extends AbstractAnnotationDriverTestCase
{
protected function loadDriver(): MappingDriver
protected static function loadDriver(): MappingDriver
{
return new AttributeDriver();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

class XmlMappingDriverTest extends AbstractMappingDriverTestCase
{
protected function loadDriver(): MappingDriver
protected static function loadDriver(): MappingDriver
{
return new XmlDriver(__DIR__ . DIRECTORY_SEPARATOR . 'xml');
}
Expand Down
41 changes: 15 additions & 26 deletions tests/Doctrine/ODM/MongoDB/Tests/Query/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,8 @@ public function provideProxiedExprMethods(): array
'mod()' => ['mod', [2, 0]],
'near()' => ['near', [1, 2]],
'nearSphere()' => ['nearSphere', [1, 2]],
'geoIntersects()' => ['geoIntersects', [$this->getMockGeometry()]],
'geoWithin()' => ['geoWithin', [$this->getMockGeometry()]],
'geoIntersects()' => ['geoIntersects', [self::createGeometry()]],
'geoWithin()' => ['geoWithin', [self::createGeometry()]],
'geoWithinBox()' => ['geoWithinBox', [1, 2, 3, 4]],
'geoWithinCenter()' => ['geoWithinCenter', [1, 2, 3]],
'geoWithinCenterSphere()' => ['geoWithinCenterSphere', [1, 2, 3]],
Expand All @@ -522,22 +522,22 @@ public function provideProxiedExprMethods(): array
'unsetField()' => ['unsetField'],
'setOnInsert()' => ['setOnInsert', [1]],
'push() with value' => ['push', ['value']],
'push() with Expr' => ['push', [$this->getMockExpr()]],
'push() with Expr' => ['push', [self::createExpr()]],
'addToSet() with value' => ['addToSet', ['value']],
'addToSet() with Expr' => ['addToSet', [$this->getMockExpr()]],
'addToSet() with Expr' => ['addToSet', [self::createExpr()]],
'popFirst()' => ['popFirst'],
'popLast()' => ['popLast'],
'pull()' => ['pull', ['value']],
'pullAll()' => ['pullAll', [['value1', 'value2']]],
'addAnd() array' => ['addAnd', [[]]],
'addAnd() Expr' => ['addAnd', [$this->getMockExpr()]],
'addAnd() Expr' => ['addAnd', [self::createExpr()]],
'addOr() array' => ['addOr', [[]]],
'addOr() Expr' => ['addOr', [$this->getMockExpr()]],
'addOr() Expr' => ['addOr', [self::createExpr()]],
'addNor() array' => ['addNor', [[]]],
'addNor() Expr' => ['addNor', [$this->getMockExpr()]],
'addNor() Expr' => ['addNor', [self::createExpr()]],
'elemMatch() array' => ['elemMatch', [[]]],
'elemMatch() Expr' => ['elemMatch', [$this->getMockExpr()]],
'not()' => ['not', [$this->getMockExpr()]],
'elemMatch() Expr' => ['elemMatch', [self::createExpr()]],
'not()' => ['not', [self::createExpr()]],
'language()' => ['language', ['en']],
'caseSensitive()' => ['caseSensitive', [true]],
'diacriticSensitive()' => ['diacriticSensitive', [true]],
Expand All @@ -560,7 +560,7 @@ public function providePoint(): array
return [
'legacy array' => [$coordinates, $coordinates, false],
'GeoJSON array' => [$json, $json, true],
'GeoJSON object' => [$this->getMockPoint($json), $json, true],
'GeoJSON object' => [new Point($coordinates), $json, true],
];
}

Expand Down Expand Up @@ -864,26 +864,15 @@ private function getMockExpr()
return $this->createMock(Expr::class);
}

/** @return MockObject&Geometry */
private function getMockGeometry()
private static function createExpr(): Expr
{
return $this->createMock(Geometry::class);
return new Expr(static::createTestDocumentManager());
}

/**
* @param array<string, mixed> $json
*
* @return MockObject&Point
*/
private function getMockPoint(array $json)
private static function createGeometry(): Geometry
{
$point = $this->createMock(Point::class);

$point->expects($this->once())
->method('jsonSerialize')
->willReturn($json);

return $point;
return new class extends Geometry {
};
}
}

Expand Down
46 changes: 8 additions & 38 deletions tests/Doctrine/ODM/MongoDB/Tests/Query/ExprTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use GeoJson\Geometry\Point;
use GeoJson\Geometry\Polygon;
use MongoDB\BSON\ObjectId;
use PHPUnit\Framework\MockObject\MockObject;

class ExprTest extends BaseTestCase
{
Expand Down Expand Up @@ -399,12 +398,13 @@ public function testOperatorWithoutCurrentFieldWrapsEqualityCriteria(): void

public function provideGeoJsonPoint(): array
{
$json = ['type' => 'Point', 'coordinates' => [1, 2]];
$expected = ['$geometry' => $json];
$coordinates = [1, 2];
$json = ['type' => 'Point', 'coordinates' => $coordinates];
$expected = ['$geometry' => $json];

return [
'array' => [$json, $expected],
'object' => [$this->getMockPoint($json), $expected],
'object' => [new Point($coordinates), $expected],
];
}

Expand Down Expand Up @@ -561,16 +561,18 @@ public function testGeoIntersects($geometry, array $expected): void

public function provideGeoJsonPolygon(): array
{
$coordinates = [[[0, 0], [1, 1], [1, 0], [0, 0]]];

$json = [
'type' => 'Polygon',
'coordinates' => [[[0, 0], [1, 1], [1, 0], [0, 0]]],
'coordinates' => $coordinates,
];

$expected = ['$geometry' => $json];

return [
'array' => [$json, $expected],
'object' => [$this->getMockPolygon($json), $expected],
'object' => [new Polygon($coordinates), $expected],
];
}

Expand Down Expand Up @@ -702,36 +704,4 @@ private function createExpr(): Expr

return $expr;
}

/**
* @param array<string, mixed> $json
*
* @return MockObject&Point
*/
private function getMockPoint(array $json)
{
$point = $this->createMock(Point::class);

$point->expects($this->once())
->method('jsonSerialize')
->willReturn($json);

return $point;
}

/**
* @param array<string, mixed> $json
*
* @return MockObject&Polygon
*/
private function getMockPolygon(array $json)
{
$point = $this->createMock(Polygon::class);

$point->expects($this->once())
->method('jsonSerialize')
->willReturn($json);

return $point;
}
}
4 changes: 2 additions & 2 deletions tests/Doctrine/ODM/MongoDB/Tests/RepositoryFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function testRepositoryFactoryCanBeReplaced(): void
$factory = $this->createMock(RepositoryFactory::class);
$factory->expects($this->once())->method('getRepository');

$conf = $this->getConfiguration();
$conf = static::getConfiguration();
$conf->setRepositoryFactory($factory);
$dm = DocumentManager::create(null, $conf);

Expand All @@ -36,7 +36,7 @@ public function testRepositoriesAreSameForSameClasses(): void

public function testRepositoriesAreDifferentForDifferentDms(): void
{
$conf = $this->getConfiguration();
$conf = static::getConfiguration();
$conf->setRepositoryFactory(new DefaultRepositoryFactory());

$dm1 = DocumentManager::create(null, $conf);
Expand Down