Skip to content

Commit

Permalink
Merge pull request #1468 from gruberro/drop-fs-files
Browse files Browse the repository at this point in the history
Ensure GridFS collections are dropped properly
  • Loading branch information
alcaeus committed Jul 29, 2016
2 parents 183ee00 + dd151f4 commit b1639e5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
4 changes: 1 addition & 3 deletions lib/Doctrine/ODM/MongoDB/SchemaManager.php
Expand Up @@ -373,9 +373,7 @@ public function dropDocumentCollection($documentName)
if ($class->isMappedSuperclass || $class->isEmbeddedDocument) {
throw new \InvalidArgumentException('Cannot delete document indexes for mapped super classes or embedded documents.');
}
$this->dm->getDocumentDatabase($documentName)->dropCollection(
$class->getCollection()
);
$this->dm->getDocumentCollection($documentName)->drop();
}

/**
Expand Down
20 changes: 20 additions & 0 deletions tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1468Test.php
@@ -0,0 +1,20 @@
<?php

namespace Doctrine\ODM\MongoDB\Tests\Functional\Ticket;

use Documents;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

class GH1468Test extends \Doctrine\ODM\MongoDB\Tests\BaseTest
{
public function testFilesCollectionIsDroppedProperly()
{
$file = new Documents\File();
$this->dm->persist($file);
$this->dm->flush();
$this->assertCount(1, $this->dm->getRepository(get_class($file))->findAll());

$this->dm->getSchemaManager()->dropCollections();
$this->assertCount(0, $this->dm->getRepository(get_class($file))->findAll());
}
}
20 changes: 10 additions & 10 deletions tests/Doctrine/ODM/MongoDB/Tests/SchemaManagerTest.php
Expand Up @@ -228,13 +228,13 @@ public function testCreateCollections()

public function testDropCollections()
{
foreach ($this->documentDatabases as $class => $database) {
foreach ($this->documentCollections as $class => $collection) {
if (in_array($class, $this->indexedClasses + $this->someNonIndexedClasses)) {
$database->expects($this->once())
->method('dropCollection')
->with($this->classMetadatas[$class]->collection);
$collection->expects($this->once())
->method('drop')
->with();
} elseif (in_array($class, $this->someMappedSuperclassAndEmbeddedClasses)) {
$database->expects($this->never())->method('dropCollection');
$collection->expects($this->never())->method('drop');
}
}

Expand All @@ -243,13 +243,13 @@ public function testDropCollections()

public function testDropDocumentCollection()
{
foreach ($this->documentDatabases as $class => $database) {
foreach ($this->documentCollections as $class => $collection) {
if ($class === 'Documents\CmsArticle') {
$database->expects($this->once())
->method('dropCollection')
->with($this->classMetadatas[$class]->collection);
$collection->expects($this->once())
->method('drop')
->with();
} else {
$database->expects($this->never())->method('dropCollection');
$collection->expects($this->never())->method('drop');
}
}

Expand Down

0 comments on commit b1639e5

Please sign in to comment.