-
Notifications
You must be signed in to change notification settings - Fork 155
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
6 changed files
with
389 additions
and
318 deletions.
There are no files selected for viewing
68 changes: 0 additions & 68 deletions
68
src/Component/spec/Doctrine/Common/State/RemoveProcessorSpec.php
This file was deleted.
Oops, something went wrong.
40 changes: 0 additions & 40 deletions
40
src/Component/spec/Doctrine/Persistence/Exception/ResourceExistsExceptionSpec.php
This file was deleted.
Oops, something went wrong.
210 changes: 0 additions & 210 deletions
210
src/Component/spec/Doctrine/Persistence/InMemoryRepositorySpec.php
This file was deleted.
Oops, something went wrong.
75 changes: 75 additions & 0 deletions
75
src/Component/tests/Doctrine/Common/State/RemoveProcessorTest.php
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,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())); | ||
} | ||
} |
Oops, something went wrong.