Skip to content

Commit 0ff284d

Browse files
authored
Merge pull request tattali#9 from robertfausk/fix_device_version_call_with_type_float
Fix device_version call with $type float
2 parents 60d0acb + 178ff2f commit 0ff284d

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/Twig/Extension/MobileDetectExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ public function getRules(): array
9898
* is optional and defaults to self::VERSION_TYPE_STRING. Passing an
9999
* invalid parameter will default to the this type as well.
100100
*
101-
* @return string|float the version of the property we are trying to extract
101+
* @return string|float|null the version of the property we are trying to extract
102102
*/
103-
public function deviceVersion(string $propertyName, string $type = MobileDetector::VERSION_TYPE_STRING): ?string
103+
public function deviceVersion(string $propertyName, string $type = MobileDetector::VERSION_TYPE_STRING)
104104
{
105105
return $this->mobileDetector->version($propertyName, $type) ?: null;
106106
}

tests/Twig/Extension/MobileDetectExtensionTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,20 @@ public function testRulesList(): void
109109

110110
public function testDeviceVersion(): void
111111
{
112-
$this->mobileDetector->expects(static::exactly(2))
112+
$this->mobileDetector->expects(static::exactly(3))
113113
->method('version')
114114
->withConsecutive(
115115
[static::equalTo('Version'), static::equalTo(MobileDetector::VERSION_TYPE_STRING)],
116-
[static::equalTo('Firefox'), static::equalTo(MobileDetector::VERSION_TYPE_STRING)]
116+
[static::equalTo('Firefox'), static::equalTo(MobileDetector::VERSION_TYPE_STRING)],
117+
[static::equalTo('Firefox'), static::equalTo(MobileDetector::VERSION_TYPE_FLOAT)]
117118
)
118-
->willReturn(false, '98.0')
119+
->willReturn(false, '98.0', 98.0)
119120
;
120121
$deviceView = new DeviceView($this->requestStack);
121122
$extension = new MobileDetectExtension($this->requestStack, $this->mobileDetector, $deviceView, $this->config);
122123
static::assertNull($extension->deviceVersion('Version', MobileDetector::VERSION_TYPE_STRING));
123124
static::assertSame('98.0', $extension->deviceVersion('Firefox', MobileDetector::VERSION_TYPE_STRING));
125+
static::assertSame(98.0, $extension->deviceVersion('Firefox', MobileDetector::VERSION_TYPE_FLOAT));
124126
}
125127

126128
public function testFullViewUrlHostNull(): void

0 commit comments

Comments
 (0)