-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Init GridFS bucket from doctrine or configuration
- Loading branch information
Showing
4 changed files
with
197 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
tests/Adapter/Builder/GridFSAdapterDefinitionBuilderTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the flysystem-bundle project. | ||
* | ||
* (c) Titouan Galopin <galopintitouan@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Tests\League\FlysystemBundle\Adapter\Builder; | ||
|
||
use Doctrine\ODM\MongoDB\Configuration; | ||
use Doctrine\ODM\MongoDB\DocumentManager; | ||
use League\Flysystem\GridFS\GridFSAdapter; | ||
use League\FlysystemBundle\Adapter\Builder\GridFSAdapterDefinitionBuilder; | ||
use MongoDB\Client; | ||
use MongoDB\GridFS\Bucket; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class GridFSAdapterDefinitionBuilderTest extends TestCase | ||
{ | ||
public function createBuilder(): GridFSAdapterDefinitionBuilder | ||
{ | ||
return new GridFSAdapterDefinitionBuilder(); | ||
} | ||
|
||
public function provideValidOptions(): \Generator | ||
{ | ||
yield 'doctrine_minimal' => [[ | ||
'doctrine_connection' => 'default', | ||
]]; | ||
|
||
yield 'doctrine_full' => [[ | ||
'doctrine_connection' => 'custom', | ||
'database' => 'testing', | ||
'bucket' => 'avatars', | ||
]]; | ||
|
||
yield 'config_minimal' => [[ | ||
'mongodb_uri' => 'mongodb://localhost:27017/', | ||
'database' => 'testing', | ||
]]; | ||
|
||
yield 'config_full' => [[ | ||
'mongodb_uri' => 'mongodb://server1:27017,server2:27017/', | ||
'mongodb_uri_options' => ['appname' => 'flysystem'], | ||
'mongodb_driver_options' => ['disableClientPersistence' => false], | ||
'database' => 'testing', | ||
'bucket' => 'avatars', | ||
]]; | ||
|
||
yield 'service' => [[ | ||
'bucket' => 'bucket', | ||
]]; | ||
} | ||
|
||
/** | ||
* @dataProvider provideValidOptions | ||
*/ | ||
public function testCreateDefinition($options) | ||
{ | ||
$this->assertSame(GridFSAdapter::class, $this->createBuilder()->createDefinition($options, null)->getClass()); | ||
} | ||
|
||
public function testInitializeBucketFromDocumentManager() | ||
{ | ||
$client = new Client(); | ||
$config = new Configuration(); | ||
$config->setDefaultDB('testing'); | ||
$dm = $this->createMock(DocumentManager::class); | ||
$dm->expects($this->once())->method('getClient')->willReturn($client); | ||
$dm->expects($this->once())->method('getConfiguration')->willReturn($config); | ||
|
||
$bucket = GridFSAdapterDefinitionBuilder::initializeBucketFromDocumentManager($dm, null, 'avatars'); | ||
|
||
$this->assertInstanceOf(Bucket::class, $bucket); | ||
$this->assertSame('testing', $bucket->getDatabaseName()); | ||
$this->assertSame('avatars', $bucket->getBucketName()); | ||
} | ||
|
||
public function testInitializeBucketFromConfig() | ||
{ | ||
$bucket = GridFSAdapterDefinitionBuilder::initializeBucketFromConfig( | ||
'mongodb://server:27017/', | ||
['appname' => 'flysystem'], | ||
['disableClientPersistence' => false], | ||
'testing', | ||
'avatars' | ||
); | ||
|
||
$this->assertInstanceOf(Bucket::class, $bucket); | ||
$this->assertSame('testing', $bucket->getDatabaseName()); | ||
$this->assertSame('avatars', $bucket->getBucketName()); | ||
} | ||
} |