File tree Expand file tree Collapse file tree 2 files changed +68
-0
lines changed Expand file tree Collapse file tree 2 files changed +68
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments