From 25083656ea38a3f7ad489dbc05bf38f12ae3317f Mon Sep 17 00:00:00 2001 From: Kamil Kokot Date: Thu, 8 Jun 2017 10:35:50 +0200 Subject: [PATCH] Introduce Document suffix for Elasticsearch models --- ...buteSpec.php => AttributeDocumentSpec.php} | 6 +-- ...pec.php => AttributeValueDocumentSpec.php} | 10 ++-- .../{ImageSpec.php => ImageDocumentSpec.php} | 6 +-- .../{PriceSpec.php => PriceDocumentSpec.php} | 6 +-- ...roductSpec.php => ProductDocumentSpec.php} | 14 +++--- .../{TaxonSpec.php => TaxonDocumentSpec.php} | 6 +-- spec/Projection/ProductProjectorSpec.php | 14 +++--- .../Filter/ProductInChannelApplicatorSpec.php | 8 ++-- .../ProductInPriceRangeApplicatorSpec.php | 8 ++-- .../Filter/ProductInTaxonApplicatorSpec.php | 8 ++-- .../MatchProductByNameApplicatorSpec.php | 8 ++-- .../Sort/SortByFieldApplicatorSpec.php | 4 +- src/Controller/SearchController.php | 4 +- .../{Attribute.php => AttributeDocument.php} | 2 +- ...teValue.php => AttributeValueDocument.php} | 12 ++--- src/Document/{Image.php => ImageDocument.php} | 2 +- src/Document/{Price.php => PriceDocument.php} | 2 +- .../{Product.php => ProductDocument.php} | 28 +++++------ src/Document/{Taxon.php => TaxonDocument.php} | 6 +-- ...Factory.php => ProductDocumentFactory.php} | 40 +++++++--------- ...hp => ProductDocumentFactoryInterface.php} | 11 ++--- src/Factory/ProductListViewFactory.php | 2 - src/Projection/ProductProjector.php | 8 ++-- src/Resources/config/services.xml | 2 +- .../Context/Domain/Shop/ProductContext.php | 20 ++++---- tests/Behat/Context/Setup/ProductContext.php | 24 +++++----- ...est.php => ProductDocumentFactoryTest.php} | 46 ++++++------------- 27 files changed, 136 insertions(+), 171 deletions(-) rename spec/Document/{AttributeSpec.php => AttributeDocumentSpec.php} (69%) rename spec/Document/{AttributeValueSpec.php => AttributeValueDocumentSpec.php} (58%) rename spec/Document/{ImageSpec.php => ImageDocumentSpec.php} (70%) rename spec/Document/{PriceSpec.php => PriceDocumentSpec.php} (70%) rename spec/Document/{ProductSpec.php => ProductDocumentSpec.php} (83%) rename spec/Document/{TaxonSpec.php => TaxonDocumentSpec.php} (84%) rename src/Document/{Attribute.php => AttributeDocument.php} (96%) rename src/Document/{AttributeValue.php => AttributeValueDocument.php} (77%) rename src/Document/{Image.php => ImageDocument.php} (96%) rename src/Document/{Price.php => PriceDocument.php} (97%) rename src/Document/{Product.php => ProductDocument.php} (91%) rename src/Document/{Taxon.php => TaxonDocument.php} (95%) rename src/Factory/{ProductFactory.php => ProductDocumentFactory.php} (86%) rename src/Factory/{ProductFactoryInterface.php => ProductDocumentFactoryInterface.php} (74%) rename tests/Factory/{ProductFactoryTest.php => ProductDocumentFactoryTest.php} (79%) diff --git a/spec/Document/AttributeSpec.php b/spec/Document/AttributeDocumentSpec.php similarity index 69% rename from spec/Document/AttributeSpec.php rename to spec/Document/AttributeDocumentSpec.php index 8f70a2d..1278195 100644 --- a/spec/Document/AttributeSpec.php +++ b/spec/Document/AttributeDocumentSpec.php @@ -2,14 +2,14 @@ namespace spec\Sylius\ElasticSearchPlugin\Document; -use Sylius\ElasticSearchPlugin\Document\Attribute; +use Sylius\ElasticSearchPlugin\Document\AttributeDocument; use PhpSpec\ObjectBehavior; -final class AttributeSpec extends ObjectBehavior +final class AttributeDocumentSpec extends ObjectBehavior { function it_is_initializable() { - $this->shouldHaveType(Attribute::class); + $this->shouldHaveType(AttributeDocument::class); } function it_has_code() diff --git a/spec/Document/AttributeValueSpec.php b/spec/Document/AttributeValueDocumentSpec.php similarity index 58% rename from spec/Document/AttributeValueSpec.php rename to spec/Document/AttributeValueDocumentSpec.php index c3f3bab..8d2da16 100644 --- a/spec/Document/AttributeValueSpec.php +++ b/spec/Document/AttributeValueDocumentSpec.php @@ -2,15 +2,15 @@ namespace spec\Sylius\ElasticSearchPlugin\Document; -use Sylius\ElasticSearchPlugin\Document\Attribute; -use Sylius\ElasticSearchPlugin\Document\AttributeValue; +use Sylius\ElasticSearchPlugin\Document\AttributeDocument; +use Sylius\ElasticSearchPlugin\Document\AttributeValueDocument; use PhpSpec\ObjectBehavior; -final class AttributeValueSpec extends ObjectBehavior +final class AttributeValueDocumentSpec extends ObjectBehavior { function it_is_initializable() { - $this->shouldHaveType(AttributeValue::class); + $this->shouldHaveType(AttributeValueDocument::class); } function it_has_value() @@ -22,7 +22,7 @@ function it_has_value() function it_has_attribute() { - $attribute = new Attribute(); + $attribute = new AttributeDocument(); $this->setAttribute($attribute); $this->getAttribute()->shouldReturn($attribute); diff --git a/spec/Document/ImageSpec.php b/spec/Document/ImageDocumentSpec.php similarity index 70% rename from spec/Document/ImageSpec.php rename to spec/Document/ImageDocumentSpec.php index 7ace190..2325382 100644 --- a/spec/Document/ImageSpec.php +++ b/spec/Document/ImageDocumentSpec.php @@ -2,14 +2,14 @@ namespace spec\Sylius\ElasticSearchPlugin\Document; -use Sylius\ElasticSearchPlugin\Document\Image; +use Sylius\ElasticSearchPlugin\Document\ImageDocument; use PhpSpec\ObjectBehavior; -final class ImageSpec extends ObjectBehavior +final class ImageDocumentSpec extends ObjectBehavior { function it_is_initializable() { - $this->shouldHaveType(Image::class); + $this->shouldHaveType(ImageDocument::class); } function it_has_code() diff --git a/spec/Document/PriceSpec.php b/spec/Document/PriceDocumentSpec.php similarity index 70% rename from spec/Document/PriceSpec.php rename to spec/Document/PriceDocumentSpec.php index 42d64f5..aaa163a 100644 --- a/spec/Document/PriceSpec.php +++ b/spec/Document/PriceDocumentSpec.php @@ -2,14 +2,14 @@ namespace spec\Sylius\ElasticSearchPlugin\Document; -use Sylius\ElasticSearchPlugin\Document\Price; +use Sylius\ElasticSearchPlugin\Document\PriceDocument; use PhpSpec\ObjectBehavior; -final class PriceSpec extends ObjectBehavior +final class PriceDocumentSpec extends ObjectBehavior { function it_is_initializable() { - $this->shouldHaveType(Price::class); + $this->shouldHaveType(PriceDocument::class); } function it_has_amount() diff --git a/spec/Document/ProductSpec.php b/spec/Document/ProductDocumentSpec.php similarity index 83% rename from spec/Document/ProductSpec.php rename to spec/Document/ProductDocumentSpec.php index d5f4fef..261d31b 100644 --- a/spec/Document/ProductSpec.php +++ b/spec/Document/ProductDocumentSpec.php @@ -3,16 +3,16 @@ namespace spec\Sylius\ElasticSearchPlugin\Document; use ONGR\ElasticsearchBundle\Collection\Collection; -use Sylius\ElasticSearchPlugin\Document\Price; -use Sylius\ElasticSearchPlugin\Document\Product; +use Sylius\ElasticSearchPlugin\Document\PriceDocument; +use Sylius\ElasticSearchPlugin\Document\ProductDocument; use PhpSpec\ObjectBehavior; -use Sylius\ElasticSearchPlugin\Document\Taxon; +use Sylius\ElasticSearchPlugin\Document\TaxonDocument; -final class ProductSpec extends ObjectBehavior +final class ProductDocumentSpec extends ObjectBehavior { function it_is_initializable() { - $this->shouldHaveType(Product::class); + $this->shouldHaveType(ProductDocument::class); } function it_has_code() @@ -52,7 +52,7 @@ function it_has_description() function it_has_price() { - $price = new Price(); + $price = new PriceDocument(); $this->setPrice($price); $this->getPrice()->shouldReturn($price); @@ -60,7 +60,7 @@ function it_has_price() function it_has_main_taxon() { - $taxon = new Taxon(); + $taxon = new TaxonDocument(); $this->setMainTaxon($taxon); $this->getMainTaxon()->shouldReturn($taxon); diff --git a/spec/Document/TaxonSpec.php b/spec/Document/TaxonDocumentSpec.php similarity index 84% rename from spec/Document/TaxonSpec.php rename to spec/Document/TaxonDocumentSpec.php index 65989a1..6fc8967 100644 --- a/spec/Document/TaxonSpec.php +++ b/spec/Document/TaxonDocumentSpec.php @@ -3,14 +3,14 @@ namespace spec\Sylius\ElasticSearchPlugin\Document; use ONGR\ElasticsearchBundle\Collection\Collection; -use Sylius\ElasticSearchPlugin\Document\Taxon; +use Sylius\ElasticSearchPlugin\Document\TaxonDocument; use PhpSpec\ObjectBehavior; -final class TaxonSpec extends ObjectBehavior +final class TaxonDocumentSpec extends ObjectBehavior { function it_is_initializable() { - $this->shouldHaveType(Taxon::class); + $this->shouldHaveType(TaxonDocument::class); } function it_has_code() diff --git a/spec/Projection/ProductProjectorSpec.php b/spec/Projection/ProductProjectorSpec.php index ba2597a..ce89a75 100644 --- a/spec/Projection/ProductProjectorSpec.php +++ b/spec/Projection/ProductProjectorSpec.php @@ -7,16 +7,16 @@ use Sylius\Component\Core\Model\ChannelInterface; use Sylius\Component\Core\Model\ProductInterface; use Sylius\Component\Locale\Model\LocaleInterface; -use Sylius\ElasticSearchPlugin\Document\Product; +use Sylius\ElasticSearchPlugin\Document\ProductDocument; use Sylius\ElasticSearchPlugin\Event\ProductCreated; -use Sylius\ElasticSearchPlugin\Factory\ProductFactoryInterface; +use Sylius\ElasticSearchPlugin\Factory\ProductDocumentFactoryInterface; use Sylius\ElasticSearchPlugin\Projection\ProductProjector; use PhpSpec\ObjectBehavior; use Prophecy\Argument; final class ProductProjectorSpec extends ObjectBehavior { - function let(Manager $manager, ProductFactoryInterface $factory) + function let(Manager $manager, ProductDocumentFactoryInterface $factory) { $this->beConstructedWith($manager, $factory); } @@ -28,7 +28,7 @@ function it_is_initializable() function it_saves_product_document_if_product_has_channel_defined( Manager $manager, - ProductFactoryInterface $factory, + ProductDocumentFactoryInterface $factory, ProductInterface $product, LocaleInterface $locale, ChannelInterface $channel @@ -36,7 +36,7 @@ function it_saves_product_document_if_product_has_channel_defined( $channel->getLocales()->willReturn(new ArrayCollection([$locale->getWrappedObject()])); $product->getChannels()->willReturn(new ArrayCollection([$channel->getWrappedObject()])); - $productDocument = new Product(); + $productDocument = new ProductDocument(); $factory->createFromSyliusSimpleProductModel($product, $locale, $channel)->willReturn($productDocument); $manager->persist($productDocument)->shouldBeCalled(); @@ -47,7 +47,7 @@ function it_saves_product_document_if_product_has_channel_defined( function it_does_not_save_product_document_if_product_has_not_channel_defined( Manager $manager, - ProductFactoryInterface $factory, + ProductDocumentFactoryInterface $factory, ProductInterface $product ) { $product->getChannels()->willReturn(new ArrayCollection([])); @@ -61,7 +61,7 @@ function it_does_not_save_product_document_if_product_has_not_channel_defined( function it_does_not_save_product_document_if_channel_has_not_locales_defined( Manager $manager, - ProductFactoryInterface $factory, + ProductDocumentFactoryInterface $factory, ProductInterface $product, ChannelInterface $channel ) { diff --git a/spec/Search/Elastic/Applicator/Filter/ProductInChannelApplicatorSpec.php b/spec/Search/Elastic/Applicator/Filter/ProductInChannelApplicatorSpec.php index 7444143..07b0dec 100644 --- a/spec/Search/Elastic/Applicator/Filter/ProductInChannelApplicatorSpec.php +++ b/spec/Search/Elastic/Applicator/Filter/ProductInChannelApplicatorSpec.php @@ -4,7 +4,7 @@ use ONGR\ElasticsearchDSL\Query\Compound\BoolQuery; use ONGR\ElasticsearchDSL\Query\Joining\NestedQuery; -use Sylius\ElasticSearchPlugin\Document\Product; +use Sylius\ElasticSearchPlugin\Document\ProductDocument; use Sylius\ElasticSearchPlugin\Search\Criteria\Criteria; use Sylius\ElasticSearchPlugin\Search\Criteria\Filtering\ProductInChannelFilter; use Sylius\ElasticSearchPlugin\Search\Elastic\Applicator\Filter\ProductInChannelApplicator; @@ -38,7 +38,7 @@ function it_applies_search_criteria_with_channel_code( Search $search, NestedQuery $nestedQuery ) { - $criteria = Criteria::fromQueryParameters(Product::class, ['channel_code' => 'web']); + $criteria = Criteria::fromQueryParameters(ProductDocument::class, ['channel_code' => 'web']); $productInChannelQueryFactory->create($criteria->filtering()->fields())->willReturn($nestedQuery); $search->addPostFilter($nestedQuery, BoolQuery::MUST)->shouldBeCalled(); @@ -47,11 +47,11 @@ function it_applies_search_criteria_with_channel_code( function it_supports_channel_code_parameter() { - $criteria = Criteria::fromQueryParameters(Product::class, ['channel_code' => 'web']); + $criteria = Criteria::fromQueryParameters(ProductDocument::class, ['channel_code' => 'web']); $this->supports($criteria)->shouldReturn(true); - $criteria = Criteria::fromQueryParameters(Product::class, ['taxon_code' => 'tree']); + $criteria = Criteria::fromQueryParameters(ProductDocument::class, ['taxon_code' => 'tree']); $this->supports($criteria)->shouldReturn(false); } diff --git a/spec/Search/Elastic/Applicator/Filter/ProductInPriceRangeApplicatorSpec.php b/spec/Search/Elastic/Applicator/Filter/ProductInPriceRangeApplicatorSpec.php index 1b57b79..b80003a 100644 --- a/spec/Search/Elastic/Applicator/Filter/ProductInPriceRangeApplicatorSpec.php +++ b/spec/Search/Elastic/Applicator/Filter/ProductInPriceRangeApplicatorSpec.php @@ -4,7 +4,7 @@ use ONGR\ElasticsearchDSL\Query\Compound\BoolQuery; use ONGR\ElasticsearchDSL\Query\TermLevel\TermQuery; -use Sylius\ElasticSearchPlugin\Document\Product; +use Sylius\ElasticSearchPlugin\Document\ProductDocument; use Sylius\ElasticSearchPlugin\Search\Criteria\Criteria; use Sylius\ElasticSearchPlugin\Search\Criteria\Filtering\ProductInPriceRangeFilter; use Sylius\ElasticSearchPlugin\Search\Elastic\Applicator\Filter\ProductInPriceRangeApplicator; @@ -35,7 +35,7 @@ function it_is_search_criteria_applicator() function it_applies_search_criteria_for_given_query(QueryFactoryInterface $productInPriceRangeQueryFactory, Search $search, TermQuery $termQuery) { - $criteria = Criteria::fromQueryParameters(Product::class, ['product_price_range' => ['grater_than' => 20, 'less_than' => 50]]); + $criteria = Criteria::fromQueryParameters(ProductDocument::class, ['product_price_range' => ['grater_than' => 20, 'less_than' => 50]]); $productInPriceRangeQueryFactory->create($criteria->filtering()->fields())->willReturn($termQuery); $search->addPostFilter($termQuery, BoolQuery::MUST)->shouldBeCalled(); @@ -44,10 +44,10 @@ function it_applies_search_criteria_for_given_query(QueryFactoryInterface $produ function it_supports_product_price_range_parameter() { - $criteria = Criteria::fromQueryParameters(Product::class, ['product_price_range' => ['grater_than' => 20, 'less_than' => 50]]); + $criteria = Criteria::fromQueryParameters(ProductDocument::class, ['product_price_range' => ['grater_than' => 20, 'less_than' => 50]]); $this->supports($criteria)->shouldReturn(true); - $criteria = Criteria::fromQueryParameters(Product::class, []); + $criteria = Criteria::fromQueryParameters(ProductDocument::class, []); $this->supports($criteria)->shouldReturn(false); } } diff --git a/spec/Search/Elastic/Applicator/Filter/ProductInTaxonApplicatorSpec.php b/spec/Search/Elastic/Applicator/Filter/ProductInTaxonApplicatorSpec.php index 2605ccd..960fa3f 100644 --- a/spec/Search/Elastic/Applicator/Filter/ProductInTaxonApplicatorSpec.php +++ b/spec/Search/Elastic/Applicator/Filter/ProductInTaxonApplicatorSpec.php @@ -4,7 +4,7 @@ use ONGR\ElasticsearchDSL\Query\Compound\BoolQuery; use ONGR\ElasticsearchDSL\Query\TermLevel\TermQuery; -use Sylius\ElasticSearchPlugin\Document\Product; +use Sylius\ElasticSearchPlugin\Document\ProductDocument; use Sylius\ElasticSearchPlugin\Search\Criteria\Criteria; use Sylius\ElasticSearchPlugin\Search\Criteria\Filtering\ProductInTaxonFilter; use Sylius\ElasticSearchPlugin\Search\Elastic\Applicator\Filter\ProductInTaxonApplicator; @@ -38,7 +38,7 @@ function it_applies_search_query_for_given_criteria( TermQuery $termQuery, Search $search ) { - $criteria = Criteria::fromQueryParameters(Product::class, ['taxon_code' => 'mugs']); + $criteria = Criteria::fromQueryParameters(ProductDocument::class, ['taxon_code' => 'mugs']); $productInMainTaxon->create($criteria->filtering()->fields())->willReturn($termQuery); @@ -49,10 +49,10 @@ function it_applies_search_query_for_given_criteria( function it_supports_taxon_code_paramter() { - $criteria = Criteria::fromQueryParameters(Product::class, ['taxon_code' => 'mugs']); + $criteria = Criteria::fromQueryParameters(ProductDocument::class, ['taxon_code' => 'mugs']); $this->supports($criteria)->shouldReturn(true); - $criteria = Criteria::fromQueryParameters(Product::class, []); + $criteria = Criteria::fromQueryParameters(ProductDocument::class, []); $this->supports($criteria)->shouldReturn(false); } } diff --git a/spec/Search/Elastic/Applicator/Query/MatchProductByNameApplicatorSpec.php b/spec/Search/Elastic/Applicator/Query/MatchProductByNameApplicatorSpec.php index 93d4e8c..dd74859 100644 --- a/spec/Search/Elastic/Applicator/Query/MatchProductByNameApplicatorSpec.php +++ b/spec/Search/Elastic/Applicator/Query/MatchProductByNameApplicatorSpec.php @@ -3,7 +3,7 @@ namespace spec\Sylius\ElasticSearchPlugin\Search\Elastic\Applicator\Query; use ONGR\ElasticsearchDSL\Query\FullText\MatchQuery; -use Sylius\ElasticSearchPlugin\Document\Product; +use Sylius\ElasticSearchPlugin\Document\ProductDocument; use Sylius\ElasticSearchPlugin\Search\Criteria\Criteria; use Sylius\ElasticSearchPlugin\Search\Criteria\SearchPhrase; use Sylius\ElasticSearchPlugin\Search\Elastic\Applicator\Query\MatchProductByNameApplicator; @@ -38,7 +38,7 @@ function it_applies_match_product_by_name_query( MatchQuery $matchQuery, Search $search ) { - $criteria = Criteria::fromQueryParameters(Product::class, ['search' => 'banana']); + $criteria = Criteria::fromQueryParameters(ProductDocument::class, ['search' => 'banana']); $matchProductNameQueryFactory->create($criteria->filtering()->fields())->willReturn($matchQuery); $search->addQuery($matchQuery)->shouldBeCalled(); @@ -47,10 +47,10 @@ function it_applies_match_product_by_name_query( function it_supports_search_parameter() { - $criteria = Criteria::fromQueryParameters(Product::class, ['search' => 'banana']); + $criteria = Criteria::fromQueryParameters(ProductDocument::class, ['search' => 'banana']); $this->supports($criteria)->shouldReturn(true); - $criteria = Criteria::fromQueryParameters(Product::class, []); + $criteria = Criteria::fromQueryParameters(ProductDocument::class, []); $this->supports($criteria)->shouldReturn(false); } } diff --git a/spec/Search/Elastic/Applicator/Sort/SortByFieldApplicatorSpec.php b/spec/Search/Elastic/Applicator/Sort/SortByFieldApplicatorSpec.php index 8395a8a..b303db1 100644 --- a/spec/Search/Elastic/Applicator/Sort/SortByFieldApplicatorSpec.php +++ b/spec/Search/Elastic/Applicator/Sort/SortByFieldApplicatorSpec.php @@ -2,7 +2,7 @@ namespace spec\Sylius\ElasticSearchPlugin\Search\Elastic\Applicator\Sort; -use Sylius\ElasticSearchPlugin\Document\Product; +use Sylius\ElasticSearchPlugin\Document\ProductDocument; use Sylius\ElasticSearchPlugin\Search\Criteria\Criteria; use Sylius\ElasticSearchPlugin\Search\Elastic\Applicator\SearchCriteriaApplicatorInterface; use Sylius\ElasticSearchPlugin\Search\Elastic\Applicator\Sort\SortByFieldApplicator; @@ -36,7 +36,7 @@ function it_applies_sort_query_to_search_with_given_sorting( Search $search, FieldSort $fieldSort ) { - $criteria = Criteria::fromQueryParameters(Product::class, ['sort' => '-name']); + $criteria = Criteria::fromQueryParameters(ProductDocument::class, ['sort' => '-name']); $sortByFieldSortFactory->create($criteria->ordering())->willReturn($fieldSort); $search->addSort($fieldSort)->shouldBeCalled(); diff --git a/src/Controller/SearchController.php b/src/Controller/SearchController.php index 7db156d..13e9b89 100644 --- a/src/Controller/SearchController.php +++ b/src/Controller/SearchController.php @@ -13,7 +13,7 @@ use FOS\RestBundle\View\View; use FOS\RestBundle\View\ViewHandlerInterface; -use Sylius\ElasticSearchPlugin\Document\Product; +use Sylius\ElasticSearchPlugin\Document\ProductDocument; use Sylius\ElasticSearchPlugin\Factory\ProductListViewFactoryInterface; use Sylius\ElasticSearchPlugin\Search\Criteria\Criteria; use Sylius\ElasticSearchPlugin\Search\SearchEngineInterface; @@ -65,7 +65,7 @@ public function __invoke(Request $request) $content = $request->query->all(); } - $criteria = Criteria::fromQueryParameters(Product::class, $content); + $criteria = Criteria::fromQueryParameters(ProductDocument::class, $content); $result = $this->searchEngine->match($criteria); diff --git a/src/Document/Attribute.php b/src/Document/AttributeDocument.php similarity index 96% rename from src/Document/Attribute.php rename to src/Document/AttributeDocument.php index c3bc094..a5e3d06 100644 --- a/src/Document/Attribute.php +++ b/src/Document/AttributeDocument.php @@ -7,7 +7,7 @@ /** * @ElasticSearch\Object */ -final class Attribute +final class AttributeDocument { /** * @var string diff --git a/src/Document/AttributeValue.php b/src/Document/AttributeValueDocument.php similarity index 77% rename from src/Document/AttributeValue.php rename to src/Document/AttributeValueDocument.php index 747065c..3093f7d 100644 --- a/src/Document/AttributeValue.php +++ b/src/Document/AttributeValueDocument.php @@ -7,7 +7,7 @@ /** * @ElasticSearch\Object */ -final class AttributeValue +final class AttributeValueDocument { /** * @var string @@ -17,9 +17,9 @@ final class AttributeValue private $value; /** - * @var Attribute + * @var AttributeDocument * - * @ElasticSearch\Embedded(class="SyliusElasticSearchPlugin:Attribute") + * @ElasticSearch\Embedded(class="SyliusElasticSearchPlugin:AttributeDocument") */ private $attribute; @@ -40,7 +40,7 @@ public function setValue($value) } /** - * @return Attribute + * @return AttributeDocument */ public function getAttribute() { @@ -48,9 +48,9 @@ public function getAttribute() } /** - * @param Attribute $attribute + * @param AttributeDocument $attribute */ - public function setAttribute(Attribute $attribute) + public function setAttribute(AttributeDocument $attribute) { $this->attribute = $attribute; } diff --git a/src/Document/Image.php b/src/Document/ImageDocument.php similarity index 96% rename from src/Document/Image.php rename to src/Document/ImageDocument.php index 5719109..a16b968 100644 --- a/src/Document/Image.php +++ b/src/Document/ImageDocument.php @@ -7,7 +7,7 @@ /** * @ElasticSearch\Object */ -final class Image +final class ImageDocument { /** * @var string diff --git a/src/Document/Price.php b/src/Document/PriceDocument.php similarity index 97% rename from src/Document/Price.php rename to src/Document/PriceDocument.php index d1aa991..8fbf057 100644 --- a/src/Document/Price.php +++ b/src/Document/PriceDocument.php @@ -7,7 +7,7 @@ /** * @ElasticSearch\Object */ -final class Price +final class PriceDocument { /** * @var int diff --git a/src/Document/Product.php b/src/Document/ProductDocument.php similarity index 91% rename from src/Document/Product.php rename to src/Document/ProductDocument.php index 5afacb4..8c81cf2 100644 --- a/src/Document/Product.php +++ b/src/Document/ProductDocument.php @@ -8,7 +8,7 @@ /** * @ElasticSearch\Document(type="product") */ -class Product +class ProductDocument { /** * @var string @@ -63,37 +63,37 @@ class Product private $description; /** - * @var Price + * @var PriceDocument * - * @ElasticSearch\Embedded(class="SyliusElasticSearchPlugin:Price") + * @ElasticSearch\Embedded(class="SyliusElasticSearchPlugin:PriceDocument") */ private $price; /** - * @var Taxon + * @var TaxonDocument * - * @ElasticSearch\Embedded(class="SyliusElasticSearchPlugin:Taxon") + * @ElasticSearch\Embedded(class="SyliusElasticSearchPlugin:TaxonDocument") */ private $mainTaxon; /** * @var Collection * - * @ElasticSearch\Embedded(class="SyliusElasticSearchPlugin:Taxon", multiple=true) + * @ElasticSearch\Embedded(class="SyliusElasticSearchPlugin:TaxonDocument", multiple=true) */ private $taxons; /** * @var Collection * - * @ElasticSearch\Embedded(class="SyliusElasticSearchPlugin:AttributeValue", multiple=true) + * @ElasticSearch\Embedded(class="SyliusElasticSearchPlugin:AttributeValueDocument", multiple=true) */ private $attributeValues; /** * @var Collection * - * @ElasticSearch\Embedded(class="SyliusElasticSearchPlugin:Image", multiple=true) + * @ElasticSearch\Embedded(class="SyliusElasticSearchPlugin:ImageDocument", multiple=true) */ private $images; @@ -208,7 +208,7 @@ public function setDescription($description) } /** - * @return Price + * @return PriceDocument */ public function getPrice() { @@ -216,15 +216,15 @@ public function getPrice() } /** - * @param Price $price + * @param PriceDocument $price */ - public function setPrice(Price $price) + public function setPrice(PriceDocument $price) { $this->price = $price; } /** - * @return Taxon + * @return TaxonDocument */ public function getMainTaxon() { @@ -232,9 +232,9 @@ public function getMainTaxon() } /** - * @param Taxon $mainTaxon + * @param TaxonDocument $mainTaxon */ - public function setMainTaxon(Taxon $mainTaxon) + public function setMainTaxon(TaxonDocument $mainTaxon) { $this->mainTaxon = $mainTaxon; } diff --git a/src/Document/Taxon.php b/src/Document/TaxonDocument.php similarity index 95% rename from src/Document/Taxon.php rename to src/Document/TaxonDocument.php index 2d27ae0..aa096a3 100644 --- a/src/Document/Taxon.php +++ b/src/Document/TaxonDocument.php @@ -8,7 +8,7 @@ /** * @ElasticSearch\Object */ -final class Taxon +final class TaxonDocument { /** * @var string @@ -32,9 +32,9 @@ final class Taxon private $position; /** - * @var Image[]|Collection + * @var ImageDocument[]|Collection * - * @ElasticSearch\Embedded(class="SyliusElasticSearchPlugin:Image", multiple=true) + * @ElasticSearch\Embedded(class="SyliusElasticSearchPlugin:ImageDocument", multiple=true) */ private $images; diff --git a/src/Factory/ProductFactory.php b/src/Factory/ProductDocumentFactory.php similarity index 86% rename from src/Factory/ProductFactory.php rename to src/Factory/ProductDocumentFactory.php index fd7327d..3597ffd 100644 --- a/src/Factory/ProductFactory.php +++ b/src/Factory/ProductDocumentFactory.php @@ -10,30 +10,22 @@ use Sylius\Component\Core\Model\ProductVariantInterface; use Sylius\Component\Locale\Model\LocaleInterface; use Sylius\Component\Resource\Model\TranslationInterface; -use Sylius\ElasticSearchPlugin\Document\Attribute; -use Sylius\ElasticSearchPlugin\Document\AttributeValue; -use Sylius\ElasticSearchPlugin\Document\Image; -use Sylius\ElasticSearchPlugin\Document\Price; -use Sylius\ElasticSearchPlugin\Document\Product; -use Sylius\ElasticSearchPlugin\Document\Taxon; +use Sylius\ElasticSearchPlugin\Document\AttributeDocument; +use Sylius\ElasticSearchPlugin\Document\AttributeValueDocument; +use Sylius\ElasticSearchPlugin\Document\ImageDocument; +use Sylius\ElasticSearchPlugin\Document\PriceDocument; +use Sylius\ElasticSearchPlugin\Document\ProductDocument; +use Sylius\ElasticSearchPlugin\Document\TaxonDocument; use Sylius\ElasticSearchPlugin\Exception\UnsupportedFactoryMethodException; -final class ProductFactory implements ProductFactoryInterface +final class ProductDocumentFactory implements ProductDocumentFactoryInterface { - /** - * @return Product - */ - public function create() - { - return new Product(); - } - /** * @param ProductInterface $syliusProduct * @param LocaleInterface $locale * @param ChannelInterface $channel * - * @return Product + * @return ProductDocument */ public function createFromSyliusSimpleProductModel(ProductInterface $syliusProduct, LocaleInterface $locale, ChannelInterface $channel) { @@ -59,9 +51,9 @@ public function createFromSyliusSimpleProductModel(ProductInterface $syliusProdu ); $syliusProductTaxons = $syliusProduct->getProductTaxons(); - $product = new Product(); - $price = new Price(); - $taxon = new Taxon(); + $product = new ProductDocument(); + $price = new PriceDocument(); + $taxon = new TaxonDocument(); $taxon->setCode($syliusProduct->getMainTaxon()->getCode()); $taxon->setSlug($syliusProduct->getMainTaxon()->getSlug()); $taxon->setDescription($syliusProduct->getMainTaxon()->getDescription()); @@ -82,7 +74,7 @@ public function createFromSyliusSimpleProductModel(ProductInterface $syliusProdu $productImages = []; $syliusProductImages = $syliusProduct->getImages(); foreach ($syliusProductImages as $syliusProductImage) { - $productImage = new Image(); + $productImage = new ImageDocument(); $productImage->setPath($syliusProductImage->getPath()); $productImage->setCode($syliusProductImage->getType()); $productImages[] = $productImage; @@ -91,7 +83,7 @@ public function createFromSyliusSimpleProductModel(ProductInterface $syliusProdu $productTaxons = []; foreach ($syliusProductTaxons as $syliusProductTaxon) { - $productTaxon = new Taxon(); + $productTaxon = new TaxonDocument(); $productTaxon->setCode($syliusProductTaxon->getTaxon()->getCode()); $productTaxon->setSlug($syliusProductTaxon->getTaxon()->getSlug()); $productTaxon->setPosition($syliusProductTaxon->getTaxon()->getPosition()); @@ -100,7 +92,7 @@ public function createFromSyliusSimpleProductModel(ProductInterface $syliusProdu $productTaxonImages = []; $syliusTaxonImages = $syliusProductTaxon->getTaxon()->getImages(); foreach ($syliusTaxonImages as $syliusTaxonImage) { - $productTaxonImage = new Image(); + $productTaxonImage = new ImageDocument(); $productTaxonImage->setPath($syliusTaxonImage->getPath()); $productTaxonImage->setCode($syliusTaxonImage->getType()); $productTaxonImages[] = $productTaxonImage; @@ -113,10 +105,10 @@ public function createFromSyliusSimpleProductModel(ProductInterface $syliusProdu $productAttributeValues = []; foreach ($syliusProductAttributes as $syliusProductAttributeValue) { - $productAttributeValue = new AttributeValue(); + $productAttributeValue = new AttributeValueDocument(); $productAttributeValue->setValue($syliusProductAttributeValue->getValue()); - $attribute = new Attribute(); + $attribute = new AttributeDocument(); $attribute->setCode($syliusProductAttributeValue->getAttribute()->getCode()); $attribute->setName($syliusProductAttributeValue->getAttribute()->getName()); $productAttributeValue->setAttribute($attribute); diff --git a/src/Factory/ProductFactoryInterface.php b/src/Factory/ProductDocumentFactoryInterface.php similarity index 74% rename from src/Factory/ProductFactoryInterface.php rename to src/Factory/ProductDocumentFactoryInterface.php index 01281ec..d8a83ba 100644 --- a/src/Factory/ProductFactoryInterface.php +++ b/src/Factory/ProductDocumentFactoryInterface.php @@ -5,21 +5,16 @@ use Sylius\Component\Core\Model\ChannelInterface; use Sylius\Component\Core\Model\ProductInterface; use Sylius\Component\Locale\Model\LocaleInterface; -use Sylius\ElasticSearchPlugin\Document\Product; +use Sylius\ElasticSearchPlugin\Document\ProductDocument; -interface ProductFactoryInterface +interface ProductDocumentFactoryInterface { - /** - * @return Product - */ - public function create(); - /** * @param ProductInterface $product * @param LocaleInterface $locale * @param ChannelInterface $channel * - * @return Product + * @return ProductDocument */ public function createFromSyliusSimpleProductModel( ProductInterface $product, diff --git a/src/Factory/ProductListViewFactory.php b/src/Factory/ProductListViewFactory.php index d4fa9e4..4e5140f 100644 --- a/src/Factory/ProductListViewFactory.php +++ b/src/Factory/ProductListViewFactory.php @@ -11,8 +11,6 @@ use Sylius\ElasticSearchPlugin\Controller\ProductListItemView; use Sylius\ElasticSearchPlugin\Controller\ProductListView; use Sylius\ElasticSearchPlugin\Controller\ProductVariantItemView; -use Sylius\ElasticSearchPlugin\Controller\TaxonItemView; -use Sylius\ElasticSearchPlugin\Document\AttributeValue; use Sylius\ElasticSearchPlugin\Exception\UnsupportedFactoryMethodException; use Sylius\ElasticSearchPlugin\Search\Criteria\Paginating; diff --git a/src/Projection/ProductProjector.php b/src/Projection/ProductProjector.php index 1b0aacf..2621fd3 100644 --- a/src/Projection/ProductProjector.php +++ b/src/Projection/ProductProjector.php @@ -5,7 +5,7 @@ use ONGR\ElasticsearchBundle\Service\Manager; use Sylius\Component\Core\Model\ChannelInterface; use Sylius\ElasticSearchPlugin\Event\ProductCreated; -use Sylius\ElasticSearchPlugin\Factory\ProductFactoryInterface; +use Sylius\ElasticSearchPlugin\Factory\ProductDocumentFactoryInterface; final class ProductProjector { @@ -15,15 +15,15 @@ final class ProductProjector private $manager; /** - * @var ProductFactoryInterface + * @var ProductDocumentFactoryInterface */ private $productDocumentFactory; /** * @param Manager $manager - * @param ProductFactoryInterface $productDocumentFactory + * @param ProductDocumentFactoryInterface $productDocumentFactory */ - public function __construct(Manager $manager, ProductFactoryInterface $productDocumentFactory) + public function __construct(Manager $manager, ProductDocumentFactoryInterface $productDocumentFactory) { $this->manager = $manager; $this->productDocumentFactory = $productDocumentFactory; diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index b63d793..56ed6fb 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -18,7 +18,7 @@ - + diff --git a/tests/Behat/Context/Domain/Shop/ProductContext.php b/tests/Behat/Context/Domain/Shop/ProductContext.php index 44d0178..0ffaa7e 100644 --- a/tests/Behat/Context/Domain/Shop/ProductContext.php +++ b/tests/Behat/Context/Domain/Shop/ProductContext.php @@ -15,7 +15,7 @@ use ONGR\ElasticsearchBundle\Result\DocumentIterator; use Porpaginas\Page; use Porpaginas\Result; -use Sylius\ElasticSearchPlugin\Document\Product; +use Sylius\ElasticSearchPlugin\Document\ProductDocument; use Sylius\ElasticSearchPlugin\Search\Criteria\Criteria; use Sylius\ElasticSearchPlugin\Search\Criteria\Filtering\ProductHasOptionCodesFilter; use Sylius\ElasticSearchPlugin\Search\Criteria\Filtering\ProductInChannelFilter; @@ -53,7 +53,7 @@ public function __construct(SearchEngineInterface $searchEngine, SharedStorageIn */ public function iFilterThemByPriceBetweenAnd($graterThan, $lessThan) { - $criteria = Criteria::fromQueryParameters(Product::class, ['product_price_range' => ['grater_than' => $graterThan, 'less_than' => $lessThan]]); + $criteria = Criteria::fromQueryParameters(ProductDocument::class, ['product_price_range' => ['grater_than' => $graterThan, 'less_than' => $lessThan]]); $this->match($criteria); } @@ -62,7 +62,7 @@ public function iFilterThemByPriceBetweenAnd($graterThan, $lessThan) */ public function iViewTheListOfTheProductsWithoutFiltering() { - $criteria = Criteria::fromQueryParameters(Product::class, []); + $criteria = Criteria::fromQueryParameters(ProductDocument::class, []); $this->match($criteria); } @@ -71,7 +71,7 @@ public function iViewTheListOfTheProductsWithoutFiltering() */ public function iFilterThemByChannel($channelCode) { - $criteria = Criteria::fromQueryParameters(Product::class, ['channel_code' => $channelCode]); + $criteria = Criteria::fromQueryParameters(ProductDocument::class, ['channel_code' => $channelCode]); $this->match($criteria); } @@ -80,7 +80,7 @@ public function iFilterThemByChannel($channelCode) */ public function iFilterThemByChannelAndPriceBetweenAnd($channelCode, $graterThan, $lessThan) { - $criteria = Criteria::fromQueryParameters(Product::class, [ + $criteria = Criteria::fromQueryParameters(ProductDocument::class, [ 'channel_code' => $channelCode, 'product_price_range' => ['grater_than' => $graterThan, 'less_than' => $lessThan], ]); @@ -93,7 +93,7 @@ public function iFilterThemByChannelAndPriceBetweenAnd($channelCode, $graterThan */ public function iFilterThemByTaxon($taxonCode) { - $criteria = Criteria::fromQueryParameters(Product::class, ['taxon_code' => $taxonCode]); + $criteria = Criteria::fromQueryParameters(ProductDocument::class, ['taxon_code' => $taxonCode]); $this->match($criteria); } @@ -106,7 +106,7 @@ public function iSortThemByNameInAscendingOrder($field, $order) $field = '-' . $field; } - $criteria = Criteria::fromQueryParameters(Product::class, ['sort' => $field]); + $criteria = Criteria::fromQueryParameters(ProductDocument::class, ['sort' => $field]); $this->match($criteria); } @@ -115,7 +115,7 @@ public function iSortThemByNameInAscendingOrder($field, $order) */ public function iSearchForProductsWithName($name) { - $criteria = Criteria::fromQueryParameters(Product::class, ['search' => $name]); + $criteria = Criteria::fromQueryParameters(ProductDocument::class, ['search' => $name]); $this->match($criteria); } @@ -140,7 +140,7 @@ public function iShouldSeeProductsInOrderLike(...$productNames) /** * @var int $position - * @var Product $product + * @var ProductDocument $product */ foreach ($searchResult as $position => $product) { if ($product['name'] !== $productNames[$position]) { @@ -167,7 +167,7 @@ public function itShouldBe(...$expectedProductNames) /** @var Result $searchResult */ $searchResult = $this->sharedStorage->get('search_result'); - /** @var Product $product */ + /** @var ProductDocument $product */ foreach ($searchResult as $product) { Assert::oneOf($product['name'], $expectedProductNames); } diff --git a/tests/Behat/Context/Setup/ProductContext.php b/tests/Behat/Context/Setup/ProductContext.php index dbf8e9e..500873a 100644 --- a/tests/Behat/Context/Setup/ProductContext.php +++ b/tests/Behat/Context/Setup/ProductContext.php @@ -14,9 +14,9 @@ use Behat\Behat\Context\Context; use Doctrine\ORM\Id\UuidGenerator; use ONGR\ElasticsearchBundle\Service\Manager; -use Sylius\ElasticSearchPlugin\Document\Price; -use Sylius\ElasticSearchPlugin\Document\Product; -use Sylius\ElasticSearchPlugin\Document\Taxon; +use Sylius\ElasticSearchPlugin\Document\PriceDocument; +use Sylius\ElasticSearchPlugin\Document\ProductDocument; +use Sylius\ElasticSearchPlugin\Document\TaxonDocument; final class ProductContext implements Context { @@ -38,13 +38,13 @@ public function __construct(Manager $manager) */ public function theStoreHasAboutMugsAndStickers($mugsNumber, $stickersNumber, $booksNumber) { - $mugsTaxon = new Taxon(); + $mugsTaxon = new TaxonDocument(); $mugsTaxon->setCode('mugs'); - $stickersTaxon = new Taxon(); + $stickersTaxon = new TaxonDocument(); $stickersTaxon->setCode('stickers'); - $booksTaxon = new Taxon(); + $booksTaxon = new TaxonDocument(); $booksTaxon->setCode('books'); $this->generateProductsInTaxon($mugsNumber, $mugsTaxon); @@ -67,12 +67,12 @@ public function storeHasAProductPricedAt($productName, $price = 100, $channelCod /** * @param int $howMany - * @param Taxon $taxonCode + * @param TaxonDocument $taxonCode */ - private function generateProductsInTaxon($howMany, Taxon $taxonCode) + private function generateProductsInTaxon($howMany, TaxonDocument $taxonCode) { for ($i = 0; $i < $howMany; $i++) { - $product = new Product(); + $product = new ProductDocument(); $product->setMainTaxon($taxonCode); $product->setCode(uniqid()); $this->manager->persist($product); @@ -86,15 +86,15 @@ private function generateProductsInTaxon($howMany, Taxon $taxonCode) * @param int $priceAmount * @param string $channelCode * - * @return Product + * @return ProductDocument */ private function createProduct($productName, $priceAmount, $channelCode) { - $price = new Price(); + $price = new PriceDocument(); $price->setCurrency('USD'); $price->setAmount($priceAmount); - $product = new Product(); + $product = new ProductDocument(); $product->setCode(uniqid()); $product->setPrice($price); $product->setChannelCode($channelCode); diff --git a/tests/Factory/ProductFactoryTest.php b/tests/Factory/ProductDocumentFactoryTest.php similarity index 79% rename from tests/Factory/ProductFactoryTest.php rename to tests/Factory/ProductDocumentFactoryTest.php index b2f30fd..1839ef6 100644 --- a/tests/Factory/ProductFactoryTest.php +++ b/tests/Factory/ProductDocumentFactoryTest.php @@ -14,35 +14,15 @@ use Sylius\Component\Locale\Model\Locale; use Sylius\Component\Product\Model\ProductAttribute; use Sylius\Component\Product\Model\ProductAttributeValue; -use Sylius\ElasticSearchPlugin\Document\Attribute; -use Sylius\ElasticSearchPlugin\Document\AttributeValue; -use Sylius\ElasticSearchPlugin\Document\Product; -use Sylius\ElasticSearchPlugin\Document\Taxon; +use Sylius\ElasticSearchPlugin\Document\AttributeDocument; +use Sylius\ElasticSearchPlugin\Document\AttributeValueDocument; +use Sylius\ElasticSearchPlugin\Document\ProductDocument; +use Sylius\ElasticSearchPlugin\Document\TaxonDocument; use Sylius\ElasticSearchPlugin\Exception\UnsupportedFactoryMethodException; -use Sylius\ElasticSearchPlugin\Factory\ProductFactory; +use Sylius\ElasticSearchPlugin\Factory\ProductDocumentFactory; -final class ProductFactoryTest extends \PHPUnit_Framework_TestCase +final class ProductDocumentFactoryTest extends \PHPUnit_Framework_TestCase { - /** - * @test - */ - public function it_creates_new_empty_product_document() - { - $factory = new ProductFactory(); - /** @var Product $product */ - $product = $factory->create(); - - $this->assertEquals(null, $product->getCode()); - $this->assertEquals(null, $product->getName()); - $this->assertEquals(null, $product->getLocaleCode()); - $this->assertEquals(new Collection(), $product->getAttributeValues()); - $this->assertEquals(null, $product->getPrice()); - $this->assertEquals(null, $product->getChannelCode()); - $this->assertEquals(null, $product->getCreatedAt()); - $this->assertEquals(null, $product->getDescription()); - $this->assertEquals(new Collection(), $product->getTaxons()); - } - /** * @test */ @@ -101,31 +81,31 @@ public function it_creates_product_document_from_sylius_product_model() $syliusProduct->setCode('banana'); $syliusProduct->addAttribute($syliusProductAttributeValue); - $factory = new ProductFactory(); - /** @var Product $product */ + $factory = new ProductDocumentFactory(); + /** @var ProductDocument $product */ $product = $factory->createFromSyliusSimpleProductModel( $syliusProduct, $syliusLocale, $syliusChannel ); - $taxon = new Taxon(); + $taxon = new TaxonDocument(); $taxon->setCode('tree'); $taxon->setPosition(0); $taxon->setSlug('/tree'); $taxon->setDescription('Lorem ipsum'); - $productTaxon = new Taxon(); + $productTaxon = new TaxonDocument(); $productTaxon->setCode('tree'); $productTaxon->setSlug('/tree'); $productTaxon->setPosition(0); $productTaxon->setDescription('Lorem ipsum'); - $productAttribute = new Attribute(); + $productAttribute = new AttributeDocument(); $productAttribute->setCode('red'); $productAttribute->setName('Color red'); - $productAttributeValue = new AttributeValue(); + $productAttributeValue = new AttributeValueDocument(); $productAttributeValue->setValue('red'); $productAttributeValue->setAttribute($productAttribute); @@ -156,7 +136,7 @@ public function it_creates_product_document_from_sylius_product_model() public function it_cannot_create_product_document_from_configurable_product() { $this->expectException(UnsupportedFactoryMethodException::class); - $factory = new ProductFactory(); + $factory = new ProductDocumentFactory(); $syliusProduct = new SyliusProduct(); $syliusProduct->addVariant(new ProductVariant());