Skip to content

Commit

Permalink
[ElasticSearch] Define api end point
Browse files Browse the repository at this point in the history
  • Loading branch information
Arminek committed May 29, 2017
1 parent 505822b commit 0f83a8b
Show file tree
Hide file tree
Showing 51 changed files with 278 additions and 758 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ language: php

php:
- 7.1
- 5.6

jdk:
- oraclejdk8
Expand All @@ -13,7 +12,7 @@ addons:
- elasticsearch-5.x
packages:
- elasticsearch
- oracle-java8-installer
- oracle-java8-set-default

services:
- elasticsearch
Expand Down
35 changes: 7 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Sylius ElasticSearchBundle
Sylius ElasticSearchPlugin
==========================
Elastic search for Sylius.
[![Build status on Linux](https://img.shields.io/travis/Lakion/SyliusElasticSearchBundle/master.svg)](http://travis-ci.org/Lakion/SyliusELasticSearchBundle)
Expand All @@ -8,12 +8,12 @@ Elastic search for Sylius.
1. Install it:

```bash
$ composer require lakion/sylius-elastic-search-bundle
$ composer require sylius/elastic-search-plugin
```
2. Install elastic search server:

```bash
$ brew install elasticsearch@2.4
$ brew install elasticsearch@5.0
```

3. Run elastic search server:
Expand All @@ -25,8 +25,8 @@ Elastic search for Sylius.
4. Add this bundle to `AppKernel.php`:

```php
new \FOS\ElasticaBundle\FOSElasticaBundle(),
new \Lakion\SyliusElasticSearchBundle\LakionSyliusElasticSearchBundle(),
new \ONGR\ElasticsearchBundle\ONGRElasticsearchBundle(),
new \Lakion\SyliusElasticSearchBundle\SyliusElasticSearchPlugin(),
```

5. Create/Setup database:
Expand All @@ -37,37 +37,16 @@ Elastic search for Sylius.
$ app/console syl:fix:lo
```

6. Populate your elastic search server with command or your custom code:

```bash
$ app/console fos:elastic:pop
```

7. Import config file in `app/config/config.yml` for default filter set configuration:

```yaml
imports:
- { resource: "@LakionSyliusElasticSearchBundle/Resources/config/app/config.yml" }
- { resource: "@SyliusElasticSearchPlugin/Resources/config/app/config.yml" }
```
8. Import routing files in `app/config/routing.yml`:
```yaml
sylius_search:
resource: "@LakionSyliusElasticSearchBundle/Resources/config/routing.yml"
```
8. Configuration reference:
```yaml
sylius_elastic_search:
filter_sets:
mugs:
filters:
product_options:
type: option
options:
code: mug_type
product_price:
type: price
resource: "@SyliusElasticSearchPlugin/Resources/config/routing.yml"
```
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"sylius/sylius": "dev-master",
"ongr/elasticsearch-dsl": "^5.0",
"ongr/elasticsearch-bundle": "^5.0",
"simple-bus/symfony-bridge": "^4.1"
"simple-bus/symfony-bridge": "^4.1",
"beberlei/porpaginas": "^1.0"
},
"require-dev": {
"behat/behat": "^3.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ Feature: Filtering list of products by taxon
I want to be able to filter the products

Background:
Given the store has 40 Mugs, 15 Stickers and 50 Books
Given the store has 3 Mugs, 2 Stickers and 5 Books

@domain
Scenario: Filtering products by book
When I filter them by "books" taxon
Then I should see 50 products on the list
Then I should see 5 products on the list

@domain
Scenario: Filtering product by stickers
When I filter them by "stickers" taxon
Then I should see 15 products on the list
Then I should see 2 products on the list

@domain
Scenario: Filtering product by mugs
When I filter them by "mugs" taxon
Then I should see 40 products on the list
Then I should see 3 products on the list

@domain
Scenario: List of all products without filtering
When I view the list of the products without filtering
Then I should see 105 products on the list
Then I should see 10 products on the list
14 changes: 14 additions & 0 deletions spec/EventListener/ProductPublisherSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function it_is_initializable()

function it_publishes_product_event(MessageBus $eventBus, LifecycleEventArgs $event, ProductInterface $product)
{
$product->isSimple()->willReturn(true);
$event->getEntity()->willReturn($product);

$eventBus->handle(ProductCreated::occur($product->getWrappedObject()))->shouldBeCalled();
Expand All @@ -39,4 +40,17 @@ function it_does_not_publish_product_event_if_entity_is_not_a_product(MessageBus

$this->postPersist($event);
}

function it_does_not_publish_product_event_if_entity_is_not_a_simple_product(
MessageBus $eventBus,
LifecycleEventArgs $event,
ProductInterface $product
) {
$product->isSimple()->willReturn(false);
$event->getEntity()->willReturn($product);

$eventBus->handle(Argument::any())->shouldNotBeCalled();

$this->postPersist($event);
}
}
8 changes: 4 additions & 4 deletions spec/Search/Criteria/CriteriaSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ function it_is_created_from_query_parameters_and_resource_alias()
'option' => 'red',
]]);

$this->getResourceAlias()->shouldReturn('sylius.product');
$this->getFiltering()->shouldBeLike(Filtering::fromQueryParameters([
$this->documentClass()->shouldReturn('sylius.product');
$this->filtering()->shouldBeLike(Filtering::fromQueryParameters([
'page' => 2,
'per_page' => 50,
'sort' => '-price',
'option' => 'red',
]));
$this->getPaginating()->shouldBeLike(Paginating::fromQueryParameters([
$this->paginating()->shouldBeLike(Paginating::fromQueryParameters([
'page' => 2,
'per_page' => 50,
'sort' => '-price',
'option' => 'red',
]));
$this->getOrdering()->shouldBeLike(Ordering::fromQueryParameters([
$this->ordering()->shouldBeLike(Ordering::fromQueryParameters([
'page' => 2,
'per_page' => 50,
'sort' => '-price',
Expand Down
27 changes: 0 additions & 27 deletions spec/Search/Criteria/Filtering/ProductHasOptionCodesFilterSpec.php

This file was deleted.

27 changes: 0 additions & 27 deletions spec/Search/Criteria/Filtering/ProductInChannelFilterSpec.php

This file was deleted.

32 changes: 0 additions & 32 deletions spec/Search/Criteria/Filtering/ProductInPriceRangeFilterSpec.php

This file was deleted.

27 changes: 0 additions & 27 deletions spec/Search/Criteria/Filtering/ProductInTaxonFilterSpec.php

This file was deleted.

4 changes: 2 additions & 2 deletions spec/Search/Criteria/FilteringSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function it_can_be_created_from_query_parameters()
'size' => 's',
]]);

$this->getFields()->shouldReturn(['option' => 'red', 'size' => 's',]);
$this->fields()->shouldReturn(['option' => 'red', 'size' => 's',]);
}

function it_removes_page_per_page_and_sort_attributes_from_query_parameters()
Expand All @@ -35,6 +35,6 @@ function it_removes_page_per_page_and_sort_attributes_from_query_parameters()
'limit' => 50,
]]);

$this->getFields()->shouldReturn(['option' => 'blue', 'size' => 'm',]);
$this->fields()->shouldReturn(['option' => 'blue', 'size' => 'm',]);
}
}
8 changes: 4 additions & 4 deletions spec/Search/Criteria/OrderingSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ function it_can_be_created_from_query_parameters_with_default_direction()
'sort' => 'code',
]]);

$this->getField()->shouldReturn('code.raw');
$this->getDirection()->shouldReturn('asc');
$this->field()->shouldReturn('code.raw');
$this->direction()->shouldReturn('asc');
}

function it_can_be_created_from_query_parameters()
Expand All @@ -31,7 +31,7 @@ function it_can_be_created_from_query_parameters()
'sort' => '-code',
]]);

$this->getField()->shouldReturn('code.raw');
$this->getDirection()->shouldReturn('desc');
$this->field()->shouldReturn('code.raw');
$this->direction()->shouldReturn('desc');
}
}
18 changes: 9 additions & 9 deletions spec/Search/Criteria/PaginatingSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ function it_can_be_created_form_query_parameters_with_default_values_if_paramete
{
$this->beConstructedThrough('fromQueryParameters', [[]]);

$this->getCurrentPage()->shouldReturn(1);
$this->getItemsPerPage()->shouldReturn(10);
$this->getOffset()->shouldReturn(0);
$this->currentPage()->shouldReturn(1);
$this->itemsPerPage()->shouldReturn(10);
$this->offset()->shouldReturn(0);
}

function it_can_be_created_from_query_parameters_with_default_values_if_parameters_are_not_valid()
Expand All @@ -31,9 +31,9 @@ function it_can_be_created_from_query_parameters_with_default_values_if_paramete
'limit' => -100,
]]);

$this->getCurrentPage()->shouldReturn(1);
$this->getItemsPerPage()->shouldReturn(10);
$this->getOffset()->shouldReturn(0);
$this->currentPage()->shouldReturn(1);
$this->itemsPerPage()->shouldReturn(10);
$this->offset()->shouldReturn(0);
}

function it_can_be_created_from_query_parameters()
Expand All @@ -43,8 +43,8 @@ function it_can_be_created_from_query_parameters()
'limit' => 50,
]]);

$this->getCurrentPage()->shouldReturn(2);
$this->getItemsPerPage()->shouldReturn(50);
$this->getOffset()->shouldReturn(50);
$this->currentPage()->shouldReturn(2);
$this->itemsPerPage()->shouldReturn(50);
$this->offset()->shouldReturn(50);
}
}
Loading

0 comments on commit 0f83a8b

Please sign in to comment.