Skip to content

Commit b120c2a

Browse files
author
Tom Van Herreweghe
committed
Add property on Exif class to contain the raw data; Refactored unit tests
Signed-off-by: Tom Van Herreweghe <tom@king-foo.be>
1 parent 9f6afbe commit b120c2a

File tree

2 files changed

+63
-33
lines changed

2 files changed

+63
-33
lines changed

lib/PHPExif/Exif.php

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,31 +49,38 @@ class Exif
4949
const WIDTH = 'width';
5050

5151
/**
52-
* The EXIF data
52+
* The mapped EXIF data
5353
*
5454
* @var array
5555
*/
5656
protected $data = array();
5757

58+
/**
59+
* The raw EXIF data
60+
*
61+
* @var array
62+
*/
63+
protected $rawData = array();
64+
5865
/**
5966
* Class constructor
6067
*
6168
* @param array $data
6269
*/
6370
public function __construct(array $data = array())
6471
{
65-
$this->setRawData($data);
72+
$this->setData($data);
6673
}
6774

6875
/**
69-
* Sets the EXIF data
76+
* Sets the raw EXIF data
7077
*
7178
* @param array $data The data to set
7279
* @return \PHPExif\Exif Current instance for chaining
7380
*/
7481
public function setRawData(array $data)
7582
{
76-
$this->data = $data;
83+
$this->rawData = $data;
7784

7885
return $this;
7986
}
@@ -84,6 +91,29 @@ public function setRawData(array $data)
8491
* @return array
8592
*/
8693
public function getRawData()
94+
{
95+
return $this->rawData;
96+
}
97+
98+
/**
99+
* Sets the mapped EXIF data
100+
*
101+
* @param array $data The data to set
102+
* @return \PHPExif\Exif Current instance for chaining
103+
*/
104+
public function setData(array $data)
105+
{
106+
$this->data = $data;
107+
108+
return $this;
109+
}
110+
111+
/**
112+
* Returns the mapped EXIF data
113+
*
114+
* @return array
115+
*/
116+
public function getData()
87117
{
88118
return $this->data;
89119
}

tests/PHPExif/ExifTest.php

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function setUp()
2020
*/
2121
public function testGetRawData()
2222
{
23-
$reflProperty = new \ReflectionProperty('\PHPExif\Exif', 'data');
23+
$reflProperty = new \ReflectionProperty('\PHPExif\Exif', 'rawData');
2424
$reflProperty->setAccessible(true);
2525

2626
$this->assertEquals($reflProperty->getValue($this->exif), $this->exif->getRawData());
@@ -32,7 +32,7 @@ public function testGetRawData()
3232
public function testSetRawData()
3333
{
3434
$testData = array('foo', 'bar', 'baz');
35-
$reflProperty = new \ReflectionProperty('\PHPExif\Exif', 'data');
35+
$reflProperty = new \ReflectionProperty('\PHPExif\Exif', 'rawData');
3636
$reflProperty->setAccessible(true);
3737

3838
$result = $this->exif->setRawData($testData);
@@ -93,7 +93,7 @@ public function testGetAperture()
9393
{
9494
$expected = 'f/8.0';
9595
$data[\PHPExif\Exif::APERTURE] = $expected;
96-
$this->exif->setRawData($data);
96+
$this->exif->setData($data);
9797

9898
$this->assertEquals($expected, $this->exif->getAperture());
9999
}
@@ -106,7 +106,7 @@ public function testGetIso()
106106
{
107107
$expected = 200;
108108
$data[\PHPExif\Exif::ISO] = $expected;
109-
$this->exif->setRawData($data);
109+
$this->exif->setData($data);
110110
$this->assertEquals($expected, $this->exif->getIso());
111111
}
112112

@@ -118,7 +118,7 @@ public function testGetExposure()
118118
{
119119
$expected = '1/320';
120120
$data[\PHPExif\Exif::EXPOSURE] = $expected;
121-
$this->exif->setRawData($data);
121+
$this->exif->setData($data);
122122
$this->assertEquals($expected, $this->exif->getExposure());
123123
}
124124

@@ -130,7 +130,7 @@ public function testGetExposureMilliseconds()
130130
{
131131
$expected = 1/320;
132132
$data[\PHPExif\Exif::EXPOSURE] = '1/320';
133-
$this->exif->setRawData($data);
133+
$this->exif->setData($data);
134134
$this->assertEquals($expected, $this->exif->getExposureMilliseconds());
135135
}
136136

@@ -142,7 +142,7 @@ public function testGetFocusDistance()
142142
{
143143
$expected = '7.94m';
144144
$data[\PHPExif\Exif::FOCAL_DISTANCE] = $expected;
145-
$this->exif->setRawData($data);
145+
$this->exif->setData($data);
146146
$this->assertEquals($expected, $this->exif->getFocusDistance());
147147
}
148148

@@ -154,7 +154,7 @@ public function testGetWidth()
154154
{
155155
$expected = 500;
156156
$data[\PHPExif\Exif::WIDTH] = $expected;
157-
$this->exif->setRawData($data);
157+
$this->exif->setData($data);
158158
$this->assertEquals($expected, $this->exif->getWidth());
159159
}
160160

@@ -166,7 +166,7 @@ public function testGetHeight()
166166
{
167167
$expected = 332;
168168
$data[\PHPExif\Exif::HEIGHT] = $expected;
169-
$this->exif->setRawData($data);
169+
$this->exif->setData($data);
170170
$this->assertEquals($expected, $this->exif->getHeight());
171171
}
172172

@@ -178,7 +178,7 @@ public function testGetTitle()
178178
{
179179
$expected = 'Morning Glory Pool';
180180
$data[\PHPExif\Exif::TITLE] = $expected;
181-
$this->exif->setRawData($data);
181+
$this->exif->setData($data);
182182
$this->assertEquals($expected, $this->exif->getTitle());
183183
}
184184

@@ -190,7 +190,7 @@ public function testGetCaption()
190190
{
191191
$expected = 'Foo Bar Baz';
192192
$data[\PHPExif\Exif::CAPTION] = $expected;
193-
$this->exif->setRawData($data);
193+
$this->exif->setData($data);
194194
$this->assertEquals($expected, $this->exif->getCaption());
195195
}
196196

@@ -202,7 +202,7 @@ public function testGetCopyright()
202202
{
203203
$expected = 'Miljar';
204204
$data[\PHPExif\Exif::COPYRIGHT] = $expected;
205-
$this->exif->setRawData($data);
205+
$this->exif->setData($data);
206206
$this->assertEquals($expected, $this->exif->getCopyright());
207207
}
208208

@@ -214,7 +214,7 @@ public function testGetKeywords()
214214
{
215215
$expected = array('18-200', 'D90', 'USA', 'Wyoming', 'Yellowstone');
216216
$data[\PHPExif\Exif::KEYWORDS] = $expected;
217-
$this->exif->setRawData($data);
217+
$this->exif->setData($data);
218218
$this->assertEquals($expected, $this->exif->getKeywords());
219219
}
220220

@@ -226,7 +226,7 @@ public function testGetCamera()
226226
{
227227
$expected = 'NIKON D90';
228228
$data[\PHPExif\Exif::CAMERA] = $expected;
229-
$this->exif->setRawData($data);
229+
$this->exif->setData($data);
230230
$this->assertEquals($expected, $this->exif->getCamera());
231231
}
232232

@@ -238,7 +238,7 @@ public function testGetHorizontalResolution()
238238
{
239239
$expected = 240;
240240
$data[\PHPExif\Exif::HORIZONTAL_RESOLUTION] = $expected;
241-
$this->exif->setRawData($data);
241+
$this->exif->setData($data);
242242
$this->assertEquals($expected, $this->exif->getHorizontalResolution());
243243
}
244244

@@ -250,7 +250,7 @@ public function testGetVerticalResolution()
250250
{
251251
$expected = 240;
252252
$data[\PHPExif\Exif::VERTICAL_RESOLUTION] = $expected;
253-
$this->exif->setRawData($data);
253+
$this->exif->setData($data);
254254
$this->assertEquals($expected, $this->exif->getVerticalResolution());
255255
}
256256

@@ -262,7 +262,7 @@ public function testGetSoftware()
262262
{
263263
$expected = 'Adobe Photoshop Lightroom';
264264
$data[\PHPExif\Exif::SOFTWARE] = $expected;
265-
$this->exif->setRawData($data);
265+
$this->exif->setData($data);
266266
$this->assertEquals($expected, $this->exif->getSoftware());
267267
}
268268

@@ -274,7 +274,7 @@ public function testGetFocalLength()
274274
{
275275
$expected = 18;
276276
$data[\PHPExif\Exif::FOCAL_LENGTH] = $expected;
277-
$this->exif->setRawData($data);
277+
$this->exif->setData($data);
278278
$this->assertEquals($expected, $this->exif->getFocalLength());
279279
}
280280

@@ -287,7 +287,7 @@ public function testGetCreationDate()
287287
$expected = '2011-06-07 20:01:50';
288288
$input = \DateTime::createFromFormat('Y-m-d H:i:s', $expected);
289289
$data[\PHPExif\Exif::CREATION_DATE] = $input;
290-
$this->exif->setRawData($data);
290+
$this->exif->setData($data);
291291
$this->assertEquals($expected, $this->exif->getCreationDate()->format('Y-m-d H:i:s'));
292292
}
293293

@@ -299,7 +299,7 @@ public function testGetAuthor()
299299
{
300300
$expected = 'John Smith';
301301
$data[\PHPExif\Exif::AUTHOR] = $expected;
302-
$this->exif->setRawData($data);
302+
$this->exif->setData($data);
303303
$this->assertEquals($expected, $this->exif->getAuthor());
304304
}
305305

@@ -311,7 +311,7 @@ public function testGetHeadline()
311311
{
312312
$expected = 'Foobar Baz';
313313
$data[\PHPExif\Exif::HEADLINE] = $expected;
314-
$this->exif->setRawData($data);
314+
$this->exif->setData($data);
315315
$this->assertEquals($expected, $this->exif->getHeadline());
316316
}
317317

@@ -323,7 +323,7 @@ public function testGetCredit()
323323
{
324324
$expected = 'john.smith@example.com';
325325
$data[\PHPExif\Exif::CREDIT] = $expected;
326-
$this->exif->setRawData($data);
326+
$this->exif->setData($data);
327327
$this->assertEquals($expected, $this->exif->getCredit());
328328
}
329329

@@ -335,7 +335,7 @@ public function testGetSource()
335335
{
336336
$expected = 'FBB NEWS';
337337
$data[\PHPExif\Exif::SOURCE] = $expected;
338-
$this->exif->setRawData($data);
338+
$this->exif->setData($data);
339339
$this->assertEquals($expected, $this->exif->getSource());
340340
}
341341

@@ -347,7 +347,7 @@ public function testGetJobtitle()
347347
{
348348
$expected = 'Yellowstone\'s geysers and pools';
349349
$data[\PHPExif\Exif::JOB_TITLE] = $expected;
350-
$this->exif->setRawData($data);
350+
$this->exif->setData($data);
351351
$this->assertEquals($expected, $this->exif->getJobtitle());
352352
}
353353

@@ -359,7 +359,7 @@ public function testGetColorSpace()
359359
{
360360
$expected = 'RGB';
361361
$data[\PHPExif\Exif::COLORSPACE] = $expected;
362-
$this->exif->setRawData($data);
362+
$this->exif->setData($data);
363363
$this->assertEquals($expected, $this->exif->getColorSpace());
364364
}
365365

@@ -371,7 +371,7 @@ public function testGetMimeType()
371371
{
372372
$expected = 'image/jpeg';
373373
$data[\PHPExif\Exif::MIMETYPE] = $expected;
374-
$this->exif->setRawData($data);
374+
$this->exif->setData($data);
375375
$this->assertEquals($expected, $this->exif->getMimeType());
376376
}
377377

@@ -383,15 +383,15 @@ public function testGetFileSize()
383383
{
384384
$expected = '27852365';
385385
$data[\PHPExif\Exif::FILESIZE] = $expected;
386-
$this->exif->setRawData($data);
386+
$this->exif->setData($data);
387387
$this->assertEquals($expected, $this->exif->getFileSize());
388388
}
389389

390390
public function testGetOrientation()
391391
{
392392
$expected = 1;
393393
$data[\PHPExif\Exif::ORIENTATION] = $expected;
394-
$this->exif->setRawData($data);
394+
$this->exif->setData($data);
395395
$this->assertEquals($expected, $this->exif->getOrientation());
396396
}
397397

@@ -428,4 +428,4 @@ public function testAdapterConsistency()
428428
}
429429
}
430430
}
431-
}
431+
}

0 commit comments

Comments
 (0)