Open Monograph Press  3.3.0
HelperTest.php
1 <?php
2 
3 namespace Omnipay\Common;
4 
5 use Mockery as m;
6 use Omnipay\Tests\TestCase;
7 
8 class HelperTest extends TestCase
9 {
10  public function testCamelCase()
11  {
12  $result = Helper::camelCase('test_case');
13  $this->assertEquals('testCase', $result);
14  }
15 
16  public function testCamelCaseAlreadyCorrect()
17  {
18  $result = Helper::camelCase('testCase');
19  $this->assertEquals('testCase', $result);
20  }
21 
23  {
24  $result = Helper::camelCase('TEST_CASE');
25  $this->assertEquals('testCase', $result);
26  }
27 
28  public function testValidateLuhnValid()
29  {
30  $result = Helper::validateLuhn('4111111111111111');
31  $this->assertTrue($result);
32  }
33 
34  public function testValidateLuhnInvalid()
35  {
36  $result = Helper::validateLuhn('4111111111111110');
37  $this->assertFalse($result);
38  }
39 
40  public function testValidateLuhnNull()
41  {
42  $result = Helper::validateLuhn(null);
43  $this->assertTrue($result);
44  }
45 
46  public function testInitializeIgnoresNull()
47  {
48  $target = m::mock();
49  Helper::initialize($target, null);
50  }
51 
52  public function testInitializeIgnoresString()
53  {
54  $target = m::mock();
55  Helper::initialize($target, 'invalid');
56  }
57 
58  public function testInitializeCallsSetters()
59  {
60  $target = m::mock('\Omnipay\Common\CreditCard');
61  $target->shouldReceive('setName')->once()->with('adrian');
62  $target->shouldReceive('setNumber')->once()->with('1234');
63 
64  Helper::initialize($target, array('name' => 'adrian', 'number' => '1234'));
65  }
66 
68  {
69  $target = m::mock('\Omnipay\Common\CreditCard');
70  $target->shouldReceive('setName')->once()->with('adrian');
71 
72  Helper::initialize($target, array('name' => 'adrian', 'extra' => 'invalid'));
73  }
74 
76  {
77  $shortName = Helper::getGatewayShortName('Omnipay\\Stripe\\Gateway');
78  $this->assertSame('Stripe', $shortName);
79  }
80 
82  {
83  $shortName = Helper::getGatewayShortName('\\Omnipay\\Stripe\\Gateway');
84  $this->assertSame('Stripe', $shortName);
85  }
86 
88  {
89  $shortName = Helper::getGatewayShortName('Omnipay\\PayPal\\ExpressGateway');
90  $this->assertSame('PayPal_Express', $shortName);
91  }
92 
94  {
95  $shortName = Helper::getGatewayShortName('\\Omnipay\\PayPal\\ExpressGateway');
96  $this->assertSame('PayPal_Express', $shortName);
97  }
98 
100  {
101  $shortName = Helper::getGatewayShortName('\\Custom\\Gateway');
102  $this->assertSame('\\Custom\\Gateway', $shortName);
103  }
104 
109  {
110  $class = Helper::getGatewayClassName('\\Custom\\Gateway');
111  $this->assertEquals('\\Custom\\Gateway', $class);
112  }
113 
118  {
119  $class = Helper::getGatewayClassName('\\Custom_Gateway');
120  $this->assertEquals('\\Custom_Gateway', $class);
121  }
122 
124  {
125  $class = Helper::getGatewayClassName('Stripe');
126  $this->assertEquals('\\Omnipay\\Stripe\\Gateway', $class);
127  }
128 
130  {
131  $class = Helper::getGatewayClassName('PayPal\\Express');
132  $this->assertEquals('\\Omnipay\\PayPal\\ExpressGateway', $class);
133  }
134 
139  {
140  $class = Helper::getGatewayClassName('PayPal_Express');
141  $this->assertEquals('\\Omnipay\\PayPal\\ExpressGateway', $class);
142  }
143 
147  public function testToFloatFromFloat()
148  {
149  $shortName = Helper::toFloat(1.99);
150  $this->assertSame(1.99, $shortName);
151  }
152 
153  public function testToFloatFromInt()
154  {
155  $shortName = Helper::toFloat(199);
156  $this->assertSame(199.0, $shortName);
157  }
158 
160  {
161  $shortName = Helper::toFloat("1.99");
162  $this->assertSame(1.99, $shortName);
163  }
164 
166  {
167  $shortName = Helper::toFloat("000009.99900000000");
168  $this->assertSame(9.999, $shortName);
169  }
170 
172  {
173  $shortName = Helper::toFloat("1.");
174  $this->assertSame(1.0, $shortName);
175  }
176 
177  public function testToFloatFromStringInt()
178  {
179  $shortName = Helper::toFloat("199");
180  $this->assertSame(199.0, $shortName);
181  }
182 
184  {
185  $shortName = Helper::toFloat("-199");
186  $this->assertSame(-199.0, $shortName);
187  }
188 
202  {
203  $shortName = Helper::toFloat(".99");
204  }
205 
211  {
212  $shortName = Helper::toFloat("1.99.");
213  }
214 
220  {
221  $shortName = Helper::toFloat("1,99");
222  }
223 
228  public function testToFloatFromBoolean()
229  {
230  $shortName = Helper::toFloat(false);
231  }
232 }
Omnipay\Common\HelperTest\testInitializeIgnoresNull
testInitializeIgnoresNull()
Definition: HelperTest.php:46
Omnipay\Common\HelperTest\testToFloatFromBoolean
testToFloatFromBoolean()
Definition: HelperTest.php:228
Omnipay\Common\HelperTest\testToFloatFromStringRedunantZeroes
testToFloatFromStringRedunantZeroes()
Definition: HelperTest.php:165
Omnipay\Common\Helper\validateLuhn
static validateLuhn($number)
Definition: lib/vendor/omnipay/common/src/Omnipay/Common/Helper.php:62
Omnipay\Common\HelperTest
Definition: HelperTest.php:8
Omnipay\Common\HelperTest\testInitializeIgnoresString
testInitializeIgnoresString()
Definition: HelperTest.php:52
Omnipay\Common\HelperTest\testGetGatewayClassNameSimple
testGetGatewayClassNameSimple()
Definition: HelperTest.php:123
Omnipay\Common\HelperTest\testToFloatFromStringWrongDecimalPoints
testToFloatFromStringWrongDecimalPoints()
Definition: HelperTest.php:219
Omnipay\Common\HelperTest\testToFloatFromInt
testToFloatFromInt()
Definition: HelperTest.php:153
Omnipay\Common\HelperTest\testValidateLuhnNull
testValidateLuhnNull()
Definition: HelperTest.php:40
Omnipay\Common\HelperTest\testToFloatFromFloat
testToFloatFromFloat()
Definition: HelperTest.php:147
Omnipay\Common\HelperTest\testGetGatewayClassNameUnderscoreNamespace
testGetGatewayClassNameUnderscoreNamespace()
Definition: HelperTest.php:138
Omnipay\Common\HelperTest\testToFloatFromStringTwoDecimalPoints
testToFloatFromStringTwoDecimalPoints()
Definition: HelperTest.php:210
Omnipay\Common\Helper\initialize
static initialize($target, $parameters)
Definition: lib/vendor/omnipay/common/src/Omnipay/Common/Helper.php:81
Omnipay\Common\Helper\toFloat
static toFloat($value)
Definition: lib/vendor/omnipay/common/src/Omnipay/Common/Helper.php:152
Omnipay\Common\HelperTest\testToFloatFromStringDecimal
testToFloatFromStringDecimal()
Definition: HelperTest.php:159
Omnipay\Common\HelperTest\testCamelCase
testCamelCase()
Definition: HelperTest.php:10
Omnipay\Common\HelperTest\testGetGatewayShortNameCustomGateway
testGetGatewayShortNameCustomGateway()
Definition: HelperTest.php:99
Omnipay\Common\HelperTest\testValidateLuhnInvalid
testValidateLuhnInvalid()
Definition: HelperTest.php:34
Omnipay\Common\HelperTest\testToFloatFromStringIntNegative
testToFloatFromStringIntNegative()
Definition: HelperTest.php:183
Omnipay\Common\HelperTest\testGetGatewayClassNamePartialNamespace
testGetGatewayClassNamePartialNamespace()
Definition: HelperTest.php:129
Omnipay\Common\HelperTest\testGetGatewayShortNameUnderscoreLeadingSlash
testGetGatewayShortNameUnderscoreLeadingSlash()
Definition: HelperTest.php:93
Omnipay\Common\HelperTest\testToFloatFromStringEmptyIntegerPart
testToFloatFromStringEmptyIntegerPart()
Definition: HelperTest.php:201
Omnipay\Common\HelperTest\testGetGatewayShortNameSimple
testGetGatewayShortNameSimple()
Definition: HelperTest.php:75
Omnipay\Common\HelperTest\testGetGatewayClassNameExistingNamespace
testGetGatewayClassNameExistingNamespace()
Definition: HelperTest.php:108
Omnipay\Common\HelperTest\testToFloatFromStringInt
testToFloatFromStringInt()
Definition: HelperTest.php:177
Omnipay\Common\HelperTest\testGetGatewayShortNameSimpleLeadingSlash
testGetGatewayShortNameSimpleLeadingSlash()
Definition: HelperTest.php:81
Omnipay\Common\Helper\getGatewayShortName
static getGatewayShortName($className)
Definition: lib/vendor/omnipay/common/src/Omnipay/Common/Helper.php:99
Omnipay\Common\HelperTest\testGetGatewayShortNameUnderscore
testGetGatewayShortNameUnderscore()
Definition: HelperTest.php:87
Omnipay\Common
Definition: lib/vendor/omnipay/common/src/Omnipay/Common/AbstractGateway.php:6
Omnipay\Common\HelperTest\testGetGatewayClassNameExistingNamespaceUnderscore
testGetGatewayClassNameExistingNamespaceUnderscore()
Definition: HelperTest.php:117
Omnipay\Common\HelperTest\testCamelCaseAlreadyCorrect
testCamelCaseAlreadyCorrect()
Definition: HelperTest.php:16
Omnipay\Common\HelperTest\testValidateLuhnValid
testValidateLuhnValid()
Definition: HelperTest.php:28
Omnipay\Common\HelperTest\testInitializeIgnoresInvalidParameters
testInitializeIgnoresInvalidParameters()
Definition: HelperTest.php:67
Omnipay\Common\HelperTest\testCamelCaseWithUppercaseValue
testCamelCaseWithUppercaseValue()
Definition: HelperTest.php:22
Omnipay\Common\HelperTest\testToFloatFromStringEmptyDecimal
testToFloatFromStringEmptyDecimal()
Definition: HelperTest.php:171
Omnipay\Common\Helper\camelCase
static camelCase($str)
Definition: lib/vendor/omnipay/common/src/Omnipay/Common/Helper.php:24
Omnipay\Common\Helper\getGatewayClassName
static getGatewayClassName($shortName)
Definition: lib/vendor/omnipay/common/src/Omnipay/Common/Helper.php:127
Omnipay\Common\HelperTest\testInitializeCallsSetters
testInitializeCallsSetters()
Definition: HelperTest.php:58