Skip to content

Commit 88e5ece

Browse files
committed
#reader-interface fixed @Covers notations + fixed example in README + cleaned reader immutable behavior
1 parent d517b09 commit 88e5ece

File tree

4 files changed

+36
-72
lines changed

4 files changed

+36
-72
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ $reader = \PHPExif\Reader::factory(\PHPExif\Reader::TYPE_NATIVE);
2828
// reader with Exiftool adapter
2929
//$reader = \PHPExif\Reader::factory(\PHPExif\Reader::TYPE_EXIFTOOL);
3030

31-
$exif = $reader->getExifFromFile('/path/to/file');
31+
$exif = $reader->read('/path/to/file');
3232

3333
echo 'Title: ' . $exif->getTitle() . PHP_EOL;
3434
```
@@ -44,7 +44,7 @@ $adapter = new \PHPExif\Reader\Adapter\Exiftool(
4444
);
4545
$reader = new \PHPExif\Reader($adapter);
4646

47-
$exif = $reader->getExifFromFile('/path/to/file');
47+
$exif = $reader->read('/path/to/file');
4848

4949
echo 'Title: ' . $exif->getTitle() . PHP_EOL;
5050
```

lib/PHPExif/Reader/Reader.php

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,27 +45,10 @@ class Reader implements ReaderInterface
4545
public function __construct(AdapterInterface $adapter = null)
4646
{
4747
if (!is_null($adapter)) {
48-
$this->setAdapter($adapter);
48+
$this->adapter = $adapter;
4949
}
5050
}
5151

52-
/**
53-
* Setter for the reader adapter
54-
*
55-
* @param \PHPExif\Adapter\AdapterInterface $adapter
56-
* @return $this Current instance for chaining
57-
* @throws ImmutableException when adapter is already set
58-
*/
59-
public function setAdapter(AdapterInterface $adapter)
60-
{
61-
if (isset($this->adapter)) {
62-
throw new ImmutableException('cannot override adapter');
63-
}
64-
$this->adapter = $adapter;
65-
66-
return $this;
67-
}
68-
6952
/**
7053
* Getter for the reader adapter
7154
*
@@ -108,10 +91,7 @@ public static function factory($type)
10891
);
10992
break;
11093
}
111-
$result = new $classname();
112-
$result->setAdapter($adapter);
113-
114-
return $result;
94+
return $classname($adapter);
11595
}
11696

11797
/**
@@ -124,4 +104,15 @@ public function read($file)
124104
{
125105
return $this->getAdapter()->getExifFromFile($file);
126106
}
107+
108+
/**
109+
* alias to read method
110+
*
111+
* @param string $file
112+
* @return \PHPExif\Exif Instance of Exif object with data
113+
*/
114+
public function getExifFromFile($file)
115+
{
116+
return $this->read($file);
117+
}
127118
}

tests/PHPExif/Reader/AdapterAbstractTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function setUp()
1414

1515
/**
1616
* @group adapter
17-
* @covers \PHPExif\AdapterAbstract::determinePropertyGetter
17+
* @covers \PHPExif\Adapter\AdapterAbstract::determinePropertyGetter
1818
*/
1919
public function testDeterminePropertyGetter()
2020
{
@@ -31,7 +31,7 @@ public function testDeterminePropertyGetter()
3131

3232
/**
3333
* @group adapter
34-
* @covers \PHPExif\AdapterAbstract::determinePropertySetter
34+
* @covers \PHPExif\Adapter\AdapterAbstract::determinePropertySetter
3535
*/
3636
public function testDeterminePropertySetter()
3737
{
@@ -48,7 +48,7 @@ public function testDeterminePropertySetter()
4848

4949
/**
5050
* @group adapter
51-
* @covers \PHPExif\AdapterAbstract::getClassConstantsOfType
51+
* @covers \PHPExif\Adapter\AdapterAbstract::getClassConstantsOfType
5252
*/
5353
public function testGetClassConstantsOfTypeAlwaysReturnsArray()
5454
{
@@ -60,7 +60,7 @@ public function testGetClassConstantsOfTypeAlwaysReturnsArray()
6060

6161
/**
6262
* @group adapter
63-
* @covers \PHPExif\AdapterAbstract::getClassConstantsOfType
63+
* @covers \PHPExif\Adapter\AdapterAbstract::getClassConstantsOfType
6464
*/
6565
public function testGetClassConstantsOfTypeReturnsCorrectData()
6666
{
@@ -74,7 +74,7 @@ public function testGetClassConstantsOfTypeReturnsCorrectData()
7474

7575
/**
7676
* @group adapter
77-
* @covers \PHPExif\AdapterAbstract::toArray
77+
* @covers \PHPExif\Adapter\AdapterAbstract::toArray
7878
*/
7979
public function testToArrayReturnsPropertiesWithGetters()
8080
{
@@ -90,7 +90,7 @@ public function testToArrayReturnsPropertiesWithGetters()
9090

9191
/**
9292
* @group adapter
93-
* @covers \PHPExif\AdapterAbstract::toArray
93+
* @covers \PHPExif\Adapter\AdapterAbstract::toArray
9494
*/
9595
public function testToArrayOmmitsPropertiesWithoutGetters()
9696
{
@@ -105,7 +105,7 @@ public function testToArrayOmmitsPropertiesWithoutGetters()
105105

106106
/**
107107
* @group adapter
108-
* @covers \PHPExif\AdapterAbstract::setOptions
108+
* @covers \PHPExif\Adapter\AdapterAbstract::setOptions
109109
*/
110110
public function testSetOptionsReturnsCurrentInstance()
111111
{
@@ -115,7 +115,7 @@ public function testSetOptionsReturnsCurrentInstance()
115115

116116
/**
117117
* @group adapter
118-
* @covers \PHPExif\AdapterAbstract::setOptions
118+
* @covers \PHPExif\Adapter\AdapterAbstract::setOptions
119119
*/
120120
public function testSetOptionsCorrectlySetsProperties()
121121
{
@@ -135,7 +135,7 @@ public function testSetOptionsCorrectlySetsProperties()
135135

136136
/**
137137
* @group adapter
138-
* @covers \PHPExif\AdapterAbstract::setOptions
138+
* @covers \PHPExif\Adapter\AdapterAbstract::setOptions
139139
*/
140140
public function testSetOptionsIgnoresPropertiesWithoutSetters()
141141
{
@@ -154,7 +154,7 @@ public function testSetOptionsIgnoresPropertiesWithoutSetters()
154154

155155
/**
156156
* @group adapter
157-
* @covers \PHPExif\AdapterAbstract::__construct
157+
* @covers \PHPExif\Adapter\AdapterAbstract::__construct
158158
*/
159159
public function testConstructorSetsOptions()
160160
{

tests/PHPExif/ReaderTest.php

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,7 @@ public function setUp()
1616

1717
/**
1818
* @group reader
19-
* @covers \PHPExif\Reader::setAdapter
20-
*/
21-
public function testSetAdapterInProperty()
22-
{
23-
$adapter = $this->getMock('\PHPExif\Adapter\AdapterInterface');
24-
$reflProperty = new \ReflectionProperty('\PHPExif\Reader\Reader', 'adapter');
25-
$reflProperty->setAccessible(true);
26-
$this->assertNull($reflProperty->getValue($this->reader));
27-
$this->reader->setAdapter($adapter);
28-
29-
$this->assertSame($adapter, $reflProperty->getValue($this->reader));
30-
}
31-
32-
/**
33-
* @group reader
34-
* @covers \PHPExif\Reader::__construct
19+
* @covers \PHPExif\Reader\Reader::__construct
3520
*/
3621
public function testConstructorWithAdapter()
3722
{
@@ -46,7 +31,7 @@ public function testConstructorWithAdapter()
4631

4732
/**
4833
* @group reader
49-
* @covers \PHPExif\Reader::getAdapter
34+
* @covers \PHPExif\Reader\Reader::getAdapter
5035
*/
5136
public function testGetAdapterFromProperty()
5237
{
@@ -61,7 +46,7 @@ public function testGetAdapterFromProperty()
6146

6247
/**
6348
* @group reader
64-
* @covers \PHPExif\Reader::getAdapter
49+
* @covers \PHPExif\Reader\Reader::getAdapter
6550
* @expectedException \PHPExif\Adapter\NoAdapterException
6651
*/
6752
public function testGetAdapterThrowsException()
@@ -71,24 +56,23 @@ public function testGetAdapterThrowsException()
7156

7257
/**
7358
* @group reader
74-
* @covers \PHPExif\Reader::getExifFromFile
59+
* @covers \PHPExif\Reader\Reader::read
7560
*/
7661
public function testGetExifPassedToAdapter()
7762
{
78-
$mock = $this->getMock('\PHPExif\Adapter\AdapterInterface');
79-
$mock->expects($this->once())
80-
->method('getExifFromFile');
63+
$adapter = $this->getMock('\PHPExif\Adapter\AdapterInterface');
64+
$adapter->expects($this->once())->method('getExifFromFile');
8165

8266
$reflProperty = new \ReflectionProperty('\PHPExif\Reader\Reader', 'adapter');
8367
$reflProperty->setAccessible(true);
84-
$reflProperty->setValue($this->reader, $mock);
68+
$reflProperty->setValue($this->reader, $adapter);
8569

8670
$this->reader->read('/tmp/foo.bar');
8771
}
8872

8973
/**
9074
* @group reader
91-
* @covers \PHPExif\Reader::factory
75+
* @covers \PHPExif\Reader\Reader::factory
9276
* @expectedException InvalidArgumentException
9377
*/
9478
public function testFactoryThrowsException()
@@ -98,7 +82,7 @@ public function testFactoryThrowsException()
9882

9983
/**
10084
* @group reader
101-
* @covers \PHPExif\Reader::factory
85+
* @covers \PHPExif\Reader\Reader::factory
10286
*/
10387
public function testFactoryReturnsCorrectType()
10488
{
@@ -109,7 +93,7 @@ public function testFactoryReturnsCorrectType()
10993

11094
/**
11195
* @group reader
112-
* @covers \PHPExif\Reader::factory
96+
* @covers \PHPExif\Reader\Reader::factory
11397
*/
11498
public function testFactoryAdapterTypeNative()
11599
{
@@ -124,7 +108,7 @@ public function testFactoryAdapterTypeNative()
124108

125109
/**
126110
* @group reader
127-
* @covers \PHPExif\Reader::factory
111+
* @covers \PHPExif\Reader\Reader::factory
128112
*/
129113
public function testFactoryAdapterTypeExiftool()
130114
{
@@ -137,15 +121,4 @@ public function testFactoryAdapterTypeExiftool()
137121
$this->assertInstanceOf('\PHPExif\Adapter\Exiftool', $adapter);
138122
}
139123

140-
/**
141-
* @group reader
142-
* @covers \PHPExif\Reader::factory
143-
*/
144-
public function testReaderIsImmutable()
145-
{
146-
$this->setExpectedException('\\PHPExif\\Reader\\ImmutableException');
147-
$reader = \PHPExif\Reader\Reader::factory(\PHPExif\Reader\Reader::TYPE_EXIFTOOL);
148-
$adapter = $this->getMock('\PHPExif\Adapter\AdapterInterface');
149-
$reader->setAdapter($adapter);
150-
}
151124
}

0 commit comments

Comments
 (0)