Skip to content

Commit

Permalink
Update the serialization of variants (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
wachterjohannes authored May 3, 2021
1 parent a4adfdf commit 51fb045
Show file tree
Hide file tree
Showing 51 changed files with 264 additions and 135 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ jobs:
run: (cd tests/Application && bin/console doctrine:schema:validate)

-
name: Run php-cs-fixer
run: vendor/bin/php-cs-fixer
name: Run php-cs-fixer
run: vendor/bin/php-cs-fixer fix --verbose --diff --dry-run

-
name: Run PHPStan
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@
/phpspec.yml

.idea

.php_cs.cache
2 changes: 1 addition & 1 deletion .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
$header = <<<'EOF'
This file is part of Sulu.
(c) MASSIVE ART WebServices GmbH
(c) Sulu GmbH
This source file is subject to the MIT license that is bundled
with this source code in the file LICENSE.
Expand Down
18 changes: 14 additions & 4 deletions bin/create_node_symlink.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
<?php

declare(strict_types=1);

/*
* This file is part of Sulu.
*
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

const NODE_MODULES_FOLDER_NAME = 'node_modules';
const PATH_TO_NODE_MODULES = 'tests' . DIRECTORY_SEPARATOR . 'Application' . DIRECTORY_SEPARATOR . 'node_modules';

/* cannot use `file_exists` or `stat` as gives false on symlinks if target path does not exist yet */
if (@lstat(NODE_MODULES_FOLDER_NAME))
{
if (@lstat(NODE_MODULES_FOLDER_NAME)) {
if (is_link(NODE_MODULES_FOLDER_NAME) || is_dir(NODE_MODULES_FOLDER_NAME)) {
echo '> `' . NODE_MODULES_FOLDER_NAME . '` already exists as a link or folder, keeping existing as may be intentional.' . PHP_EOL;
exit(0);
Expand All @@ -22,12 +32,12 @@
$success = @symlink(PATH_TO_NODE_MODULES, NODE_MODULES_FOLDER_NAME);

/* if case it has failed, but OS is Windows... */
if (!$success && strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
if (!$success && 'WIN' === strtoupper(substr(PHP_OS, 0, 3))) {
/* ...then try a different approach which does not require elevated permissions and folder to exist */
echo '> This system is running Windows, creation of links requires elevated privileges,' . PHP_EOL;
echo '> and target path to exist. Fallback to NTFS Junction:' . PHP_EOL;
exec(sprintf('mklink /J %s %s 2> NUL', NODE_MODULES_FOLDER_NAME, PATH_TO_NODE_MODULES), $output, $returnCode);
$success = $returnCode === 0;
$success = 0 === $returnCode;
if (!$success) {
echo '> Failed o create the required symlink' . PHP_EOL;
exit(2);
Expand Down
2 changes: 1 addition & 1 deletion lib/Message/RemoveProductMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of Sulu.
*
* (c) MASSIVE ART WebServices GmbH
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
Expand Down
2 changes: 1 addition & 1 deletion lib/Message/RemoveProductVariantMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of Sulu.
*
* (c) MASSIVE ART WebServices GmbH
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
Expand Down
2 changes: 1 addition & 1 deletion lib/Message/RemoveTaxonMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of Sulu.
*
* (c) MASSIVE ART WebServices GmbH
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
Expand Down
2 changes: 1 addition & 1 deletion lib/Message/SynchronizeProductMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of Sulu.
*
* (c) MASSIVE ART WebServices GmbH
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
Expand Down
2 changes: 1 addition & 1 deletion lib/Message/SynchronizeProductVariantMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of Sulu.
*
* (c) MASSIVE ART WebServices GmbH
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
Expand Down
2 changes: 1 addition & 1 deletion lib/Message/SynchronizeTaxonMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of Sulu.
*
* (c) MASSIVE ART WebServices GmbH
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
Expand Down
2 changes: 1 addition & 1 deletion spec/EventSubscriber/ProductEventSubscriberSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of Sulu.
*
* (c) MASSIVE ART WebServices GmbH
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
Expand Down
2 changes: 1 addition & 1 deletion spec/EventSubscriber/TaxonEventSubscriberSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of Sulu.
*
* (c) MASSIVE ART WebServices GmbH
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
Expand Down
2 changes: 1 addition & 1 deletion spec/Producer/ProductMessageProducerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of Sulu.
*
* (c) MASSIVE ART WebServices GmbH
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
Expand Down
13 changes: 6 additions & 7 deletions spec/Producer/ProductVariantMessageProducerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@
/*
* This file is part of Sulu.
*
* (c) MASSIVE ART WebServices GmbH
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace spec\Sulu\SyliusProducerPlugin\Producer;

use JMS\Serializer\SerializationContext;
use JMS\Serializer\SerializerInterface;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Sulu\Bundle\SyliusConsumerBundle\Message\RemoveProductVariantMessage;
use Sulu\Bundle\SyliusConsumerBundle\Message\SynchronizeProductVariantMessage;
use Sulu\SyliusProducerPlugin\Producer\ProductVariantMessageProducer;
use Sulu\SyliusProducerPlugin\Producer\Serializer\ProductVariantSerializerInterface;
use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Core\Model\ProductVariantInterface;
use Symfony\Component\Messenger\Envelope;
Expand All @@ -28,7 +27,7 @@
class ProductVariantMessageProducerSpec extends ObjectBehavior
{
public function let(
SerializerInterface $serializer,
ProductVariantSerializerInterface $serializer,
MessageBusInterface $messageBus
): void {
$this->beConstructedWith($serializer, $messageBus);
Expand All @@ -40,16 +39,16 @@ public function it_is_initializable(): void
}

public function it_should_dispatch_synchronize_message(
SerializerInterface $serializer,
ProductVariantSerializerInterface $serializer,
MessageBusInterface $messageBus,
ProductVariantInterface $productVariant,
ProductInterface $product
): void {
$productVariant->getCode()->willReturn('product-1-variant-0');
$productVariant->getProduct()->willReturn($product);
$product->getCode()->willReturn('product-1');
$serializer->serialize($productVariant, 'json', Argument::type(SerializationContext::class))
->shouldBeCalled()->willReturn('{"code": "product-1"}');
$serializer->serialize($productVariant)
->shouldBeCalled()->willReturn(['code' => 'product-1']);

$messageBus->dispatch(
Argument::that(
Expand Down
2 changes: 1 addition & 1 deletion spec/Producer/TaxonMessageProducerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of Sulu.
*
* (c) MASSIVE ART WebServices GmbH
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
Expand Down
2 changes: 1 addition & 1 deletion src/Command/BaseSynchronizeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of Sulu.
*
* (c) MASSIVE ART WebServices GmbH
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
Expand Down
2 changes: 1 addition & 1 deletion src/Command/SynchronizeProductVariantsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of Sulu.
*
* (c) MASSIVE ART WebServices GmbH
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
Expand Down
6 changes: 3 additions & 3 deletions src/Command/SynchronizeProductsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of Sulu.
*
* (c) MASSIVE ART WebServices GmbH
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
Expand Down Expand Up @@ -50,13 +50,13 @@ public function __construct(
$this->productRepository = $productRepository;
}

protected function configure():void
protected function configure(): void
{
$this->setName('sulu-sylius:synchronize:products')
->setDescription('Synchronize all products to Sulu');
}

protected function execute(InputInterface $input, OutputInterface $output):int
protected function execute(InputInterface $input, OutputInterface $output): int
{
parent::execute($input, $output);

Expand Down
4 changes: 2 additions & 2 deletions src/Command/SynchronizeTaxonCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of Sulu.
*
* (c) MASSIVE ART WebServices GmbH
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
Expand Down Expand Up @@ -49,7 +49,7 @@ public function __construct(
$this->taxonRepository = $taxonRepository;
}

protected function configure():void
protected function configure(): void
{
$this->setName('sulu-sylius:synchronize:taxon')
->setDescription('Synchronize taxon tree to Sulu');
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of Sulu.
*
* (c) MASSIVE ART WebServices GmbH
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
Expand Down
4 changes: 2 additions & 2 deletions src/DependencyInjection/SuluSyliusProducerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of Sulu.
*
* (c) MASSIVE ART WebServices GmbH
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
Expand All @@ -21,7 +21,7 @@

final class SuluSyliusProducerExtension extends Extension implements PrependExtensionInterface
{
public function prepend(ContainerBuilder $container):void
public function prepend(ContainerBuilder $container): void
{
if ($container->hasExtension('framework')) {
$container->prependExtensionConfig('framework', [
Expand Down
8 changes: 6 additions & 2 deletions src/EventSubscriber/AddressSerializeEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of Sulu.
*
* (c) MASSIVE ART WebServices GmbH
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
Expand All @@ -16,6 +16,7 @@
use JMS\Serializer\EventDispatcher\Events;
use JMS\Serializer\EventDispatcher\EventSubscriberInterface;
use JMS\Serializer\EventDispatcher\ObjectEvent;
use JMS\Serializer\JsonSerializationVisitor;
use Sylius\Component\Addressing\Model\AddressInterface;

class AddressSerializeEventSubscriber implements EventSubscriberInterface
Expand Down Expand Up @@ -44,7 +45,10 @@ public function onPostSerialize(ObjectEvent $event): void
}

if (null !== $object->getCompany()) {
$event->getVisitor()->setData('company', $object->getCompany());
/** @var JsonSerializationVisitor $visitor */
$visitor = $event->getVisitor();

$visitor->setData('company', $object->getCompany());
}
}
}
8 changes: 6 additions & 2 deletions src/EventSubscriber/CustomDataSerializeEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of Sulu.
*
* (c) MASSIVE ART WebServices GmbH
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
Expand All @@ -16,6 +16,7 @@
use JMS\Serializer\EventDispatcher\Events;
use JMS\Serializer\EventDispatcher\EventSubscriberInterface;
use JMS\Serializer\EventDispatcher\ObjectEvent;
use JMS\Serializer\JsonSerializationVisitor;
use Sulu\SyliusProducerPlugin\Model\CustomDataInterface;

class CustomDataSerializeEventSubscriber implements EventSubscriberInterface
Expand Down Expand Up @@ -43,6 +44,9 @@ public function onPostSerialize(ObjectEvent $event): void
return;
}

$event->getVisitor()->setData('customData', $object->getCustomData());
/** @var JsonSerializationVisitor $visitor */
$visitor = $event->getVisitor();

$visitor->setData('customData', $object->getCustomData());
}
}
4 changes: 2 additions & 2 deletions src/EventSubscriber/CustomerEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of Sulu.
*
* (c) MASSIVE ART WebServices GmbH
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
Expand Down Expand Up @@ -37,7 +37,7 @@ public function __construct(GeneratorInterface $tokenGenerator)
$this->tokenGenerator = $tokenGenerator;
}

public function createToken(GenericEvent $event):void
public function createToken(GenericEvent $event): void
{
$customer = $event->getSubject();
if (!$customer instanceof CustomerInterface) {
Expand Down
8 changes: 6 additions & 2 deletions src/EventSubscriber/OrderSerializeEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/*
* This file is part of Sulu.
*
* (c) MASSIVE ART WebServices GmbH
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
Expand All @@ -16,6 +16,7 @@
use JMS\Serializer\EventDispatcher\Events;
use JMS\Serializer\EventDispatcher\EventSubscriberInterface;
use JMS\Serializer\EventDispatcher\ObjectEvent;
use JMS\Serializer\JsonSerializationVisitor;
use Sylius\Component\Order\Model\OrderInterface;

class OrderSerializeEventSubscriber implements EventSubscriberInterface
Expand Down Expand Up @@ -44,7 +45,10 @@ public function onPostSerialize(ObjectEvent $event): void
}

if (null !== $object->getNotes()) {
$event->getVisitor()->setData('notes', $object->getNotes());
/** @var JsonSerializationVisitor $visitor */
$visitor = $event->getVisitor();

$visitor->setData('notes', $object->getNotes());
}
}
}
Loading

0 comments on commit 51fb045

Please sign in to comment.