Skip to content
This repository has been archived by the owner on Aug 3, 2018. It is now read-only.

Commit

Permalink
Merge pull request #2 from Sylius/tweak-api-response
Browse files Browse the repository at this point in the history
[API] Tweak api response
  • Loading branch information
lchrusciel authored Jun 5, 2017
2 parents 7e514f1 + 37b1775 commit 1ca29d2
Show file tree
Hide file tree
Showing 41 changed files with 1,703 additions and 199 deletions.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"beberlei/porpaginas": "^1.0"
},
"require-dev": {
"symfony/symfony": "~3.2, <3.3",
"behat/behat": "^3.2",
"behat/mink": "^1.7",
"behat/mink-browserkit-driver": "^1.3",
Expand All @@ -36,7 +37,8 @@
"php-http/guzzle6-adapter": "^1.1",
"phpspec/phpspec": "^3.2",
"phpunit/phpunit": "^5.6",
"behat/mink-selenium2-driver": "^1.3"
"behat/mink-selenium2-driver": "^1.3",
"lakion/api-test-case": "^1.1"
},
"config": {
"bin-dir": "bin"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ Feature: Filtering list of products by channels
I want to be able to filter the products

Background:
Given the store has a product "Banana T-Shirt" priced at "$100" in "tablets" channel
And the store also has a product "Star Wars T-Shirt" priced at "$150" in "mobile" channel
And the store also has a product "LOTR T-Shirt" priced at "$300" in "mobile" channel
And the store also has a product "Breaking Bad T-Shirt" priced at "$50" in "mobile" channel
And the store also has a product "Westworld T-Shirt" priced at "$1000" in "europe" channel
And the store also has a product "Orange T-Shirt" priced at "$1000" in "europe" channel
Given the store has a product "Banana T-Shirt" priced at "$100" in "Tablets" channel
And the store also has a product "Star Wars T-Shirt" priced at "$150" in "Mobile" channel
And the store also has a product "LOTR T-Shirt" priced at "$300" in "Mobile" channel
And the store also has a product "Breaking Bad T-Shirt" priced at "$50" in "Mobile" channel
And the store also has a product "Westworld T-Shirt" priced at "$1000" in "Europe" channel
And the store also has a product "Orange T-Shirt" priced at "$1000" in "Europe" channel

@domain
Scenario: Filtering products by mobile channel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ Feature: Filtering list of products by channels and price
I want to be able to filter the products

Background:
Given the store has a product "Banana T-Shirt" priced at "$100" in "tablets" channel
And the store also has a product "Star Wars T-Shirt" priced at "$150" in "mobile" channel
And the store also has a product "LOTR T-Shirt" priced at "$300" in "mobile" channel
And the store also has a product "Breaking Bad T-Shirt" priced at "$50" in "mobile" channel
And the store also has a product "Westworld T-Shirt" priced at "$1000" in "europe" channel
And the store also has a product "Orange T-Shirt" priced at "$1000" in "europe" channel
Given the store has a product "Banana T-Shirt" priced at "$100" in "Tablets" channel
And the store also has a product "Star Wars T-Shirt" priced at "$150" in "Mobile" channel
And the store also has a product "LOTR T-Shirt" priced at "$300" in "Mobile" channel
And the store also has a product "Breaking Bad T-Shirt" priced at "$50" in "Mobile" channel
And the store also has a product "Westworld T-Shirt" priced at "$1000" in "Europe" channel
And the store also has a product "Orange T-Shirt" priced at "$1000" in "Europe" channel

@domain
Scenario: Filtering products by mobile channel and price range
Expand Down
1 change: 0 additions & 1 deletion spec/Document/AttributeSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace spec\Sylius\ElasticSearchPlugin\Document;

use ONGR\ElasticsearchBundle\Collection\Collection;
use Sylius\ElasticSearchPlugin\Document\Attribute;
use PhpSpec\ObjectBehavior;

Expand Down
8 changes: 0 additions & 8 deletions spec/Document/AttributeValueSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Sylius\ElasticSearchPlugin\Document\Attribute;
use Sylius\ElasticSearchPlugin\Document\AttributeValue;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

final class AttributeValueSpec extends ObjectBehavior
{
Expand All @@ -28,11 +27,4 @@ function it_has_attribute()

$this->getAttribute()->shouldReturn($attribute);
}

function it_has_code()
{
$this->setCode('red');

$this->getCode()->shouldReturn('red');
}
}
28 changes: 28 additions & 0 deletions spec/Document/ImageSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace spec\Sylius\ElasticSearchPlugin\Document;

use Sylius\ElasticSearchPlugin\Document\Image;
use PhpSpec\ObjectBehavior;

final class ImageSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType(Image::class);
}

function it_has_code()
{
$this->setCode('abc');

$this->getCode()->shouldReturn('abc');
}

function it_has_path()
{
$this->setPath('/abc');

$this->getPath()->shouldReturn('/abc');
}
}
33 changes: 24 additions & 9 deletions spec/Document/ProductSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Sylius\ElasticSearchPlugin\Document\Price;
use Sylius\ElasticSearchPlugin\Document\Product;
use PhpSpec\ObjectBehavior;
use Sylius\ElasticSearchPlugin\Document\TaxonCode;
use Sylius\ElasticSearchPlugin\Document\Taxon;

final class ProductSpec extends ObjectBehavior
{
Expand Down Expand Up @@ -58,20 +58,20 @@ function it_has_price()
$this->getPrice()->shouldReturn($price);
}

function it_has_main_taxon_code()
function it_has_main_taxon()
{
$taxonCode = new TaxonCode();
$this->setMainTaxonCode($taxonCode);
$taxon = new Taxon();
$this->setMainTaxon($taxon);

$this->getMainTaxonCode()->shouldReturn($taxonCode);
$this->getMainTaxon()->shouldReturn($taxon);
}

function it_has_taxon_codes()
function it_has_taxons()
{
$taxonCodes = new Collection();
$this->setTaxonCodes($taxonCodes);
$taxons = new Collection();
$this->setTaxons($taxons);

$this->getTaxonCodes()->shouldReturn($taxonCodes);
$this->getTaxons()->shouldReturn($taxons);
}

function it_has_attributes()
Expand All @@ -81,4 +81,19 @@ function it_has_attributes()

$this->getAttributeValues()->shouldReturn($attributeValues);
}

function it_has_slug()
{
$this->setSlug('/mug');

$this->getSlug()->shouldReturn('/mug');
}

function it_has_images()
{
$images = new Collection();
$this->setImages($images);

$this->getImages()->shouldReturn($images);
}
}
22 changes: 0 additions & 22 deletions spec/Document/TaxonCodeSpec.php

This file was deleted.

51 changes: 51 additions & 0 deletions spec/Document/TaxonSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace spec\Sylius\ElasticSearchPlugin\Document;

use ONGR\ElasticsearchBundle\Collection\Collection;
use Sylius\ElasticSearchPlugin\Document\Taxon;
use PhpSpec\ObjectBehavior;

final class TaxonSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType(Taxon::class);
}

function it_has_code()
{
$this->setCode('mug');

$this->getCode()->shouldReturn('mug');
}

function it_has_slug()
{
$this->setSlug('/mug');

$this->getSlug()->shouldReturn('/mug');
}

function it_has_position()
{
$this->setPosition(1);

$this->getPosition()->shouldReturn(1);
}

function it_has_images()
{
$images = new Collection();
$this->setImages($images);

$this->getImages()->shouldReturn($images);
}

function it_has_description()
{
$this->setDescription('Lorem ipsum');

$this->getDescription()->shouldReturn('Lorem ipsum');
}
}
43 changes: 31 additions & 12 deletions spec/EventListener/ProductPublisherSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace spec\Sylius\ElasticSearchPlugin\EventListener;

use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Event\OnFlushEventArgs;
use Doctrine\ORM\UnitOfWork;
use SimpleBus\Message\Bus\MessageBus;
use Sylius\Component\Core\Model\ProductInterface;
use Sylius\ElasticSearchPlugin\Event\ProductCreated;
Expand All @@ -22,35 +24,52 @@ function it_is_initializable()
$this->shouldHaveType(ProductPublisher::class);
}

function it_publishes_product_event(MessageBus $eventBus, LifecycleEventArgs $event, ProductInterface $product)
{
function it_publishes_product_event(
MessageBus $eventBus,
OnFlushEventArgs $event,
ProductInterface $product,
EntityManager $entityManager,
UnitOfWork $unitOfWork
) {
$product->isSimple()->willReturn(true);
$event->getEntity()->willReturn($product);
$event->getEntityManager()->willReturn($entityManager);
$entityManager->getUnitOfWork()->willReturn($unitOfWork);
$unitOfWork->getScheduledEntityInsertions()->willReturn([$product]);

$eventBus->handle(ProductCreated::occur($product->getWrappedObject()))->shouldBeCalled();

$this->postPersist($event);
$this->onFlush($event);
}

function it_does_not_publish_product_event_if_entity_is_not_a_product(MessageBus $eventBus, LifecycleEventArgs $event)
{
$event->getEntity()->willReturn(new \stdClass());
function it_does_not_publish_product_event_if_entity_is_not_a_product(
MessageBus $eventBus,
OnFlushEventArgs $event,
EntityManager $entityManager,
UnitOfWork $unitOfWork
) {
$event->getEntityManager()->willReturn($entityManager);
$entityManager->getUnitOfWork()->willReturn($unitOfWork);
$unitOfWork->getScheduledEntityInsertions()->willReturn([new \stdClass()]);

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

$this->postPersist($event);
$this->onFlush($event);
}

function it_does_not_publish_product_event_if_entity_is_not_a_simple_product(
MessageBus $eventBus,
LifecycleEventArgs $event,
OnFlushEventArgs $event,
EntityManager $entityManager,
UnitOfWork $unitOfWork,
ProductInterface $product
) {
$event->getEntityManager()->willReturn($entityManager);
$entityManager->getUnitOfWork()->willReturn($unitOfWork);
$unitOfWork->getScheduledEntityInsertions()->willReturn([$product]);
$product->isSimple()->willReturn(false);
$event->getEntity()->willReturn($product);

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

$this->postPersist($event);
$this->onFlush($event);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function it_is_query_factory()

function it_creates_query()
{
$this->create(['taxon_code' => 'mugs'])->shouldBeLike(new TermQuery('main_taxon_code.value', 'mugs'));
$this->create(['taxon_code' => 'mugs'])->shouldBeLike(new TermQuery('main_taxon.code', 'mugs'));
}

function it_cannot_create_query_if_there_is_no_required_parameters()
Expand Down
16 changes: 16 additions & 0 deletions src/Controller/ImageItemView.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Sylius\ElasticSearchPlugin\Controller;

final class ImageItemView
{
/**
* @var string
*/
public $code;

/**
* @var string
*/
public $path;
}
18 changes: 18 additions & 0 deletions src/Controller/PriceView.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Sylius\ElasticSearchPlugin\Controller;

final class PriceView
{
/**
* @var int
*/
public $current;

/**
* @var string
*/
public $currency;
}
Loading

0 comments on commit 1ca29d2

Please sign in to comment.