Completed
Push — master ( 798ee0...2329f6 )
by Lucas
08:18
created

HeaderFieldStrategyTest::testApply()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 24
rs 8.9713
cc 1
eloc 15
nc 1
nop 1
1
<?php
2
/**
3
 * check to see if reading from header field works
4
 */
5
6
namespace Graviton\SecurityBundle\Authentication\Strategies;
7
8
use Graviton\TestBundle\Test\WebTestCase;
9
10
/**
11
 * Class HeaderFieldStrategyTest
12
 *
13
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
14
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
15
 * @link     http://swisscom.ch
16
 */
17
class HeaderFieldStrategyTest extends WebTestCase
18
{
19
    /**
20
     * @covers       \Graviton\SecurityBundle\Authentication\Strategies\HeaderFieldStrategy::apply
21
     * @covers       \Graviton\SecurityBundle\Authentication\Strategies\AbstractHttpStrategy::extractFieldInfo
22
     * @covers       \Graviton\SecurityBundle\Authentication\Strategies\AbstractHttpStrategy::validateField
23
     *
24
     * @dataProvider stringProvider
25
     *
26
     * @param string $headerFieldValue header to test with
27
     *
28
     * @return void
29
     */
30
    public function testApply($headerFieldValue)
31
    {
32
        $server = array(
33
            'HTTP_X_IDP_USERNAME' => $headerFieldValue, //"example-authentication-header",
34
        );
35
36
        $client = static::createClient();
37
        $client->request(
38
            'GET', //method
39
            '/', //uri
40
            array(), //parameters
41
            array(), //files
42
            $server
43
        );
44
45
        $strategy = new HeaderFieldStrategy(
46
            $client->getKernel()->getContainer()->getParameter('graviton.security.authentication.strategy_key')
47
        );
48
49
        $this->assertEquals(
50
            $headerFieldValue,
51
            $strategy->apply($client->getRequest())
0 ignored issues
show
Documentation introduced by
$client->getRequest() is of type object<Symfony\Component\BrowserKit\Request>, but the function expects a object<Symfony\Component\HttpFoundation\Request>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
52
        );
53
    }
54
55
    /**
56
     * @return array<string>
57
     */
58 View Code Duplication
    public function stringProvider()
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...
59
    {
60
        return array(
61
            'plain string, no special chars' => array('exampleAuthenticationHeader'),
62
            'string with special chars'      => array("$-_.+!*'(),{}|\\^~[]`<>#%;/?:@&=."),
63
            'string with octal chars'        => array("a: \141, A: \101"),
64
            'string with hex chars'          => array("a: \x61, A: \x41")
65
        );
66
    }
67
}
68