Completed
Push — master ( 4e6ecf...24a4d5 )
by Cesar
12s
created

Missing   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 156
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 69
dl 0
loc 156
rs 10
c 0
b 0
f 0
wmc 12

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getDNI() 0 10 1
F run() 0 116 12
1
<?php
2
3
namespace Pagantis\SeleniumFormUtils\Step\ConfirmData;
4
5
use Facebook\WebDriver\WebDriverBy;
6
use Facebook\WebDriver\WebDriverSelect;
7
use Faker\Factory;
8
use Pagantis\SeleniumFormUtils\SeleniumHelper;
9
use Pagantis\SeleniumFormUtils\Step\AbstractStep;
10
11
/**
12
 * Class Missing
13
 * @package Pagantis\SeleniumFormUtils\Step\Result\Status
14
 */
15
class Missing extends AbstractStep
16
{
17
    /**
18
     * Handler step
19
     */
20
    const STEP = '/confirm-data/missing';
21
22
    /**
23
     * @return string
24
     */
25
    protected function getDNI()
26
    {
27
        $dni = '0000' . rand(pow(10, 4-1), pow(10, 4)-1);
28
        $value = (int) ($dni / 23);
29
        $value *= 23;
30
        $value= $dni - $value;
31
        $letter= "TRWAGMYFPDXBNJZSQVHLCKEO";
32
        $dniLetter= substr($letter, $value, 1);
33
34
        return $dni.$dniLetter;
35
    }
36
37
    /**
38
     * Pass from confirm-data to next step in Application Form
39
     *
40
     * @throws \Exception
41
     */
42
    public function run()
43
    {
44
        $this->validateStep(self::STEP);
45
        //Click on confirm:
46
        $this->waitTobeVisible(WebDriverBy::name('workingStatus'));
47
        $select = new WebDriverSelect($this->webDriver->findElement(WebDriverBy::name('workingStatus')));
48
        $select->selectByValue('employed');
49
50
        /*
51
         * Optional Full Name:
52
         */
53
        try {
54
            $name = $this->webDriver->findElement(WebDriverBy::name('name'));
55
            $name->clear()->sendKeys(
56
                $this->faker->firstName . ' ' . $this->faker->lastName
0 ignored issues
show
Bug introduced by
The property firstName does not seem to exist on Faker\Factory.
Loading history...
Bug introduced by
The property lastName does not seem to exist on Faker\Factory.
Loading history...
57
            );
58
        } catch (\Exception $exception) {
59
            unset($exception);
60
        }
61
62
        /*
63
         * Optional DNI:
64
         */
65
        try {
66
            $name = $this->webDriver->findElement(WebDriverBy::name('dni'));
67
            $name->clear()->sendKeys($this->getDNI());
68
        } catch (\Exception $exception) {
69
            unset($exception);
70
        }
71
72
        /*
73
         * Optional BirthDate:
74
         */
75
        try {
76
            $select = new WebDriverSelect($this->webDriver->findElement(WebDriverBy::name('dob-day')));
77
            $select->selectByValue($this->faker->numberBetween(1, 28));
0 ignored issues
show
Bug introduced by
The method numberBetween() does not exist on Faker\Factory. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

77
            $select->selectByValue($this->faker->/** @scrutinizer ignore-call */ numberBetween(1, 28));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
78
            $select = new WebDriverSelect($this->webDriver->findElement(WebDriverBy::name('dob-month')));
79
            $select->selectByValue($this->faker->numberBetween(1, 12));
80
            $select = new WebDriverSelect($this->webDriver->findElement(WebDriverBy::name('dob-year')));
81
            $select->selectByValue('1975');
82
        } catch (\Exception $exception) {
83
            unset($exception);
84
        }
85
86
        /*
87
         * Optional Phone:
88
         */
89
        try {
90
            $name = $this->webDriver->findElement(WebDriverBy::name('cellphone'));
91
            $name->clear()->sendKeys('6' . $this->faker->randomNumber(8));
0 ignored issues
show
Bug introduced by
The method randomNumber() does not exist on Faker\Factory. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

91
            $name->clear()->sendKeys('6' . $this->faker->/** @scrutinizer ignore-call */ randomNumber(8));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
92
        } catch (\Exception $exception) {
93
            unset($exception);
94
        }
95
96
        /*
97
         * Optional address:
98
         */
99
        try {
100
            $name = $this->webDriver->findElement(WebDriverBy::name('address'));
101
            $name->clear()->sendKeys($this->faker->address. ' ' . $this->faker->city);
0 ignored issues
show
Bug introduced by
The property city does not seem to exist on Faker\Factory.
Loading history...
Bug introduced by
The property address does not seem to exist on Faker\Factory.
Loading history...
102
        } catch (\Exception $exception) {
103
            unset($exception);
104
        }
105
106
        /*
107
         * Optional city:
108
         */
109
        try {
110
            $name = $this->webDriver->findElement(WebDriverBy::name('city'));
111
            $name->clear()->sendKeys($this->faker->city);
112
        } catch (\Exception $exception) {
113
            unset($exception);
114
        }
115
116
        /*
117
         * Optional zipcode:
118
         */
119
        try {
120
            $name = $this->webDriver->findElement(WebDriverBy::name('zipcode'));
121
            $name->clear()->sendKeys($this->faker->postcode);
0 ignored issues
show
Bug introduced by
The property postcode does not seem to exist on Faker\Factory.
Loading history...
122
        } catch (\Exception $exception) {
123
            unset($exception);
124
        }
125
126
        /*
127
         * Optional password:
128
         */
129
        try {
130
            $name = $this->webDriver->findElement(WebDriverBy::name('password'));
131
            if (null === SeleniumHelper::$mobilePhone) {
0 ignored issues
show
introduced by
The condition null === Pagantis\Seleni...niumHelper::mobilePhone is always false.
Loading history...
132
                throw new \Exception('Please provide mobile phone for returning customer');
133
            } else {
134
                $name->clear()->sendKeys(substr(SeleniumHelper::$mobilePhone, -4));
135
            }
136
        } catch (\Exception $exception) {
137
            unset($exception);
138
        }
139
140
        /*
141
         * Click form continue
142
         */
143
        try {
144
            $formContinue = $this->webDriver->findElement(WebDriverBy::name('edit_customer_data_form_continue'));
145
            $formContinue->click();
146
        } catch (\Exception $exception) {
147
            unset($exception);
148
        }
149
150
        /*
151
         * Click login button
152
         */
153
        try {
154
            $formContinue = $this->webDriver->findElement(WebDriverBy::name('login_modal_loginButton'));
155
            $formContinue->click();
156
        } catch (\Exception $exception) {
157
            unset($exception);
158
        }
159
    }
160
}
161