1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PHP\Math\BigIntegerTest; |
4
|
|
|
|
5
|
|
|
use PHP\Math\BigInteger\BigInteger; |
6
|
|
|
use PHPUnit_Framework_TestCase; |
7
|
|
|
|
8
|
|
|
class BigIntegerConstructorTest extends PHPUnit_Framework_TestCase |
9
|
|
|
{ |
10
|
|
|
public function testEmpty() |
11
|
|
|
{ |
12
|
|
|
// Arrange |
13
|
|
|
// ... |
14
|
|
|
|
15
|
|
|
// Act |
16
|
|
|
$bigInteger = new BigInteger(); |
17
|
|
|
|
18
|
|
|
// Assert |
19
|
|
|
$this->assertInternalType('string', $bigInteger->getValue()); |
20
|
|
|
$this->assertEquals('0', $bigInteger->getValue()); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function testWithInteger() |
24
|
|
|
{ |
25
|
|
|
// Arrange |
26
|
|
|
// ... |
27
|
|
|
|
28
|
|
|
// Act |
29
|
|
|
$bigInteger = new BigInteger(123); |
30
|
|
|
|
31
|
|
|
// Assert |
32
|
|
|
$this->assertInternalType('string', $bigInteger->getValue()); |
33
|
|
|
$this->assertEquals('123', $bigInteger->getValue()); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testWithString() |
37
|
|
|
{ |
38
|
|
|
// Arrange |
39
|
|
|
// ... |
40
|
|
|
|
41
|
|
|
// Act |
42
|
|
|
$bigInteger = new BigInteger('123'); |
43
|
|
|
|
44
|
|
|
// Assert |
45
|
|
|
$this->assertInternalType('string', $bigInteger->getValue()); |
46
|
|
|
$this->assertEquals('123', $bigInteger->getValue()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testWithBigInteger() |
50
|
|
|
{ |
51
|
|
|
// Arrange |
52
|
|
|
// ... |
53
|
|
|
|
54
|
|
|
// Act |
55
|
|
|
$bigIntegerValue = new BigInteger('123'); |
56
|
|
|
$bigInteger = new BigInteger($bigIntegerValue); |
|
|
|
|
57
|
|
|
|
58
|
|
|
// Assert |
59
|
|
|
$this->assertInternalType('string', $bigInteger->getValue()); |
60
|
|
|
$this->assertEquals('123', $bigInteger->getValue()); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @expectedException InvalidArgumentException |
65
|
|
|
*/ |
66
|
|
|
public function testWithInvalidValue() |
67
|
|
|
{ |
68
|
|
|
// Arrange |
69
|
|
|
// ... |
70
|
|
|
|
71
|
|
|
// Act |
72
|
|
|
new BigInteger('123.123'); |
73
|
|
|
|
74
|
|
|
// Assert |
75
|
|
|
// ... |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: