Completed
Push — master ( b66556...89216d )
by Dmitry
21:57
created

PriceCest::ensureICanAddPricesNonTemplate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

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