Skip to content

Commit

Permalink
Move Media related exceptions to Media and improve rename method name
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Fedurtsya <[email protected]>
  • Loading branch information
Sieg committed Feb 5, 2024
1 parent e106a94 commit f9baf1f
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

declare(strict_types=1);

namespace OxidEsales\MediaLibrary\Exception;
namespace OxidEsales\MediaLibrary\Media\Exception;

class MediaNotFoundException extends \Exception
{
Expand Down
4 changes: 2 additions & 2 deletions src/Media/Repository/MediaRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
use Doctrine\DBAL\Exception;
use OxidEsales\EshopCommunity\Internal\Framework\Database\ConnectionProviderInterface;
use OxidEsales\EshopCommunity\Internal\Transition\Utility\BasicContextInterface;
use OxidEsales\MediaLibrary\Exception\MediaNotFoundException;
use OxidEsales\MediaLibrary\Media\DataType\MediaInterface;
use OxidEsales\MediaLibrary\Media\Exception\MediaNotFoundException;
use OxidEsales\MediaLibrary\Media\Exception\WrongMediaIdGivenException;

class MediaRepository implements MediaRepositoryInterface
Expand Down Expand Up @@ -112,7 +112,7 @@ private function getMediaSelectSqlPart(): string
/**
* @throws Exception
*/
public function rename(string $mediaIdToRename, string $newName): void
public function renameMedia(string $mediaIdToRename, string $newName): void
{
$this->connection->executeQuery(
"UPDATE ddmedia SET DDFILENAME = :DDFILENAME WHERE OXID = :OXID",
Expand Down
5 changes: 2 additions & 3 deletions src/Media/Repository/MediaRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

namespace OxidEsales\MediaLibrary\Media\Repository;

use Doctrine\DBAL\Exception;
use OxidEsales\MediaLibrary\Exception\MediaNotFoundException;
use OxidEsales\MediaLibrary\Media\DataType\MediaInterface;
use OxidEsales\MediaLibrary\Media\Exception\MediaNotFoundException;
use OxidEsales\MediaLibrary\Media\Exception\WrongMediaIdGivenException;

interface MediaRepositoryInterface
Expand All @@ -23,7 +22,7 @@ public function getMediaById(string $mediaId): ?MediaInterface;

public function addMedia(MediaInterface $exampleMedia): void;

public function rename(string $mediaIdToRename, string $newName): void;
public function renameMedia(string $mediaIdToRename, string $newName): void;

/**
* @throws WrongMediaIdGivenException
Expand Down
2 changes: 1 addition & 1 deletion src/Service/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function rename($sOldName, $sNewName, $sId, $sType = 'file')

$sNewName = basename($sNewPath);

$this->mediaRepository->rename($sId, $sNewName);
$this->mediaRepository->renameMedia($sId, $sNewName);

$aResult = [
'success' => true,
Expand Down
4 changes: 2 additions & 2 deletions tests/Integration/Media/Repository/MediaRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
use OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactoryInterface;
use OxidEsales\EshopCommunity\Internal\Transition\Utility\BasicContextInterface;
use OxidEsales\EshopCommunity\Tests\Integration\IntegrationTestCase;
use OxidEsales\MediaLibrary\Exception\MediaNotFoundException;
use OxidEsales\MediaLibrary\Image\DataTransfer\ImageSize;
use OxidEsales\MediaLibrary\Image\Service\ThumbnailResourceInterface;
use OxidEsales\MediaLibrary\Media\DataType\Media;
use OxidEsales\MediaLibrary\Media\Exception\MediaNotFoundException;
use OxidEsales\MediaLibrary\Media\Exception\WrongMediaIdGivenException;
use OxidEsales\MediaLibrary\Media\Repository\MediaFactory;
use OxidEsales\MediaLibrary\Media\Repository\MediaFactoryInterface;
Expand Down Expand Up @@ -245,7 +245,7 @@ public function testRenameMedia(): void
$newName = 'NewName';

$sut = $this->getSut();
$sut->rename($mediaIdToRename, $newName);
$sut->renameMedia($mediaIdToRename, $newName);

$updatedData = $sut->getMediaById($mediaIdToRename);
$this->assertSame($newName, $updatedData->getFileName());
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Service/MediaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function testRename($structure, $oldName, $newName, $structureExpected, $
);

$mediaRepositorySpy = $this->createMock(MediaRepositoryInterface::class);
$mediaRepositorySpy->expects($this->once())->method('rename');
$mediaRepositorySpy->expects($this->once())->method('renameMedia');

$sut = $this->getSut(
shopConfig: $shopConfigMock,
Expand Down

0 comments on commit f9baf1f

Please sign in to comment.