|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the core-library package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) 2017 NdC/WBW |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace WBW\Library\Core\Tests\Utility; |
|
13
|
|
|
|
|
14
|
|
|
use Exception; |
|
15
|
|
|
use PHPUnit_Framework_TestCase; |
|
16
|
|
|
use WBW\Library\Core\Exception\Argument\DoubleArgumentException; |
|
17
|
|
|
use WBW\Library\Core\Utility\DoubleUtility; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Double utility test. |
|
21
|
|
|
* |
|
22
|
|
|
* @author NdC/WBW <https://github.com/webeweb/> |
|
23
|
|
|
* @package WBW\Library\Core\Tests\Utility |
|
24
|
|
|
* @final |
|
25
|
|
|
*/ |
|
26
|
|
|
final class DoubleUtilityTest extends PHPUnit_Framework_TestCase { |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Tests the parseString() method. |
|
30
|
|
|
* |
|
31
|
|
|
* @return void |
|
32
|
|
|
*/ |
|
33
|
|
|
public function testParseString() { |
|
34
|
|
|
|
|
35
|
|
|
try { |
|
36
|
|
|
DoubleUtility::parseString("exception"); |
|
37
|
|
|
} catch (Exception $ex) { |
|
38
|
|
|
$this->assertInstanceOf(DoubleArgumentException::class, $ex); |
|
39
|
|
|
$this->assertEquals("The argument \"exception\" is not a double", $ex->getMessage()); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
try { |
|
43
|
|
|
DoubleUtility::parseString("1A"); |
|
44
|
|
|
} catch (Exception $ex) { |
|
45
|
|
|
$this->assertInstanceOf(DoubleArgumentException::class, $ex); |
|
46
|
|
|
$this->assertEquals("The argument \"1A\" is not a double", $ex->getMessage()); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$this->assertEquals(null, DoubleUtility::parseString(null)); |
|
50
|
|
|
$this->assertEquals(1.0, DoubleUtility::parseString("1")); |
|
51
|
|
|
$this->assertEquals(1.0, DoubleUtility::parseString("1.")); |
|
52
|
|
|
$this->assertEquals(1.0, DoubleUtility::parseString("1.0")); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
|