Skip to content

Commit

Permalink
Fix device_version call with $type float
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Freigang committed May 21, 2022
1 parent 60d0acb commit 178ff2f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Twig/Extension/MobileDetectExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ public function getRules(): array
* is optional and defaults to self::VERSION_TYPE_STRING. Passing an
* invalid parameter will default to the this type as well.
*
* @return string|float the version of the property we are trying to extract
* @return string|float|null the version of the property we are trying to extract
*/
public function deviceVersion(string $propertyName, string $type = MobileDetector::VERSION_TYPE_STRING): ?string
public function deviceVersion(string $propertyName, string $type = MobileDetector::VERSION_TYPE_STRING)
{
return $this->mobileDetector->version($propertyName, $type) ?: null;
}
Expand Down
8 changes: 5 additions & 3 deletions tests/Twig/Extension/MobileDetectExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,20 @@ public function testRulesList(): void

public function testDeviceVersion(): void
{
$this->mobileDetector->expects(static::exactly(2))
$this->mobileDetector->expects(static::exactly(3))
->method('version')
->withConsecutive(
[static::equalTo('Version'), static::equalTo(MobileDetector::VERSION_TYPE_STRING)],
[static::equalTo('Firefox'), static::equalTo(MobileDetector::VERSION_TYPE_STRING)]
[static::equalTo('Firefox'), static::equalTo(MobileDetector::VERSION_TYPE_STRING)],
[static::equalTo('Firefox'), static::equalTo(MobileDetector::VERSION_TYPE_FLOAT)]
)
->willReturn(false, '98.0')
->willReturn(false, '98.0', 98.0)
;
$deviceView = new DeviceView($this->requestStack);
$extension = new MobileDetectExtension($this->requestStack, $this->mobileDetector, $deviceView, $this->config);
static::assertNull($extension->deviceVersion('Version', MobileDetector::VERSION_TYPE_STRING));
static::assertSame('98.0', $extension->deviceVersion('Firefox', MobileDetector::VERSION_TYPE_STRING));
static::assertSame(98.0, $extension->deviceVersion('Firefox', MobileDetector::VERSION_TYPE_FLOAT));
}

public function testFullViewUrlHostNull(): void
Expand Down

0 comments on commit 178ff2f

Please sign in to comment.