-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow specifying options in AutowireDatabase and AutowireCollection (#14
) * Resolve service references for codec collection options * Add codec option to AutowireCollection * Document codec usage * Bump MongoDB dependency to 1.17 * Allow passing all options to AutowireCollection and AutowireDatabase * Use parameter for type maps
- Loading branch information
Showing
7 changed files
with
219 additions
and
18 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
namespace MongoDB\Bundle\Tests\Unit\Attribute; | ||
|
||
use Generator; | ||
use MongoDB\BSON\Document; | ||
use MongoDB\Codec\DecodeIfSupported; | ||
use MongoDB\Codec\DocumentCodec; | ||
use MongoDB\Codec\EncodeIfSupported; | ||
use MongoDB\Driver\ReadConcern; | ||
use MongoDB\Driver\ReadPreference; | ||
use MongoDB\Driver\WriteConcern; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
use function sprintf; | ||
|
||
abstract class AttributeTestCase extends TestCase | ||
{ | ||
public static function provideOptions(): Generator | ||
{ | ||
$codec = new class implements DocumentCodec { | ||
use DecodeIfSupported; | ||
use EncodeIfSupported; | ||
|
||
public function canDecode($value): bool | ||
{ | ||
return $value instanceof Document; | ||
} | ||
|
||
public function canEncode($value): bool | ||
{ | ||
return $value instanceof Document; | ||
} | ||
|
||
public function decode($value): Document | ||
{ | ||
return $value; | ||
} | ||
|
||
public function encode($value): Document | ||
{ | ||
return $value; | ||
} | ||
}; | ||
|
||
$options = [ | ||
'codec' => $codec, | ||
'writeConcern' => new WriteConcern(0), | ||
'readConcern' => new ReadConcern('majority'), | ||
'readPreference' => new ReadPreference('primary'), | ||
]; | ||
|
||
foreach ($options as $option => $value) { | ||
yield sprintf('%s option: null', $option) => [ | ||
'attributeArguments' => [$option => null], | ||
'expectedOptions' => [], | ||
]; | ||
|
||
yield sprintf('%s option: instance', $option) => [ | ||
'attributeArguments' => [$option => $value], | ||
'expectedOptions' => [$option => $value], | ||
]; | ||
|
||
yield sprintf('%s option: reference', $option) => [ | ||
'attributeArguments' => [$option => sprintf('%s_service', $option)], | ||
'expectedOptions' => [$option => new Reference(sprintf('%s_service', $option))], | ||
]; | ||
} | ||
|
||
// Type map | ||
yield 'typeMap option: null' => [ | ||
'attributeArguments' => ['typeMap' => null], | ||
'expectedOptions' => [], | ||
]; | ||
|
||
yield 'typeMap option: value' => [ | ||
'attributeArguments' => ['typeMap' => ['root' => 'bson']], | ||
'expectedOptions' => ['typeMap' => ['root' => 'bson']], | ||
]; | ||
|
||
yield 'typeMap option: parameter' => [ | ||
'attributeArguments' => ['typeMap' => 'default_typeMap'], | ||
'expectedOptions' => ['typeMap' => '%default_typeMap%'], | ||
]; | ||
} | ||
} |
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