Skip to content

Commit 365964e

Browse files
committed
file with proper extension can be set
1 parent 60e4d17 commit 365964e

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

src/IptcManager.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace IgorBudasov\IptcManager;
6+
7+
class IptcManager
8+
{
9+
private const SUPPORTED_FILE_TYPES = ['jpg', 'jpeg', 'pjpeg'];
10+
11+
/**
12+
* @var string
13+
*/
14+
private $pathToFile;
15+
16+
/**
17+
* @param string $pathToFile
18+
*/
19+
public function setPathToFile(string $pathToFile): void
20+
{
21+
$fileExtension = \pathinfo($pathToFile, PATHINFO_EXTENSION);
22+
if (!\in_array($fileExtension, self::SUPPORTED_FILE_TYPES)) {
23+
throw new \InvalidArgumentException(
24+
'Supported file types are: '.\json_encode(self::SUPPORTED_FILE_TYPES)
25+
);
26+
}
27+
28+
$this->pathToFile = $pathToFile;
29+
}
30+
}

tests/IptcTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace IgorBudasov\IptcManager\Tests;
6+
7+
use IgorBudasov\IptcManager\IptcManager;
8+
use PHPUnit\Framework\TestCase;
9+
10+
class IptcTest extends TestCase
11+
{
12+
public function testThatClassCanBeInstantiated(): void
13+
{
14+
$manager = new IptcManager();
15+
16+
self::assertInstanceOf(IptcManager::class, $manager);
17+
}
18+
19+
public function testThatPathToFileCanBeSetWhenFileTypeIsCorrect(): void
20+
{
21+
$pathToFile = '/tmp/test.jpg';
22+
23+
$manager = new IptcManager();
24+
25+
self::assertNull($manager->setPathToFile($pathToFile));
26+
}
27+
28+
public function testThatExceptionIsThrownWhenFileExtensionIsNotSupported(): void
29+
{
30+
$this->expectException(\InvalidArgumentException::class);
31+
32+
$pathToFile = '/tmp/test.wrong';
33+
34+
$manager = new IptcManager();
35+
36+
$manager->setPathToFile($pathToFile);
37+
}
38+
}

0 commit comments

Comments
 (0)