Skip to content

Commit

Permalink
Add processor test
Browse files Browse the repository at this point in the history
  • Loading branch information
mattamon committed Mar 4, 2024
1 parent d6f6f4d commit e21c1be
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Service/TranslatorServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Pimcore\Bundle\StudioApiBundle\Service;

use Pimcore\Bundle\StudioApiBundle\Dto\Translation;
use Pimcore\Bundle\StudioApiBundle\Dto\Translation;;

Check notice on line 16 in src/Service/TranslatorServiceInterface.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Unnecessary semicolon

Unnecessary ;

Check notice on line 16 in src/Service/TranslatorServiceInterface.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Unnecessary semicolon

\[EA\] Unnecessary semicolon.

Check notice on line 16 in src/Service/TranslatorServiceInterface.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Unnecessary semicolon

Unnecessary ;

Check notice on line 16 in src/Service/TranslatorServiceInterface.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Unnecessary semicolon

\[EA\] Unnecessary semicolon.

/**
* @internal
Expand Down
97 changes: 97 additions & 0 deletions tests/Unit/State/TranslationProcessorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under following license:
* - Pimcore Commercial License (PCL)
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license PCL
*/

namespace Pimcore\Bundle\StudioApiBundle\Tests\Unit\State;

use ApiPlatform\Exception\OperationNotFoundException;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\Post;
use Codeception\Test\Unit;
use Exception;
use Pimcore\Bundle\StudioApiBundle\Dto\Translation;
use Pimcore\Bundle\StudioApiBundle\Service\TranslatorServiceInterface;
use Pimcore\Bundle\StudioApiBundle\State\TranslationProcessor;
use stdClass;

final class TranslationProcessorTest extends Unit
{
/**
* @throws Exception
*/
public function testWrongUriTemplate(): void
{
$translationProcessor = $this->mockTranslationProcessor();

$this->expectException(OperationNotFoundException::class);

$translationProcessor->process(
$this->getTranslation(),
$this->getPostOperation('/wrong-uri-template')
);
}

/**
* @throws Exception
*/

public function testWrongOperation(): void
{
$translationProcessor = $this->mockTranslationProcessor();

$this->expectException(OperationNotFoundException::class);

$translationProcessor->process(
$this->getTranslation(),
$this->getGetOperation()
);
}

/**
* @throws Exception
*/
public function testWrongData(): void
{
$translationProcessor = $this->mockTranslationProcessor();

$this->expectException(OperationNotFoundException::class);

$translationProcessor->process(
new stdClass(),
$this->getPostOperation('/translations')
);
}

/**
* @throws Exception
*/
private function mockTranslationProcessor(): TranslationProcessor
{
$translatorInterface = $this->makeEmpty(TranslatorServiceInterface::class);
return new TranslationProcessor($translatorInterface);
}

private function getTranslation(): Translation
{
return new Translation('en', []);
}

private function getPostOperation(string $uriTemplate): Post
{
return new Post(uriTemplate: $uriTemplate);
}

private function getGetOperation(): Get
{
return new Get(uriTemplate: '/translations');
}
}

0 comments on commit e21c1be

Please sign in to comment.