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

Use ::class where possible #1770

Merged
merged 1 commit into from
Apr 4, 2018
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
8 changes: 4 additions & 4 deletions tests/Doctrine/ODM/MongoDB/Tests/Aggregation/ExprTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function testCallingCaseWithoutSwitchThrowsException()
$expr = $this->createExpr();

$this->expectException(\BadMethodCallException::class);
$this->expectExceptionMessage('Doctrine\ODM\MongoDB\Aggregation\Expr::case requires a valid switch statement (call switch() first).');
$this->expectExceptionMessage(Expr::class . '::case requires a valid switch statement (call switch() first).');

$expr->case('$field');
}
Expand All @@ -124,7 +124,7 @@ public function testCallingThenWithoutCaseThrowsException()
$expr = $this->createExpr();

$this->expectException(\BadMethodCallException::class);
$this->expectExceptionMessage('Doctrine\ODM\MongoDB\Aggregation\Expr::then requires a valid case statement (call case() first).');
$this->expectExceptionMessage(Expr::class . '::then requires a valid case statement (call case() first).');

$expr->then('$field');
}
Expand All @@ -138,7 +138,7 @@ public function testCallingThenWithoutCaseAfterSuccessfulCaseThrowsException()
->then('$field');

$this->expectException(\BadMethodCallException::class);
$this->expectExceptionMessage('Doctrine\ODM\MongoDB\Aggregation\Expr::then requires a valid case statement (call case() first).');
$this->expectExceptionMessage(Expr::class . '::then requires a valid case statement (call case() first).');

$expr->then('$field');
}
Expand All @@ -148,7 +148,7 @@ public function testCallingDefaultWithoutSwitchThrowsException()
$expr = $this->createExpr();

$this->expectException(\BadMethodCallException::class);
$this->expectExceptionMessage('Doctrine\ODM\MongoDB\Aggregation\Expr::default requires a valid switch statement (call switch() first).');
$this->expectExceptionMessage(Expr::class . '::default requires a valid switch statement (call switch() first).');

$expr->default('$field');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Doctrine\ODM\MongoDB\Query\Expr;
use Doctrine\ODM\MongoDB\Tests\Aggregation\AggregationTestTrait;
use Doctrine\ODM\MongoDB\Tests\BaseTest;
use Documents\User;
use GeoJson\Geometry\Geometry;
use MongoDB\BSON\UTCDateTime;

class MatchTest extends BaseTest
Expand Down Expand Up @@ -95,7 +97,7 @@ public function provideProxiedExprMethods()

public function testTypeConversion()
{
$builder = $this->dm->createAggregationBuilder('Documents\User');
$builder = $this->dm->createAggregationBuilder(User::class);

$date = new \DateTime();
$mongoDate = new UTCDateTime((int) $date->format('Uv'));
Expand All @@ -116,7 +118,7 @@ public function testTypeConversion()

private function getMockGeometry()
{
return $this->getMockBuilder('GeoJson\Geometry\Geometry')
return $this->getMockBuilder(Geometry::class)
->disableOriginalConstructor()
->getMock();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Doctrine\ODM\MongoDB\Tests\Aggregation\Stage;

use Doctrine\ODM\MongoDB\Aggregation\Expr;
use Doctrine\ODM\MongoDB\Aggregation\Stage\Operator;
use Doctrine\ODM\MongoDB\Tests\Aggregation\AggregationOperatorsProviderTrait;
use Doctrine\ODM\MongoDB\Tests\Aggregation\AggregationTestTrait;
Expand Down Expand Up @@ -78,7 +79,7 @@ public function testCallingCaseWithoutSwitchThrowsException()
$stage = $this->getStubStage();

$this->expectException(\BadMethodCallException::class);
$this->expectExceptionMessage('Doctrine\ODM\MongoDB\Aggregation\Expr::case requires a valid switch statement (call switch() first).');
$this->expectExceptionMessage(Expr::class . '::case requires a valid switch statement (call switch() first).');

$stage->case('$field');
}
Expand All @@ -88,7 +89,7 @@ public function testCallingThenWithoutCaseThrowsException()
$stage = $this->getStubStage();

$this->expectException(\BadMethodCallException::class);
$this->expectExceptionMessage('Doctrine\ODM\MongoDB\Aggregation\Expr::then requires a valid case statement (call case() first).');
$this->expectExceptionMessage(Expr::class . '::then requires a valid case statement (call case() first).');

$stage->then('$field');
}
Expand All @@ -102,7 +103,7 @@ public function testCallingThenWithoutCaseAfterSuccessfulCaseThrowsException()
->then('$field');

$this->expectException(\BadMethodCallException::class);
$this->expectExceptionMessage('Doctrine\ODM\MongoDB\Aggregation\Expr::then requires a valid case statement (call case() first).');
$this->expectExceptionMessage(Expr::class . '::then requires a valid case statement (call case() first).');

$stage->then('$field');
}
Expand All @@ -112,7 +113,7 @@ public function testCallingDefaultWithoutSwitchThrowsException()
$stage = $this->getStubStage();

$this->expectException(\BadMethodCallException::class);
$this->expectExceptionMessage('Doctrine\ODM\MongoDB\Aggregation\Expr::default requires a valid switch statement (call switch() first).');
$this->expectExceptionMessage(Expr::class . '::default requires a valid switch statement (call switch() first).');

$stage->default('$field');
}
Expand Down
5 changes: 3 additions & 2 deletions tests/Doctrine/ODM/MongoDB/Tests/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Doctrine\ODM\MongoDB\Configuration;
use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver;
use Doctrine\ODM\MongoDB\Tests\Query\Filter\Filter;
use Doctrine\ODM\MongoDB\UnitOfWork;
use MongoDB\Client;
use MongoDB\Model\DatabaseInfo;
Expand Down Expand Up @@ -71,8 +72,8 @@ protected function getConfiguration()
$config->setDefaultDB(DOCTRINE_MONGODB_DATABASE);
$config->setMetadataDriverImpl($this->createMetadataDriverImpl());

$config->addFilter('testFilter', 'Doctrine\ODM\MongoDB\Tests\Query\Filter\Filter');
$config->addFilter('testFilter2', 'Doctrine\ODM\MongoDB\Tests\Query\Filter\Filter');
$config->addFilter('testFilter', Filter::class);
$config->addFilter('testFilter2', Filter::class);

return $config;
}
Expand Down
42 changes: 29 additions & 13 deletions tests/Doctrine/ODM/MongoDB/Tests/DocumentManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,26 @@

namespace Doctrine\ODM\MongoDB\Tests;

use Doctrine\Common\EventManager;
use Doctrine\ODM\MongoDB\Aggregation\Builder as AggregationBuilder;
use Doctrine\ODM\MongoDB\Configuration;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
use Doctrine\ODM\MongoDB\Mapping\ClassMetadataFactory;
use Doctrine\ODM\MongoDB\MongoDBException;
use Doctrine\ODM\MongoDB\Proxy\ProxyFactory;
use Doctrine\ODM\MongoDB\Query\Builder as QueryBuilder;
use Doctrine\ODM\MongoDB\Query\FilterCollection;
use Doctrine\ODM\MongoDB\SchemaManager;
use Doctrine\ODM\MongoDB\UnitOfWork;
use Documents\BaseCategory;
use Documents\BaseCategoryRepository;
use Documents\BlogPost;
use Documents\Category;
use Documents\CmsPhonenumber;
use Documents\CmsUser;
use Documents\CustomRepository\Document;
use Documents\CustomRepository\Repository;
use Documents\Tournament\ParticipantSolo;
use Documents\User;
use MongoDB\BSON\ObjectId;
Expand All @@ -18,17 +34,17 @@ class DocumentManagerTest extends BaseTest
{
public function testCustomRepository()
{
$this->assertInstanceOf('Documents\CustomRepository\Repository', $this->dm->getRepository('Documents\CustomRepository\Document'));
$this->assertInstanceOf(Repository::class, $this->dm->getRepository(Document::class));
}

public function testCustomRepositoryMappedsuperclass()
{
$this->assertInstanceOf('Documents\BaseCategoryRepository', $this->dm->getRepository('Documents\BaseCategory'));
$this->assertInstanceOf(BaseCategoryRepository::class, $this->dm->getRepository(BaseCategory::class));
}

public function testCustomRepositoryMappedsuperclassChild()
{
$this->assertInstanceOf('Documents\BaseCategoryRepository', $this->dm->getRepository('Documents\Category'));
$this->assertInstanceOf(BaseCategoryRepository::class, $this->dm->getRepository(Category::class));
}

public function testGetConnection()
Expand All @@ -38,53 +54,53 @@ public function testGetConnection()

public function testGetMetadataFactory()
{
$this->assertInstanceOf('\Doctrine\ODM\MongoDB\Mapping\ClassMetadataFactory', $this->dm->getMetadataFactory());
$this->assertInstanceOf(ClassMetadataFactory::class, $this->dm->getMetadataFactory());
}

public function testGetConfiguration()
{
$this->assertInstanceOf('\Doctrine\ODM\MongoDB\Configuration', $this->dm->getConfiguration());
$this->assertInstanceOf(Configuration::class, $this->dm->getConfiguration());
}

public function testGetUnitOfWork()
{
$this->assertInstanceOf('\Doctrine\ODM\MongoDB\UnitOfWork', $this->dm->getUnitOfWork());
$this->assertInstanceOf(UnitOfWork::class, $this->dm->getUnitOfWork());
}

public function testGetProxyFactory()
{
$this->assertInstanceOf('\Doctrine\ODM\MongoDB\Proxy\ProxyFactory', $this->dm->getProxyFactory());
$this->assertInstanceOf(ProxyFactory::class, $this->dm->getProxyFactory());
}

public function testGetEventManager()
{
$this->assertInstanceOf('\Doctrine\Common\EventManager', $this->dm->getEventManager());
$this->assertInstanceOf(EventManager::class, $this->dm->getEventManager());
}

public function testGetSchemaManager()
{
$this->assertInstanceOf('\Doctrine\ODM\MongoDB\SchemaManager', $this->dm->getSchemaManager());
$this->assertInstanceOf(SchemaManager::class, $this->dm->getSchemaManager());
}

public function testCreateQueryBuilder()
{
$this->assertInstanceOf('\Doctrine\ODM\MongoDB\Query\Builder', $this->dm->createQueryBuilder());
$this->assertInstanceOf(QueryBuilder::class, $this->dm->createQueryBuilder());
}

public function testCreateAggregationBuilder()
{
$this->assertInstanceOf('\Doctrine\ODM\MongoDB\Aggregation\Builder', $this->dm->createAggregationBuilder('Documents\BlogPost'));
$this->assertInstanceOf(AggregationBuilder::class, $this->dm->createAggregationBuilder(BlogPost::class));
}

public function testGetFilterCollection()
{
$this->assertInstanceOf('\Doctrine\ODM\MongoDB\Query\FilterCollection', $this->dm->getFilterCollection());
$this->assertInstanceOf(FilterCollection::class, $this->dm->getFilterCollection());
}

public function testGetPartialReference()
{
$id = new ObjectId();
$user = $this->dm->getPartialReference('Documents\CmsUser', $id);
$user = $this->dm->getPartialReference(CmsUser::class, $id);
$this->assertTrue($this->dm->contains($user));
$this->assertEquals($id, $user->id);
$this->assertNull($user->getName());
Expand Down
5 changes: 3 additions & 2 deletions tests/Doctrine/ODM/MongoDB/Tests/DocumentRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Doctrine\ODM\MongoDB\Tests;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Documents\Account;
use Documents\Address;
Expand All @@ -20,11 +21,11 @@ class DocumentRepositoryTest extends BaseTest
{
public function testMatchingAcceptsCriteriaWithNullWhereExpression()
{
$repository = $this->dm->getRepository('Documents\User');
$repository = $this->dm->getRepository(User::class);
$criteria = new Criteria();

$this->assertNull($criteria->getWhereExpression());
$this->assertInstanceOf('Doctrine\Common\Collections\Collection', $repository->matching($criteria));
$this->assertInstanceOf(Collection::class, $repository->matching($criteria));
}

public function testFindByRefOneFull()
Expand Down
23 changes: 12 additions & 11 deletions tests/Doctrine/ODM/MongoDB/Tests/Events/LifecycleCallbacksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Doctrine\ODM\MongoDB\Tests\Events;

use DateTime;
use Doctrine\ODM\MongoDB\Event;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use Doctrine\ODM\MongoDB\Tests\BaseTest;
Expand All @@ -27,18 +28,18 @@ public function testPreUpdateChangingValue()
$user = $this->createUser();
$this->dm->clear();

$user = $this->dm->find(__NAMESPACE__ . '\User', $user->id);
$this->assertInstanceOf('DateTime', $user->createdAt);
$this->assertInstanceOf('DateTime', $user->profile->createdAt);
$user = $this->dm->find(User::class, $user->id);
$this->assertInstanceOf(DateTime::class, $user->createdAt);
$this->assertInstanceOf(DateTime::class, $user->profile->createdAt);

$user->name = 'jon changed';
$user->profile->name = 'changed';
$this->dm->flush();
$this->dm->clear();

$user = $this->dm->find(__NAMESPACE__ . '\User', $user->id);
$this->assertInstanceOf('DateTime', $user->updatedAt);
$this->assertInstanceOf('DateTime', $user->profile->updatedAt);
$user = $this->dm->find(User::class, $user->id);
$this->assertInstanceOf(DateTime::class, $user->updatedAt);
$this->assertInstanceOf(DateTime::class, $user->profile->updatedAt);
}

public function testPreAndPostPersist()
Expand Down Expand Up @@ -81,7 +82,7 @@ public function testPreLoadAndPostLoad()
$user = $this->createUser();
$this->dm->clear();

$user = $this->dm->find(__NAMESPACE__ . '\User', $user->id);
$user = $this->dm->find(User::class, $user->id);

$this->assertTrue($user->preLoad);
$this->assertTrue($user->profile->preLoad);
Expand Down Expand Up @@ -129,7 +130,7 @@ public function testEmbedManyEvent()
$this->assertTrue($profile->postUpdate);

$this->dm->clear();
$user = $this->dm->find(__NAMESPACE__ . '\User', $user->id);
$user = $this->dm->find(User::class, $user->id);
$profile = $user->profiles[0];

$this->assertTrue($profile->preLoad);
Expand Down Expand Up @@ -175,7 +176,7 @@ public function testMultipleLevelsOfEmbedded()
$this->assertTrue($profile->postUpdate);

$this->dm->clear();
$user = $this->dm->find(__NAMESPACE__ . '\User', $user->id);
$user = $this->dm->find(User::class, $user->id);
$profile = $user->profile->profile;
$profile->name = '2nd level changed again';

Expand Down Expand Up @@ -312,7 +313,7 @@ abstract class BaseDocument
public function prePersist(Event\LifecycleEventArgs $e)
{
$this->prePersist = true;
$this->createdAt = new \DateTime();
$this->createdAt = new DateTime();
}

/** @ODM\PostPersist */
Expand All @@ -325,7 +326,7 @@ public function postPersist(Event\LifecycleEventArgs $e)
public function preUpdate(Event\PreUpdateEventArgs $e)
{
$this->preUpdate = true;
$this->updatedAt = new \DateTime();
$this->updatedAt = new DateTime();
}

/** @ODM\PostUpdate */
Expand Down
Loading