PriceCest::ensureICanCreateSuggestedPrices()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
/**
3
 * Finance module for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-finance
6
 * @package   hipanel-module-finance
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\finance\tests\acceptance\manager;
12
13
use Codeception\Scenario;
14
use hipanel\helpers\Url;
15
use hipanel\modules\finance\tests\_support\Page\plan\Create as PlanCreatePage;
16
use hipanel\modules\finance\tests\_support\Page\price\Create as PriceCreatePage;
17
use hipanel\modules\finance\tests\_support\Page\price\Delete as PriceDeletePage;
18
use hipanel\modules\finance\tests\_support\Page\price\Update as PriceUpdatePage;
19
use hipanel\tests\_support\Step\Acceptance\Manager;
20
21
abstract class PriceCest
22
{
23
    /**
24
     * @var int
25
     */
26
    protected $id;
27
28
    /**
29
     * @param Manager $I
30
     * @return array of settings for future plan
31
     * ```php
32
     *  [
33
     *      'type' => 'Server', // Type of the future plan
34
     *      'templateName' => 'Main template',
35
     *      'priceTypes' => ['Main prices', 'Parts prices'],
36
     *      'object' => 'DS5000',
37
     *  ],
38
     * ```
39
     */
40
    abstract protected function suggestedPricesOptionsProvider(Manager $I): array;
41
42
    /**
43
     * @param Manager $I
44
     */
45
    public function ensureICanCreateSuggestedPrices(Manager $I): void
46
    {
47
        foreach ($this->suggestedPricesOptionsProvider($I) as $example) {
48
            $I->amGoingTo(sprintf(
49
                'Create new plan with type "%s" and fill it with prices of template "%s" (suggestions %s) for object %s',
50
                $example['type'], $example['templateName'], implode(', ', $example['priceTypes']), $example['object']
51
            ));
52
53
            $id = $this->createPlan($I, uniqid($example['type'] . 'Plan_Of_' . $example['templateName'], true), $example['type']);
54
            $I->needPage(Url::to(['@plan/view', 'id' => $id]));
55
            $I->see('No results found.');
56
57
            $page = new PriceCreatePage($I, $id);
58
            foreach ($example['priceTypes'] as $priceType) {
59
                $page->createRandomPrices($example['object'], $example['templateName'], $priceType);
60
            }
61
        }
62
    }
63
64
    /**
65
     * @param Manager $I
66
     * @param string $name
67
     * @param string $type
68
     * @return int created plan ID
69
     */
70
    protected function createPlan(Manager $I, string $name, string $type): int
71
    {
72
        $fields = [
73
            'name' => $name,
74
            'type' => $type,
75
            'client' => 'hipanel_test_reseller',
76
            'currency' => 'USD',
77
            'note' => 'test note',
78
        ];
79
80
        $page = new PlanCreatePage($I, $fields);
81
82
        return $page->createPlan();
83
    }
84
85 View Code Duplication
    public function ensureICanUpdatePrices(Manager $I, Scenario $scenario): void
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...
86
    {
87
        if ($this->id === null) {
88
            $scenario->incomplete('ID of the target plan must be set');
89
        }
90
91
        $page = new PriceUpdatePage($I, $this->id);
92
        $page->updatePrices();
93
    }
94
95 View Code Duplication
    public function ensureICanDeletePrices(Manager $I, Scenario $scenario): void
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...
96
    {
97
        if ($this->id === null) {
98
            $scenario->incomplete('ID of the target plan must be set');
99
        }
100
101
        $page = new PriceDeletePage($I, $this->id);
102
        $page->deleteTemplatePrices();
103
    }
104
}
105