Skip to content

Commit

Permalink
Use class constant in test
Browse files Browse the repository at this point in the history
  • Loading branch information
alcaeus committed May 17, 2016
1 parent 7a1e57a commit d793ed3
Showing 1 changed file with 43 additions and 43 deletions.
86 changes: 43 additions & 43 deletions tests/Doctrine/ODM/MongoDB/Tests/SchemaManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
class SchemaManagerTest extends \PHPUnit_Framework_TestCase
{
private $indexedClasses = array(
'Documents\CmsAddress',
'Documents\CmsArticle',
'Documents\CmsComment',
'Documents\CmsProduct',
'Documents\Comment',
'Documents\SimpleReferenceUser',
\Documents\CmsAddress::class,
\Documents\CmsArticle::class,
\Documents\CmsComment::class,
\Documents\CmsProduct::class,
\Documents\Comment::class,
\Documents\SimpleReferenceUser::class,
);

private $someNonIndexedClasses = array(
'Documents\CmsGroup',
'Documents\CmsPhonenumber',
'Documents\CmsUser',
\Documents\CmsGroup::class,
\Documents\CmsPhonenumber::class,
\Documents\CmsUser::class,
);

private $someMappedSuperclassAndEmbeddedClasses = array(
Expand Down Expand Up @@ -81,43 +81,43 @@ public function testEnsureIndexes()
public function testEnsureDocumentIndexes()
{
foreach ($this->documentCollections as $class => $collection) {
if ($class === 'Documents\CmsArticle') {
if ($class === \Documents\CmsArticle::class) {
$collection->expects($this->once())->method('ensureIndex');
} else {
$collection->expects($this->never())->method('ensureIndex');
}
}

$this->schemaManager->ensureDocumentIndexes('Documents\CmsArticle');
$this->schemaManager->ensureDocumentIndexes(\Documents\CmsArticle::class);
}

public function testEnsureDocumentIndexesWithTwoLevelInheritance()
{
$collection = $this->documentCollections['Documents\CmsProduct'];
$collection = $this->documentCollections[\Documents\CmsProduct::class];
$collection->expects($this->once())->method('ensureIndex');

$this->schemaManager->ensureDocumentIndexes('Documents\CmsProduct');
$this->schemaManager->ensureDocumentIndexes(\Documents\CmsProduct::class);
}

public function testEnsureDocumentIndexesWithTimeout()
{
$collection = $this->documentCollections['Documents\CmsArticle'];
$collection = $this->documentCollections[\Documents\CmsArticle::class];
$collection->expects($this->once())
->method('ensureIndex')
->with($this->anything(), $this->callback(function($o) {
return isset($o['timeout']) && $o['timeout'] === 10000;
}));

$this->schemaManager->ensureDocumentIndexes('Documents\CmsArticle', 10000);
$this->schemaManager->ensureDocumentIndexes(\Documents\CmsArticle::class, 10000);
}

public function testUpdateDocumentIndexesShouldCreateMappedIndexes()
{
$database = $this->documentDatabases['Documents\CmsArticle'];
$database = $this->documentDatabases[\Documents\CmsArticle::class];
$database->expects($this->never())
->method('command');

$collection = $this->documentCollections['Documents\CmsArticle'];
$collection = $this->documentCollections[\Documents\CmsArticle::class];
$collection->expects($this->once())
->method('getIndexInfo')
->will($this->returnValue(array()));
Expand All @@ -127,19 +127,19 @@ public function testUpdateDocumentIndexesShouldCreateMappedIndexes()
->method('getDatabase')
->will($this->returnValue($database));

$this->schemaManager->updateDocumentIndexes('Documents\CmsArticle');
$this->schemaManager->updateDocumentIndexes(\Documents\CmsArticle::class);
}

public function testUpdateDocumentIndexesShouldDeleteUnmappedIndexesBeforeCreatingMappedIndexes()
{
$database = $this->documentDatabases['Documents\CmsArticle'];
$database = $this->documentDatabases[\Documents\CmsArticle::class];
$database->expects($this->once())
->method('command')
->with($this->callback(function($c) {
return array_key_exists('deleteIndexes', $c);
}));

$collection = $this->documentCollections['Documents\CmsArticle'];
$collection = $this->documentCollections[\Documents\CmsArticle::class];
$collection->expects($this->once())
->method('getIndexInfo')
->will($this->returnValue(array(array(
Expand All @@ -153,7 +153,7 @@ public function testUpdateDocumentIndexesShouldDeleteUnmappedIndexesBeforeCreati
->method('getDatabase')
->will($this->returnValue($database));

$this->schemaManager->updateDocumentIndexes('Documents\CmsArticle');
$this->schemaManager->updateDocumentIndexes(\Documents\CmsArticle::class);
}

public function testDeleteIndexes()
Expand All @@ -172,42 +172,42 @@ public function testDeleteIndexes()
public function testDeleteDocumentIndexes()
{
foreach ($this->documentCollections as $class => $collection) {
if ($class === 'Documents\CmsArticle') {
if ($class === \Documents\CmsArticle::class) {
$collection->expects($this->once())->method('deleteIndexes');
} else {
$collection->expects($this->never())->method('deleteIndexes');
}
}

$this->schemaManager->deleteDocumentIndexes('Documents\CmsArticle');
$this->schemaManager->deleteDocumentIndexes(\Documents\CmsArticle::class);
}

public function testCreateDocumentCollection()
{
$cm = $this->classMetadatas['Documents\CmsArticle'];
$cm = $this->classMetadatas[\Documents\CmsArticle::class];
$cm->collectionCapped = true;
$cm->collectionSize = 1048576;
$cm->collectionMax = 32;

$database = $this->documentDatabases['Documents\CmsArticle'];
$database = $this->documentDatabases[\Documents\CmsArticle::class];
$database->expects($this->once())
->method('createCollection')
->with('CmsArticle', true, 1048576, 32);

$this->schemaManager->createDocumentCollection('Documents\CmsArticle');
$this->schemaManager->createDocumentCollection(\Documents\CmsArticle::class);
}

public function testCreateGridFSCollection()
{
$database = $this->documentDatabases['Documents\File'];
$database = $this->documentDatabases[\Documents\File::class];
$database->expects($this->at(0))
->method('createCollection')
->with('File.files');
$database->expects($this->at(1))
->method('createCollection')
->with('File.chunks');

$this->schemaManager->createDocumentCollection('Documents\File');
$this->schemaManager->createDocumentCollection(\Documents\File::class);
}

public function testCreateCollections()
Expand Down Expand Up @@ -241,7 +241,7 @@ public function testDropCollections()
public function testDropDocumentCollection()
{
foreach ($this->documentDatabases as $class => $database) {
if ($class === 'Documents\CmsArticle') {
if ($class === \Documents\CmsArticle::class) {
$database->expects($this->once())
->method('dropCollection')
->with($this->classMetadatas[$class]->collection);
Expand All @@ -250,33 +250,33 @@ public function testDropDocumentCollection()
}
}

$this->schemaManager->dropDocumentCollection('Documents\CmsArticle');
$this->schemaManager->dropDocumentCollection(\Documents\CmsArticle::class);
}

public function testCreateDocumentDatabase()
{
foreach ($this->documentDatabases as $class => $database) {
if ($class === 'Documents\CmsArticle') {
if ($class === \Documents\CmsArticle::class) {
$database->expects($this->once())->method('execute');
} else {
$database->expects($this->never())->method('execute');
}
}

$this->schemaManager->createDocumentDatabase('Documents\CmsArticle');
$this->schemaManager->createDocumentDatabase(\Documents\CmsArticle::class);
}

public function testDropDocumentDatabase()
{
foreach ($this->documentDatabases as $class => $database) {
if ($class === 'Documents\CmsArticle') {
if ($class === \Documents\CmsArticle::class) {
$database->expects($this->once())->method('drop');
} else {
$database->expects($this->never())->method('drop');
}
}

$this->dm->getSchemaManager()->dropDocumentDatabase('Documents\CmsArticle');
$this->dm->getSchemaManager()->dropDocumentDatabase(\Documents\CmsArticle::class);
}

public function testDropDatabases()
Expand Down Expand Up @@ -472,7 +472,7 @@ public function dataIsMongoIndexEquivalentToDocumentIndex()
public function testEnsureDocumentSharding()
{
$dbName = DOCTRINE_MONGODB_DATABASE;
$classMetadata = $this->dm->getClassMetadata('Documents\Sharded\ShardedUser');
$classMetadata = $this->dm->getClassMetadata(\Documents\Sharded\ShardedUser::class);
$collectionName = $classMetadata->getCollection();
$dbMock = $this->getMockDatabase();
$dbMock->method('getName')->willReturn($dbName);
Expand Down Expand Up @@ -503,7 +503,7 @@ public function testEnsureDocumentSharding()
public function testEnsureDocumentShardingThrowsExceptionIfThereWasAnError()
{
$dbName = DOCTRINE_MONGODB_DATABASE;
$classMetadata = $this->dm->getClassMetadata('Documents\Sharded\ShardedUser');
$classMetadata = $this->dm->getClassMetadata(\Documents\Sharded\ShardedUser::class);
$collectionName = $classMetadata->getCollection();
$dbMock = $this->getMockDatabase();
$dbMock->method('getName')->willReturn($dbName);
Expand All @@ -530,7 +530,7 @@ public function testEnsureDocumentShardingThrowsExceptionIfThereWasAnError()
public function testEnsureDocumentShardingIgnoresAlreadyShardedError()
{
$dbName = DOCTRINE_MONGODB_DATABASE;
$classMetadata = $this->dm->getClassMetadata('Documents\Sharded\ShardedUser');
$classMetadata = $this->dm->getClassMetadata(\Documents\Sharded\ShardedUser::class);
$collectionName = $classMetadata->getCollection();
$dbMock = $this->getMockDatabase();
$dbMock->method('getName')->willReturn($dbName);
Expand Down Expand Up @@ -567,9 +567,9 @@ public function testEnableShardingForDb()
$this->dm->connection = $connMock;
$dbMock = $this->getMockDatabase();
$dbMock->method('getName')->willReturn('db');
$this->dm->documentDatabases = array('Documents\Sharded\ShardedUser' => $dbMock);
$this->dm->documentDatabases = array(\Documents\Sharded\ShardedUser::class => $dbMock);

$this->schemaManager->enableShardingForDbByDocumentName('Documents\Sharded\ShardedUser');
$this->schemaManager->enableShardingForDbByDocumentName(\Documents\Sharded\ShardedUser::class);
}

/**
Expand All @@ -589,9 +589,9 @@ public function testEnableShardingForDbThrowsExceptionInCaseOfError()
$this->dm->connection = $connMock;
$dbMock = $this->getMockDatabase();
$dbMock->method('getName')->willReturn('db');
$this->dm->documentDatabases = array('Documents\Sharded\ShardedUser' => $dbMock);
$this->dm->documentDatabases = array(\Documents\Sharded\ShardedUser::class => $dbMock);

$this->schemaManager->enableShardingForDbByDocumentName('Documents\Sharded\ShardedUser');
$this->schemaManager->enableShardingForDbByDocumentName(\Documents\Sharded\ShardedUser::class);
}

public function testEnableShardingForDbIgnoresAlreadyShardedError()
Expand All @@ -607,9 +607,9 @@ public function testEnableShardingForDbIgnoresAlreadyShardedError()
$this->dm->connection = $connMock;
$dbMock = $this->getMockDatabase();
$dbMock->method('getName')->willReturn('db');
$this->dm->documentDatabases = array('Documents\Sharded\ShardedUser' => $dbMock);
$this->dm->documentDatabases = array(\Documents\Sharded\ShardedUser::class => $dbMock);

$this->schemaManager->enableShardingForDbByDocumentName('Documents\Sharded\ShardedUser');
$this->schemaManager->enableShardingForDbByDocumentName(\Documents\Sharded\ShardedUser::class);
}

private function getMockCollection()
Expand Down

0 comments on commit d793ed3

Please sign in to comment.