Skip to content

Commit

Permalink
Fixed type mismatch (#62)
Browse files Browse the repository at this point in the history
* Fixed type mismatch

* Added test for isInt
  • Loading branch information
Wruczek authored and ronindesign committed Mar 22, 2018
1 parent 02ed3a1 commit 569bbc9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions Tests/Helper/StringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,27 @@ public function testSubstr()
$this->assertEquals("ello", $string->substr(1, 4));
$this->assertEquals("world", $string->substr(-6, 5));
}

public function testIsInt()
{
$tests = [
"1" => true,
"+1" => false,
"-1" => false,
"hello" => false,
"1.0" => false,
".1" => false,

// From https://goo.gl/C5v9wT
"0x539" => false,
"0b10100111001" => false,
"1337e0" => false,
"9.1" => false,
];

foreach ($tests as $test => $expected) {
$string = new \TeamSpeak3_Helper_String($test);
$this->assertSame($string->isInt(), $expected);
}
}
}
2 changes: 1 addition & 1 deletion libraries/TeamSpeak3/Helper/String.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ public function filterDigits()
*/
public function isInt()
{
return (is_numeric($this->string) && !$this->contains(".") && !$this->contains("x")) ? TRUE : FALSE;
return ctype_digit($this->string);
}

/**
Expand Down

0 comments on commit 569bbc9

Please sign in to comment.