Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix device_version call with $type float #9

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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