Completed
Branch master (0d9475)
by WEBEWEB
02:41 queued 01:18
created

IntegerUtilityTest::testParseString()   B

Complexity

Conditions 5
Paths 16

Size

Total Lines 33
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 8.439
c 0
b 0
f 0
cc 5
eloc 23
nc 16
nop 0
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\IntegerArgumentException;
17
use WBW\Library\Core\Utility\IntegerUtility;
18
19
/**
20
 * Integer utility test.
21
 *
22
 * @author NdC/WBW <https://github.com/webeweb/>
23
 * @package WBW\Library\Core\Tests\Utility
24
 * @final
25
 */
26
final class IntegerUtilityTest extends PHPUnit_Framework_TestCase {
27
28
	/**
29
	 * Tests the parseString() method.
30
	 *
31
	 * @return void
32
	 */
33
	public function testParseString() {
34
35
		try {
36
			IntegerUtility::parseString("exception");
37
		} catch (Exception $ex) {
38
			$this->assertInstanceOf(IntegerArgumentException::class, $ex);
39
			$this->assertEquals("The argument \"exception\" is not an integer", $ex->getMessage());
40
		}
41
42
		try {
43
			IntegerUtility::parseString("1A");
44
		} catch (Exception $ex) {
45
			$this->assertInstanceOf(IntegerArgumentException::class, $ex);
46
			$this->assertEquals("The argument \"1A\" is not an integer", $ex->getMessage());
47
		}
48
49
		try {
50
			IntegerUtility::parseString("1.");
51
		} catch (Exception $ex) {
52
			$this->assertInstanceOf(IntegerArgumentException::class, $ex);
53
			$this->assertEquals("The argument \"1.\" is not an integer", $ex->getMessage());
54
		}
55
56
		try {
57
			IntegerUtility::parseString("1.0");
58
		} catch (Exception $ex) {
59
			$this->assertInstanceOf(IntegerArgumentException::class, $ex);
60
			$this->assertEquals("The argument \"1.0\" is not an integer", $ex->getMessage());
61
		}
62
63
		$this->assertEquals(null, IntegerUtility::parseString(null));
64
		$this->assertEquals(1, IntegerUtility::parseString("1"));
65
	}
66
67
}
68