[API] Remove obsolete ProductAttributeDataPersister class

This commit is contained in:
Rafikooo 2024-08-02 11:49:50 +02:00
parent 15ed55168c
commit a366ab8762
No known key found for this signature in database
GPG key ID: 4A26D8327BC2442B
4 changed files with 0 additions and 154 deletions

View file

@ -745,36 +745,6 @@ parameters:
count: 1
path: src/Sylius/Bundle/ApiBundle/DataPersister/PaymentMethodDataPersister.php
-
message: "#^Method Sylius\\\\Bundle\\\\ApiBundle\\\\DataPersister\\\\ProductAttributeDataPersister\\:\\:persist\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
count: 1
path: src/Sylius/Bundle/ApiBundle/DataPersister/ProductAttributeDataPersister.php
-
message: "#^Method Sylius\\\\Bundle\\\\ApiBundle\\\\DataPersister\\\\ProductAttributeDataPersister\\:\\:remove\\(\\) has no return type specified\\.$#"
count: 1
path: src/Sylius/Bundle/ApiBundle/DataPersister/ProductAttributeDataPersister.php
-
message: "#^Method Sylius\\\\Bundle\\\\ApiBundle\\\\DataPersister\\\\ProductAttributeDataPersister\\:\\:remove\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
count: 1
path: src/Sylius/Bundle/ApiBundle/DataPersister/ProductAttributeDataPersister.php
-
message: "#^Method Sylius\\\\Bundle\\\\ApiBundle\\\\DataPersister\\\\ProductAttributeDataPersister\\:\\:remove\\(\\) has parameter \\$data with no type specified\\.$#"
count: 1
path: src/Sylius/Bundle/ApiBundle/DataPersister/ProductAttributeDataPersister.php
-
message: "#^Method Sylius\\\\Bundle\\\\ApiBundle\\\\DataPersister\\\\ProductAttributeDataPersister\\:\\:supports\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
count: 1
path: src/Sylius/Bundle/ApiBundle/DataPersister/ProductAttributeDataPersister.php
-
message: "#^Method Sylius\\\\Bundle\\\\ApiBundle\\\\DataPersister\\\\ProductAttributeDataPersister\\:\\:supports\\(\\) has parameter \\$data with no type specified\\.$#"
count: 1
path: src/Sylius/Bundle/ApiBundle/DataPersister/ProductAttributeDataPersister.php
-
message: "#^Method Sylius\\\\Bundle\\\\ApiBundle\\\\DataPersister\\\\ProductDataPersister\\:\\:persist\\(\\) has parameter \\$data with no type specified\\.$#"
count: 1

View file

@ -1,47 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Sylius\Bundle\ApiBundle\DataPersister;
use ApiPlatform\Core\DataPersister\ContextAwareDataPersisterInterface;
use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException;
use Sylius\Bundle\ApiBundle\Exception\ProductAttributeCannotBeRemoved;
use Sylius\Component\Product\Model\ProductAttributeInterface;
final class ProductAttributeDataPersister implements ContextAwareDataPersisterInterface
{
public function __construct(
private ContextAwareDataPersisterInterface $decoratedDataPersister,
) {
}
public function supports($data, array $context = []): bool
{
return $data instanceof ProductAttributeInterface;
}
/** @param ProductAttributeInterface $data */
public function persist($data, array $context = [])
{
return $this->decoratedDataPersister->persist($data, $context);
}
public function remove($data, array $context = [])
{
try {
return $this->decoratedDataPersister->remove($data, $context);
} catch (ForeignKeyConstraintViolationException) {
throw new ProductAttributeCannotBeRemoved();
}
}
}

View file

@ -39,11 +39,6 @@
<tag name="api_platform.data_persister" />
</service>
<service id="Sylius\Bundle\ApiBundle\DataPersister\ProductAttributeDataPersister">
<argument type="service" id="api_platform.doctrine.orm.data_persister" />
<tag name="api_platform.data_persister" />
</service>
<service id="Sylius\Bundle\ApiBundle\DataPersister\ProductTaxonDataPersister">
<argument type="service" id="api_platform.doctrine.orm.data_persister" />
<argument type="service" id="sylius.event_bus" />

View file

@ -1,72 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace spec\Sylius\Bundle\ApiBundle\DataPersister;
use ApiPlatform\Core\DataPersister\ContextAwareDataPersisterInterface;
use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException;
use PhpSpec\ObjectBehavior;
use Sylius\Bundle\ApiBundle\Exception\ProductAttributeCannotBeRemoved;
use Sylius\Component\Product\Model\ProductAttributeInterface;
final class ProductAttributeDataPersisterSpec extends ObjectBehavior
{
function let(ContextAwareDataPersisterInterface $persister): void
{
$this->beConstructedWith($persister);
}
function it_is_a_context_aware_persister(): void
{
$this->shouldImplement(ContextAwareDataPersisterInterface::class);
}
function it_supports_only_product_attribute(ProductAttributeInterface $productAttribute): void
{
$this->supports(new \stdClass())->shouldReturn(false);
$this->supports($productAttribute)->shouldReturn(true);
}
function it_uses_inner_persister_to_persist_product_attribute(
ContextAwareDataPersisterInterface $persister,
ProductAttributeInterface $productAttribute,
): void {
$persister->persist($productAttribute, [])->shouldBeCalled();
$this->persist($productAttribute, []);
}
function it_throws_cannot_be_removed_exception_if_constraint_fails_on_removal(
ContextAwareDataPersisterInterface $persister,
ProductAttributeInterface $productAttribute,
): void {
$persister
->remove($productAttribute, [])
->willThrow(ForeignKeyConstraintViolationException::class)
;
$this
->shouldThrow(ProductAttributeCannotBeRemoved::class)
->during('remove', [$productAttribute])
;
}
function it_uses_inner_persister_to_remove_product_attribute(
ContextAwareDataPersisterInterface $persister,
ProductAttributeInterface $productAttribute,
): void {
$persister->remove($productAttribute, [])->shouldBeCalled();
$this->remove($productAttribute, []);
}
}