Completed
Pull Request — feature/acceptance-tests (#191)
by Michiel
02:42 queued 58s
created

FeatureContext::gatherContexts()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/**
4
 * Copyright 2020 SURFnet B.V.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace Surfnet\StepupGateway\Behat;
20
21
use Behat\Behat\Context\Context;
22
use Behat\Behat\Hook\Scope\BeforeFeatureScope;
23
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
24
use Behat\Behat\Tester\Exception\PendingException;
25
use Surfnet\StepupGateway\Behat\Service\FixtureService;
26
27
class FeatureContext implements Context
28
{
29
    /**
30
     * @var FixtureService
31
     */
32
    private $fixtureService;
33
34
    private $whitelistedInstitutions = [];
35
36
    /**
37
     * @var MinkContext
38
     */
39
    private $minkContext;
40
41
    public function __construct(FixtureService $fixtureService)
42
    {
43
        $this->fixtureService = $fixtureService;
44
    }
45
46
    /**
47
     * @BeforeFeature
48
     */
49
    public static function setupDatabase(BeforeFeatureScope $scope)
0 ignored issues
show
Unused Code introduced by
The parameter $scope is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
50
    {
51
        // Generate test databases
52
        echo "Preparing test schemas\n";
53
        shell_exec("/var/www/app/console doctrine:schema:drop --env=test --force");
54
        shell_exec("/var/www/app/console doctrine:schema:create --env=test");
55
    }
56
57
    /**
58
     * @BeforeScenario
59
     */
60
    public function gatherContexts(BeforeScenarioScope $scope)
61
    {
62
        $environment = $scope->getEnvironment();
63
        $this->minkContext = $environment->getContext(MinkContext::class);
64
    }
65
66
    /**
67
     * @Given /^a user from ([^"]*) identified by ([^"]*) with a vetted ([^"]*) token$/
68
     */
69
    public function aUserIdentifiedByWithAVettedToken($institution, $nameId, $tokenType)
70
    {
71
        switch (strtolower($tokenType)) {
72
            case "yubikey":
73
                $tokenInformation = $this->fixtureService->registerYubikeyToken($nameId, $institution);
0 ignored issues
show
Unused Code introduced by
$tokenInformation is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
74
                break;
75
        }
76
    }
77
78
    /**
79
     * @Then I should see the Yubikey OTP screen
80
     */
81
    public function iShouldSeeTheYubikeyOtpScreen()
82
    {
83
        $this->minkContext->assertPageContainsText('Log in with YubiKey');
84
        $this->minkContext->assertPageContainsText('Your YubiKey-code');
85
86
    }
87
88
    /**
89
     * @When I enter the OTP
90
     */
91
    public function iEnterTheOtp()
92
    {
93
        $this->minkContext->fillField('gateway_verify_yubikey_otp_otp', 'bogus-otp-we-use-a-mock-yubikey-service');
94
        $this->minkContext->pressButton('gateway_verify_yubikey_otp_submit');
95
        $this->minkContext->pressButton('Submit');
96
    }
97
98
    /**
99
     * @Given /^a whitelisted institution ([^"]*)$/
100
     */
101
    public function aWhitelistedInstitution($institution)
102
    {
103
        $this->whitelistedInstitutions[] = $this->fixtureService->whitelist($institution)['institution'];
104
    }
105
}
106