|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tzsk\Payu\Tests\Helpers; |
|
4
|
|
|
|
|
5
|
|
|
use Tzsk\Payu\Tests\TestCase; |
|
6
|
|
|
use Tzsk\Payu\Helpers\FormBuilder; |
|
7
|
|
|
use Illuminate\Support\Facades\Session; |
|
8
|
|
|
|
|
9
|
|
|
class FormBuilderTest extends TestCase |
|
10
|
|
|
{ |
|
11
|
|
|
public function testItWillBuildWithCorrectCredentials() |
|
12
|
|
|
{ |
|
13
|
|
|
$credentials = $this->getCredentials(); |
|
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
$builder = (new FormBuilder(request()))->build(); |
|
16
|
|
|
$this->assertTrue(is_object($builder)); |
|
17
|
|
|
$this->assertTrue(is_array($builder->fields)); |
|
18
|
|
|
$this->assertNotEmpty($builder->url); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function testWillFailWithWrongCredentials() |
|
22
|
|
|
{ |
|
23
|
|
|
$credentials = $this->getCredentials(false); |
|
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
try { |
|
26
|
|
|
$builder = (new FormBuilder(request()))->build(); |
|
|
|
|
|
|
27
|
|
|
} catch (\Exception $e) { |
|
28
|
|
|
$this->assertNotEmpty($e->getMessage()); |
|
29
|
|
|
} |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
View Code Duplication |
protected function getCredentials($transaction = true) |
|
|
|
|
|
|
33
|
|
|
{ |
|
34
|
|
|
$data = [ |
|
35
|
|
|
'data' => $transaction ? $this->getTransaction() : [], |
|
36
|
|
|
'status_url' => 'foo', |
|
37
|
|
|
'account' => 'payubiz', |
|
38
|
|
|
'model' => ['id' => 1, 'class' => 'baz'], |
|
39
|
|
|
]; |
|
40
|
|
|
|
|
41
|
|
|
Session::put('tzsk_payu_data', $data); |
|
42
|
|
|
|
|
43
|
|
|
return $data; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
View Code Duplication |
protected function getTransaction() |
|
|
|
|
|
|
47
|
|
|
{ |
|
48
|
|
|
return [ |
|
49
|
|
|
'txnid' => strtoupper(str_random(8)), |
|
50
|
|
|
'amount' => rand(100, 999), |
|
51
|
|
|
'productinfo' => 'Product Information', |
|
52
|
|
|
'firstname' => 'John', |
|
53
|
|
|
'email' => '[email protected]', |
|
54
|
|
|
'phone' => '9876543210', |
|
55
|
|
|
]; |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.