GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( c7c802...71c991 )
by Malte
03:14
created

assertHttpStatusCodeWhenCrawlingRenderedExample()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
ccs 0
cts 6
cp 0
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
namespace Webfactory\ShortcodeBundle\Tests\Functional;
4
5
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
6
use Symfony\Component\DomCrawler\Crawler;
7
8
/**
9
 * Abstract template for common shortcode tests.
10
 */
11
abstract class ShortcodeTest extends WebTestCase
12
{
13
    /**
14
     * @return string name of the shortcode to test.
15
     */
16
    abstract protected function getShortcodeToTest();
17
18
    protected function setUp()
19
    {
20
        parent::setUp();
21
22
        if ($this->getShortcodeToTest() === '' || $this->getShortcodeToTest() === null) {
23
            throw new \PHPUnit_Framework_IncompleteTestError(
24
                'Albeit being a ' . __CLASS__ . ', ' . get_called_class() . ' does not define a shortcode to test.'
25
            );
26
        }
27
    }
28
29
    /**
30
     * @param string|null $customParameters
31
     * @return Crawler
32
     */
33
    protected function crawlRenderedExample($customParameters = null)
34
    {
35
        $urlWithRenderedExample = $this->getUrlWithRenderedExample($customParameters);
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $urlWithRenderedExample exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
36
37
        $client = static::createClient();
38
        $crawlerOnRenderedExamplePage = $client->request('GET', $urlWithRenderedExample);
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $crawlerOnRenderedExamplePage exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
39
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
40
41
        $crawlerOnRenderedExample = $crawlerOnRenderedExamplePage->filter('#rendered-example');
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $crawlerOnRenderedExample exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
42
        if ($crawlerOnRenderedExample->count() === 0) {
43
            throw new \PHPUnit_Framework_ExpectationFailedException(
44
                'No rendered example found for shortcode "' . $this->shortcode . '"'
45
            );
46
        }
47
48
        return $crawlerOnRenderedExample;
49
    }
50
51
    /**
52
     * @param int $expectedStatusCode
53
     * @param string|null $customParameters
54
     * @return Crawler
0 ignored issues
show
Documentation introduced by
Should the return type not be Crawler|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
55
     */
56
    protected function assertHttpStatusCodeWhenCrawlingRenderedExample($expectedStatusCode, $customParameters = null)
57
    {
58
        $urlWithRenderedExample = $this->getUrlWithRenderedExample($customParameters);
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $urlWithRenderedExample exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
59
60
        $client = static::createClient();
61
        $crawlerOnRenderedExamplePage = $client->request('GET', $urlWithRenderedExample);
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $crawlerOnRenderedExamplePage exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
62
        $this->assertEquals($expectedStatusCode, $client->getResponse()->getStatusCode());
63
    }
64
65
    /**
66
     * @param string|null $customParameters
67
     * @return string
68
     */
69
    protected function getUrlWithRenderedExample($customParameters = null)
70
    {
71
        static::bootKernel();
72
73
        $urlParameters = ['shortcode' => $this->getShortcodeToTest()];
74
        if ($customParameters) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $customParameters of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
75
            $urlParameters['customParameters'] = $customParameters;
76
        }
77
78
        return static::$kernel
79
            ->getContainer()
80
            ->get('router')
81
            ->generate('webfactory.shortcode.guide-detail', $urlParameters);
82
    }
83
}
84