Completed
Push — master ( 9a853d...d124a5 )
by Alessandro
05:40
created

testConvertSameCurrency()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 12
loc 12
rs 9.4285
cc 1
eloc 9
nc 1
nop 0
1
<?php
2
namespace App\Test\TestCase\Controller\Component;
3
4
use CurrencyConverter\Controller\Component\CurrencyConverterComponent;
5
use Cake\Controller\Controller;
6
use Cake\Controller\ComponentRegistry;
7
use Cake\Network\Request;
8
use Cake\Network\Response;
9
use Cake\TestSuite\TestCase;
10
use Cake\ORM\TableRegistry;
11
12
class CurrencyConverterComponentTest extends TestCase {
13
    public $fixtures = ['app.currencyconverter'];
14
    public $CurrencyConverter = null;
15
    public $controller = null;
16
17
    public function setUp()
18
    {
19
        parent::setUp();
20
21
        $this->currencyConverter = new CurrencyConverterComponent(new ComponentRegistry(new Controller));
0 ignored issues
show
Bug introduced by
The property currencyConverter does not seem to exist. Did you mean CurrencyConverter?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
22
    }
23
24 View Code Duplication
    public function testAmountWithComma()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
25
    {
26
        $fromCurrency   = 'EUR';
27
        $toCurrency     = 'GBP';
28
        $amount         = '20,00';
29
        $saveIntoDb     = 0;
30
        $hourDifference = 0;
31
        $dataSource     = 'test';
32
33
        $result = $this->currencyConverter->convert($fromCurrency, $toCurrency, $amount, $saveIntoDb, $hourDifference, $dataSource);
0 ignored issues
show
Bug introduced by
The property currencyConverter does not seem to exist. Did you mean CurrencyConverter?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
34
        $this->assertGreaterThan((float)$result, (float)$amount);
35
    }
36
37 View Code Duplication
    public function testAmountWithPoint()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
38
    {
39
        $fromCurrency   = 'EUR';
40
        $toCurrency     = 'GBP';
41
        $amount         = '20.00';
42
        $saveIntoDb     = 0;
43
        $hourDifference = 0;
44
        $dataSource     = 'test';
45
46
        $result = $this->currencyConverter->convert($fromCurrency, $toCurrency, $amount, $saveIntoDb, $hourDifference, $dataSource);
0 ignored issues
show
Bug introduced by
The property currencyConverter does not seem to exist. Did you mean CurrencyConverter?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
47
        $this->assertGreaterThan($result, $amount);
48
    }
49
50 View Code Duplication
    public function testAmountWithCommaSavedInDatabase()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
    {
52
        $fromCurrency   = 'EUR';
53
        $toCurrency     = 'GBP';
54
        $amount         = '20,00';
55
        $saveIntoDb     = true;
56
        $hourDifference = 1;
57
        $dataSource     = 'test';
58
59
        $result = $this->currencyConverter->convert($fromCurrency, $toCurrency, $amount, $saveIntoDb, $hourDifference, $dataSource);
0 ignored issues
show
Bug introduced by
The property currencyConverter does not seem to exist. Did you mean CurrencyConverter?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
60
        $this->assertGreaterThan($result, $amount);
61
    }
62
63 View Code Duplication
    public function testAmountWithPointSavedInDatabase()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
64
    {
65
        $fromCurrency   = 'EUR';
66
        $toCurrency     = 'GBP';
67
        $amount         = '20.00';
68
        $saveIntoDb     = 1;
69
        $hourDifference = 1;
70
        $dataSource     = 'test';
71
72
        $result = $this->currencyConverter->convert($fromCurrency, $toCurrency, $amount, $saveIntoDb, $hourDifference, $dataSource);
0 ignored issues
show
Bug introduced by
The property currencyConverter does not seem to exist. Did you mean CurrencyConverter?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
73
        $this->assertGreaterThan($result, $amount);
74
    }
75
76 View Code Duplication
    public function testConvertToPDS()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
77
    {
78
        $fromCurrency   = 'EUR';
79
        $toCurrency     = 'PDS';
80
        $amount         = '20.00';
81
        $saveIntoDb     = 1;
82
        $hourDifference = 1;
83
        $dataSource     = 'test';
84
85
        $result = $this->currencyConverter->convert($fromCurrency, $toCurrency, $amount, $saveIntoDb, $hourDifference, $dataSource);
0 ignored issues
show
Bug introduced by
The property currencyConverter does not seem to exist. Did you mean CurrencyConverter?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
86
        $this->assertGreaterThan($result, $amount);
87
    }
88
89 View Code Duplication
    public function testConvertFromPDS()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
90
    {
91
        $fromCurrency   = 'PDS';
92
        $toCurrency     = 'EUR';
93
        $amount         = '20.00';
94
        $saveIntoDb     = 1;
95
        $hourDifference = 1;
96
        $dataSource     = 'test';
97
98
        $result = $this->currencyConverter->convert($fromCurrency, $toCurrency, $amount, $saveIntoDb, $hourDifference, $dataSource);
0 ignored issues
show
Bug introduced by
The property currencyConverter does not seem to exist. Did you mean CurrencyConverter?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
99
        $this->assertGreaterThan($amount, $result);
100
    }
101
102 View Code Duplication
    public function testConvertSameCurrency()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
103
    {
104
        $fromCurrency   = 'EUR';
105
        $toCurrency     = 'EUR';
106
        $amount         = '20.00';
107
        $saveIntoDb     = 1;
108
        $hourDifference = 1;
109
        $dataSource     = 'test';
110
111
        $result = $this->currencyConverter->convert($fromCurrency, $toCurrency, $amount, $saveIntoDb, $hourDifference, $dataSource);
0 ignored issues
show
Bug introduced by
The property currencyConverter does not seem to exist. Did you mean CurrencyConverter?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
112
        $this->assertEquals($result, $amount);
113
    }
114
115
    public function testInsertCurrency()
116
    {
117
        $currencyTable = TableRegistry::get('CurrencyConverter', [
118
            'className' => 'CurrencyConverter\Model\Table\CurrencyConvertersTable',
119
            'table' => 'currency_converter'
120
        ]);
121
122
        $query = $currencyTable->find('all');
123
124
        $query->hydrate(false);
0 ignored issues
show
Deprecated Code introduced by
The method Cake\ORM\Query::hydrate() has been deprecated with message: 3.4.0 Use enableHydration()/isHydrationEnabled() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
125
        $result =  $query->toArray();
126
127
        foreach ($result as $row){
128
            $currencyTable->deleteAll(['id' => $row['id']]);
129
        }
130
131
        $fromCurrency   = 'EUR';
132
        $toCurrency     = 'GBP';
133
        $amount         = '20.00';
134
        $saveIntoDb     = 1;
135
        $hourDifference = -1;
136
        $dataSource     = 'test';
137
138
        $resultConverted = $this->currencyConverter->convert($fromCurrency, $toCurrency, $amount, $saveIntoDb, $hourDifference, $dataSource);
0 ignored issues
show
Bug introduced by
The property currencyConverter does not seem to exist. Did you mean CurrencyConverter?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
139
140
        $currencyTable = TableRegistry::get('CurrencyConverter');
141
        $query = $currencyTable->find('all');
142
143
        $query->hydrate(false);
0 ignored issues
show
Deprecated Code introduced by
The method Cake\ORM\Query::hydrate() has been deprecated with message: 3.4.0 Use enableHydration()/isHydrationEnabled() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
144
        $result =  $query->toArray();
145
146
        $this->assertEquals(1, count($result));
147
        $this->assertGreaterThan($resultConverted, $amount);
148
    }
149
150
    public function tearDown()
151
    {
152
        parent::tearDown();
153
        unset($this->currencyConverter, $this->controller);
154
    }
155
}