forked from Lakion/SyliusElasticSearchBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
838 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace spec\Sylius\ElasticSearchPlugin\Document; | ||
|
||
use Sylius\ElasticSearchPlugin\Document\Attribute; | ||
use Sylius\ElasticSearchPlugin\Document\AttributeValue; | ||
use PhpSpec\ObjectBehavior; | ||
use Prophecy\Argument; | ||
|
||
final class AttributeValueSpec extends ObjectBehavior | ||
{ | ||
function it_is_initializable() | ||
{ | ||
$this->shouldHaveType(AttributeValue::class); | ||
} | ||
|
||
function it_has_value() | ||
{ | ||
$this->setValue('Red'); | ||
|
||
$this->getValue()->shouldReturn('Red'); | ||
} | ||
|
||
function it_has_attribute() | ||
{ | ||
$attribute = new Attribute(); | ||
$this->setAttribute($attribute); | ||
|
||
$this->getAttribute()->shouldReturn($attribute); | ||
} | ||
|
||
function it_has_code() | ||
{ | ||
$this->setCode('red'); | ||
|
||
$this->getCode()->shouldReturn('red'); | ||
} | ||
} |
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,22 @@ | ||
<?php | ||
|
||
namespace spec\Sylius\ElasticSearchPlugin\Document; | ||
|
||
use Sylius\ElasticSearchPlugin\Document\TaxonCode; | ||
use PhpSpec\ObjectBehavior; | ||
use Prophecy\Argument; | ||
|
||
final class TaxonCodeSpec extends ObjectBehavior | ||
{ | ||
function it_is_initializable() | ||
{ | ||
$this->shouldHaveType(TaxonCode::class); | ||
} | ||
|
||
function it_has_value() | ||
{ | ||
$this->setValue('mug'); | ||
|
||
$this->getValue()->shouldReturn('mug'); | ||
} | ||
} |
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,42 @@ | ||
<?php | ||
|
||
namespace spec\Sylius\ElasticSearchPlugin\EventListener; | ||
|
||
use Doctrine\ORM\Event\LifecycleEventArgs; | ||
use SimpleBus\Message\Bus\MessageBus; | ||
use Sylius\Component\Core\Model\ProductInterface; | ||
use Sylius\ElasticSearchPlugin\Event\ProductCreated; | ||
use Sylius\ElasticSearchPlugin\EventListener\ProductPublisher; | ||
use PhpSpec\ObjectBehavior; | ||
use Prophecy\Argument; | ||
|
||
final class ProductPublisherSpec extends ObjectBehavior | ||
{ | ||
function let(MessageBus $eventBus) | ||
{ | ||
$this->beConstructedWith($eventBus); | ||
} | ||
|
||
function it_is_initializable() | ||
{ | ||
$this->shouldHaveType(ProductPublisher::class); | ||
} | ||
|
||
function it_publishes_product_event(MessageBus $eventBus, LifecycleEventArgs $event, ProductInterface $product) | ||
{ | ||
$event->getEntity()->willReturn($product); | ||
|
||
$eventBus->handle(ProductCreated::occur($product->getWrappedObject()))->shouldBeCalled(); | ||
|
||
$this->postPersist($event); | ||
} | ||
|
||
function it_does_not_publish_product_event_if_entity_is_not_a_product(MessageBus $eventBus, LifecycleEventArgs $event) | ||
{ | ||
$event->getEntity()->willReturn(new \stdClass()); | ||
|
||
$eventBus->handle(Argument::any())->shouldNotBeCalled(); | ||
|
||
$this->postPersist($event); | ||
} | ||
} |
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,78 @@ | ||
<?php | ||
|
||
namespace spec\Sylius\ElasticSearchPlugin\Projection; | ||
|
||
use Doctrine\Common\Collections\ArrayCollection; | ||
use ONGR\ElasticsearchBundle\Service\Manager; | ||
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\Event\ProductCreated; | ||
use Sylius\ElasticSearchPlugin\Factory\ProductFactoryInterface; | ||
use Sylius\ElasticSearchPlugin\Projection\ProductProjector; | ||
use PhpSpec\ObjectBehavior; | ||
use Prophecy\Argument; | ||
|
||
final class ProductProjectorSpec extends ObjectBehavior | ||
{ | ||
function let(Manager $manager, ProductFactoryInterface $factory) | ||
{ | ||
$this->beConstructedWith($manager, $factory); | ||
} | ||
|
||
function it_is_initializable() | ||
{ | ||
$this->shouldHaveType(ProductProjector::class); | ||
} | ||
|
||
function it_saves_product_document_if_product_has_channel_defined( | ||
Manager $manager, | ||
ProductFactoryInterface $factory, | ||
ProductInterface $product, | ||
LocaleInterface $locale, | ||
ChannelInterface $channel | ||
) { | ||
$channel->getLocales()->willReturn(new ArrayCollection([$locale->getWrappedObject()])); | ||
$product->getChannels()->willReturn(new ArrayCollection([$channel->getWrappedObject()])); | ||
|
||
$productDocument = new Product(); | ||
$factory->createFromSyliusSimpleProductModel($product, $locale, $channel)->willReturn($productDocument); | ||
|
||
$manager->persist($productDocument)->shouldBeCalled(); | ||
$manager->commit()->shouldBeCalled(); | ||
|
||
$this->handleProductCreated(ProductCreated::occur($product->getWrappedObject())); | ||
} | ||
|
||
function it_does_not_save_product_document_if_product_has_not_channel_defined( | ||
Manager $manager, | ||
ProductFactoryInterface $factory, | ||
ProductInterface $product | ||
) { | ||
$product->getChannels()->willReturn(new ArrayCollection([])); | ||
$factory->createFromSyliusSimpleProductModel(Argument::any(), Argument::any(), Argument::any())->shouldNotBeCalled(); | ||
|
||
$manager->persist(Argument::any())->shouldNotBeCalled(); | ||
$manager->commit()->shouldBeCalled(); | ||
|
||
$this->handleProductCreated(ProductCreated::occur($product->getWrappedObject())); | ||
} | ||
|
||
function it_does_not_save_product_document_if_channel_has_not_locales_defined( | ||
Manager $manager, | ||
ProductFactoryInterface $factory, | ||
ProductInterface $product, | ||
ChannelInterface $channel | ||
) { | ||
$channel->getLocales()->willReturn(new ArrayCollection([])); | ||
$product->getChannels()->willReturn(new ArrayCollection([$channel->getWrappedObject()])); | ||
|
||
$factory->createFromSyliusSimpleProductModel(Argument::any(), Argument::any(), Argument::any())->shouldNotBeCalled(); | ||
|
||
$manager->persist(Argument::any())->shouldNotBeCalled(); | ||
$manager->commit()->shouldBeCalled(); | ||
|
||
$this->handleProductCreated(ProductCreated::occur($product->getWrappedObject())); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -12,8 +12,12 @@ | |
namespace Sylius\ElasticSearchPlugin\Controller; | ||
|
||
use FOS\RestBundle\View\ConfigurableViewHandlerInterface; | ||
use FOS\RestBundle\View\View; | ||
use Sylius\ElasticSearchPlugin\Document\Product; | ||
use Sylius\ElasticSearchPlugin\Search\Criteria\Criteria; | ||
use Sylius\ElasticSearchPlugin\Search\SearchEngineInterface; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
/** | ||
* @author Arkadiusz Krakowiak <[email protected]> | ||
|
@@ -42,9 +46,18 @@ public function __construct(ConfigurableViewHandlerInterface $restViewHandler, S | |
|
||
/** | ||
* @param Request $request | ||
* | ||
* @return Response | ||
*/ | ||
public function searchAction(Request $request) | ||
{ | ||
$content = $request->getContent(); | ||
$criteria = Criteria::fromQueryParameters(Product::class, json_decode($content, true)); | ||
|
||
$result = $this->searchEngine->match($criteria); | ||
|
||
$view = View::create($result); | ||
|
||
return $this->restViewHandler->handle($view); | ||
} | ||
} |
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
Oops, something went wrong.