Skip to content

Commit

Permalink
Add other conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
loic425 committed Sep 10, 2024
1 parent 08e7af0 commit a2a6146
Show file tree
Hide file tree
Showing 6 changed files with 389 additions and 318 deletions.
68 changes: 0 additions & 68 deletions src/Component/spec/Doctrine/Common/State/RemoveProcessorSpec.php

This file was deleted.

This file was deleted.

210 changes: 0 additions & 210 deletions src/Component/spec/Doctrine/Persistence/InMemoryRepositorySpec.php

This file was deleted.

75 changes: 75 additions & 0 deletions src/Component/tests/Doctrine/Common/State/RemoveProcessorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?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\Resource\Tests\Doctrine\Common\State;

use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Persistence\ObjectManager;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Sylius\Resource\Context\Context;
use Sylius\Resource\Doctrine\Common\State\RemoveProcessor;
use Sylius\Resource\Metadata\Operation;

final class RemoveProcessorTest extends TestCase
{
use ProphecyTrait;

private ManagerRegistry|ObjectProphecy $managerRegistry;

private RemoveProcessor $removeProcessor;

protected function setUp(): void
{
$this->managerRegistry = $this->prophesize(ManagerRegistry::class);
$this->removeProcessor = new RemoveProcessor($this->managerRegistry->reveal());
}

public function testItIsInitializable(): void
{
$this->assertInstanceOf(RemoveProcessor::class, $this->removeProcessor);
}

public function testItRemovesData(): void
{
$data = new \stdClass();
$operation = $this->prophesize(Operation::class)->reveal();
$manager = $this->prophesize(ObjectManager::class);

$this->managerRegistry->getManagerForClass(\stdClass::class)->willReturn($manager->reveal());
$manager->contains($data)->willReturn(false);

$manager->remove($data)->shouldBeCalled();
$manager->flush()->shouldBeCalled();

$this->removeProcessor->process($data, $operation, new Context());
}

public function testItDoesNothingWhenDataIsNotManagedByDoctrine(): void
{
$data = new \stdClass();
$operation = $this->prophesize(Operation::class)->reveal();

$this->managerRegistry->getManagerForClass(\stdClass::class)->willReturn(null);

$this->assertNull($this->removeProcessor->process($data, $operation, new Context()));
}

public function testItDoesNothingWhenDataIsNotAnObject(): void
{
$operation = $this->prophesize(Operation::class)->reveal();

$this->assertNull($this->removeProcessor->process(1, $operation, new Context()));
}
}
Loading

0 comments on commit a2a6146

Please sign in to comment.