-
Notifications
You must be signed in to change notification settings - Fork 43
allow tu prefix collection #65
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
95 changes: 95 additions & 0 deletions
95
tests/Unit/DependencyInjection/ACSEOTypesenseExtensionTest.php
This file contains hidden or 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,95 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace ACSEO\Bundle\TypesenseBundle\Tests\Unit\DependencyInjection; | ||
|
|
||
|
|
||
| use ACSEO\TypesenseBundle\DependencyInjection\ACSEOTypesenseExtension; | ||
| // use FOS\ElasticaBundle\Doctrine\MongoDBPagerProvider; | ||
| // use FOS\ElasticaBundle\Doctrine\ORMPagerProvider; | ||
| // use FOS\ElasticaBundle\Doctrine\PHPCRPagerProvider; | ||
| // use FOS\ElasticaBundle\Doctrine\RegisterListenersService; | ||
| // use FOS\ElasticaBundle\Persister\InPlacePagerPersister; | ||
| // use FOS\ElasticaBundle\Persister\Listener\FilterObjectsListener; | ||
| // use FOS\ElasticaBundle\Persister\PagerPersisterRegistry; | ||
| use PHPUnit\Framework\TestCase; | ||
| use Symfony\Component\Config\FileLocator; | ||
| // use Symfony\Component\DependencyInjection\ChildDefinition; | ||
| use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
| use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; | ||
| // use Symfony\Component\DependencyInjection\Reference; | ||
| use Symfony\Component\Yaml\Yaml; | ||
|
|
||
| /** | ||
| * @internal | ||
| */ | ||
| class ACSEOTypesenseExtensionTest extends TestCase | ||
| { | ||
|
|
||
| public function testTypesenseClientDefinition() | ||
| { | ||
| $containerBuilder = new ContainerBuilder(); | ||
| $containerBuilder->registerExtension($extension = new ACSEOTypesenseExtension()); | ||
| $containerBuilder->setParameter('kernel.debug', true); | ||
|
|
||
| $loader = new YamlFileLoader($containerBuilder, new FileLocator(__DIR__.'/fixtures')); | ||
| $loader->load('acseo_typesense.yml'); | ||
|
|
||
| $extensionConfig = $containerBuilder->getExtensionConfig($extension->getAlias()); | ||
| $extension->load($extensionConfig, $containerBuilder); | ||
|
|
||
| $this->assertTrue($containerBuilder->hasDefinition('typesense.client')); | ||
|
|
||
| $clientDefinition = $containerBuilder->findDefinition('typesense.client'); | ||
|
|
||
| $this->assertSame('http://localhost:8108', $clientDefinition->getArgument(0)); | ||
| $this->assertSame('ACSEO', $clientDefinition->getArgument(1)); | ||
| } | ||
|
|
||
| public function testFinderServiceDefinition() | ||
| { | ||
| $containerBuilder = new ContainerBuilder(); | ||
| $containerBuilder->registerExtension($extension = new ACSEOTypesenseExtension()); | ||
| $containerBuilder->setParameter('kernel.debug', true); | ||
|
|
||
| $loader = new YamlFileLoader($containerBuilder, new FileLocator(__DIR__.'/fixtures')); | ||
| $loader->load('acseo_typesense.yml'); | ||
|
|
||
| $extensionConfig = $containerBuilder->getExtensionConfig($extension->getAlias()); | ||
| $extension->load($extensionConfig, $containerBuilder); | ||
|
|
||
| $this->assertTrue($containerBuilder->hasDefinition('typesense.finder')); | ||
| $this->assertTrue($containerBuilder->hasDefinition('typesense.finder.books')); | ||
|
|
||
| $finderBooksDefinition = $containerBuilder->findDefinition('typesense.finder.books'); | ||
| $finderBooksDefinitionArguments = $finderBooksDefinition->getArguments(); | ||
| $arguments = array_pop($finderBooksDefinitionArguments); | ||
|
|
||
| $this->assertSame('books', $arguments['typesense_name']); | ||
| $this->assertSame('books', $arguments['name']); | ||
| } | ||
|
|
||
| public function testFinderServiceDefinitionWithCollectionPrefix() | ||
| { | ||
| $containerBuilder = new ContainerBuilder(); | ||
| $containerBuilder->registerExtension($extension = new ACSEOTypesenseExtension()); | ||
| $containerBuilder->setParameter('kernel.debug', true); | ||
|
|
||
| $loader = new YamlFileLoader($containerBuilder, new FileLocator(__DIR__.'/fixtures')); | ||
| $loader->load('acseo_typesense_collection_prefix.yml'); | ||
|
|
||
| $extensionConfig = $containerBuilder->getExtensionConfig($extension->getAlias()); | ||
| $extension->load($extensionConfig, $containerBuilder); | ||
|
|
||
| $this->assertTrue($containerBuilder->hasDefinition('typesense.finder')); | ||
| $this->assertTrue($containerBuilder->hasDefinition('typesense.finder.books')); | ||
|
|
||
| $finderBooksDefinition = $containerBuilder->findDefinition('typesense.finder.books'); | ||
| $finderBooksDefinitionArguments = $finderBooksDefinition->getArguments(); | ||
| $arguments = array_pop($finderBooksDefinitionArguments); | ||
|
|
||
| $this->assertSame('acseo_prefix_books', $arguments['typesense_name']); | ||
| $this->assertSame('books', $arguments['name']); | ||
| } | ||
| } |
48 changes: 48 additions & 0 deletions
48
tests/Unit/DependencyInjection/fixtures/acseo_typesense.yml
This file contains hidden or 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,48 @@ | ||
| acseo_typesense: | ||
| typesense: | ||
| url: 'http://localhost:8108' | ||
| key: 'ACSEO' | ||
| collections: | ||
| # Collection settings | ||
| books: # Typesense collection name | ||
| entity: 'App\Entity\Book' # Doctrine Entity class | ||
| collection_name: 'books' | ||
| fields: | ||
| # | ||
| # Keeping Database and Typesense synchronized with ids | ||
| # | ||
| id: # Entity attribute name | ||
| name: id # Typesense attribute name | ||
| type: primary # Attribute type | ||
| # | ||
| # Using again id as a sortable field (int32 required) | ||
| # | ||
| sortable_id: | ||
| entity_attribute: id # Entity attribute name forced | ||
| name: sortable_id # Typesense field name | ||
| type: int32 | ||
| title: | ||
| name: title | ||
| type: string | ||
| author: | ||
| name: author | ||
| type: object # Object conversion with __toString() | ||
| author.country: | ||
| name: author_country | ||
| type: string | ||
| facet: true # Declare field as facet (required to use "group_by" query option) | ||
| entity_attribute: author.country # Equivalent of $book->getAuthor()->getCountry() | ||
| genres: | ||
| name: genres | ||
| type: collection # Convert ArrayCollection to array of strings | ||
| publishedAt: | ||
| name: publishedAt | ||
| type: datetime | ||
| optional: true # Declare field as optional | ||
| default_sorting_field: sortable_id # Default sorting field. Must be int32 or float | ||
| finders: | ||
| title_or_author: | ||
| finder_parameters: | ||
| query_by : 'title,author' | ||
| limit: 10 | ||
| num_typos: 2 |
49 changes: 49 additions & 0 deletions
49
tests/Unit/DependencyInjection/fixtures/acseo_typesense_collection_prefix.yml
This file contains hidden or 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,49 @@ | ||
| acseo_typesense: | ||
| typesense: | ||
| url: 'http://localhost:8108' | ||
| key: 'ACSEO' | ||
| collection_prefix: 'acseo_prefix_' | ||
| collections: | ||
| # Collection settings | ||
| books: # Typesense collection name | ||
| entity: 'App\Entity\Book' # Doctrine Entity class | ||
| collection_name: 'books' | ||
| fields: | ||
| # | ||
| # Keeping Database and Typesense synchronized with ids | ||
| # | ||
| id: # Entity attribute name | ||
| name: id # Typesense attribute name | ||
| type: primary # Attribute type | ||
| # | ||
| # Using again id as a sortable field (int32 required) | ||
| # | ||
| sortable_id: | ||
| entity_attribute: id # Entity attribute name forced | ||
| name: sortable_id # Typesense field name | ||
| type: int32 | ||
| title: | ||
| name: title | ||
| type: string | ||
| author: | ||
| name: author | ||
| type: object # Object conversion with __toString() | ||
| author.country: | ||
| name: author_country | ||
| type: string | ||
| facet: true # Declare field as facet (required to use "group_by" query option) | ||
| entity_attribute: author.country # Equivalent of $book->getAuthor()->getCountry() | ||
| genres: | ||
| name: genres | ||
| type: collection # Convert ArrayCollection to array of strings | ||
| publishedAt: | ||
| name: publishedAt | ||
| type: datetime | ||
| optional: true # Declare field as optional | ||
| default_sorting_field: sortable_id # Default sorting field. Must be int32 or float | ||
| finders: | ||
| title_or_author: | ||
| finder_parameters: | ||
| query_by : 'title,author' | ||
| limit: 10 | ||
| num_typos: 2 | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this work with parameters / environment placeholders?
Like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it will !