Passed
Push — main ( c439fd...c90578 )
by Mariano
02:51
created

AmpOptimizerSubscriberTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 9
eloc 39
c 1
b 0
f 1
dl 0
loc 90
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testSubscribedEvents() 0 5 1
A getInstance() 0 24 3
A testTransformRequest() 0 5 1
A testNotMasterRequest() 0 5 1
A getEventNotMasterRequestMocked() 0 7 1
A getEventMasterRequestMocked() 0 14 1
A setUp() 0 3 1
1
<?php
0 ignored issues
show
Coding Style introduced by
Class found in ".php" file; use ".inc" extension instead
Loading history...
Coding Style introduced by
This file is missing a doc comment.
Loading history...
Coding Style introduced by
The PHP open tag does not have a corresponding PHP close tag
Loading history...
Coding Style introduced by
Filename "AmpOptimizerSubscriberTest.php" doesn't match the expected filename "ampoptimizersubscribertest.php"
Loading history...
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace App\Tests\Unit\EventSubscriber;
4
5
use AmpProject\Optimizer\ErrorCollection;
6
use AmpProject\Optimizer\TransformationEngine;
7
use DG\BypassFinals;
8
use Hola\AmpToolboxBundle\EventSubscriber\AmpOptimizerSubscriber;
9
use PHPUnit\Framework\TestCase;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Prophecy\Argument;
11
use Psr\Log\LoggerInterface;
12
use Symfony\Component\HttpFoundation\Response;
13
use Symfony\Component\HttpKernel\Event\ResponseEvent;
14
use Symfony\Component\HttpKernel\KernelEvents;
15
16
class AmpOptimizerSubscriberTest extends TestCase
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for class AmpOptimizerSubscriberTest
Loading history...
17
{
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration for class AmpOptimizerSubscriberTest
Loading history...
18
    public function setUp(): void
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 0 found
Loading history...
Coding Style introduced by
Missing doc comment for function setUp()
Loading history...
19
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
20
        BypassFinals::enable();
21
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end setUp()
Loading history...
22
23
    public function testSubscribedEvents()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function testSubscribedEvents()
Loading history...
24
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
25
        $events = AmpOptimizerSubscriber::getSubscribedEvents();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 9 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
26
        $eventsExpected = [KernelEvents::RESPONSE => ['onKernelResponse', -10]];
0 ignored issues
show
Coding Style introduced by
Arrays with multiple values should not be declared on a single line.
Loading history...
Coding Style introduced by
Short array syntax is not allowed
Loading history...
27
        $this->assertEquals($events, $eventsExpected);
28
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end testSubscribedEvents()
Loading history...
29
30
    public function testNotMasterRequest()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function testNotMasterRequest()
Loading history...
31
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
32
        $instance = $this->getInstance(false);
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL should be uppercase as per the configured coding-style; instead of false please use FALSE.
Loading history...
33
        $event = $this->getEventNotMasterRequestMocked();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
34
        $instance->onKernelResponse($event);
35
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end testNotMasterRequest()
Loading history...
36
37
38
    public function testTransformRequest()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function testTransformRequest()
Loading history...
39
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
40
        $instance = $this->getInstance();
41
        $event = $this->getEventMasterRequestMocked();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
42
        $instance->onKernelResponse($event);
43
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end testTransformRequest()
Loading history...
44
45
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
46
     * @param bool $transform
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected "boolean" but found "bool" for parameter type
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
47
     * @param array $config
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
48
     * @return AmpOptimizerSubscriber
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
49
     */
50
    private function getInstance($transform = true, $config = []): AmpOptimizerSubscriber
0 ignored issues
show
Coding Style introduced by
Private method name "AmpOptimizerSubscriberTest::getInstance" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Type hint "bool" missing for $transform
Loading history...
introduced by
Type hint "array" missing for $config
Loading history...
Coding Style introduced by
TRUE, FALSE and NULL should be uppercase as per the configured coding-style; instead of true please use TRUE.
Loading history...
Coding Style introduced by
Short array syntax is not allowed
Loading history...
51
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
52
        $logger = $this->prophesize(LoggerInterface::class);
53
54
        $transformationEngine = $this->prophesize(TransformationEngine::class);
55
56
        if ($transform) {
57
            $transformationEngine->optimizeHtml(
58
                Argument::type('string'),
59
                Argument::type(ErrorCollection::class)
60
            )->shouldBeCalled();
61
        }
62
63
        if (!$transform) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
64
            $transformationEngine->optimizeHtml(
65
                Argument::type('string'),
66
                Argument::type(ErrorCollection::class)
67
            )->shouldNotBeCalled();
68
        }
69
70
        return new AmpOptimizerSubscriber(
71
            $logger->reveal(),
72
            $transformationEngine->reveal(),
73
            $config
74
        );
75
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end getInstance()
Loading history...
76
77
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
78
     * @return ResponseEvent
79
     */
80
    private function getEventMasterRequestMocked(): ResponseEvent
0 ignored issues
show
Coding Style introduced by
Private method name "AmpOptimizerSubscriberTest::getEventMasterRequestMocked" must be prefixed with an underscore
Loading history...
81
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
82
        /** @var Response $response */
0 ignored issues
show
Coding Style introduced by
Inline doc block comments are not allowed; use "/* Comment */" or "// Comment" instead
Loading history...
Coding Style introduced by
Block comments must be started with /*
Loading history...
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
83
        $response = $this->prophesize(Response::class);
84
        $response->getContent()->shouldBeCalled()->willReturn('html');
85
        $response->setContent(null)->shouldBeCalled();
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL should be uppercase as per the configured coding-style; instead of null please use NULL.
Loading history...
Bug introduced by
The method shouldBeCalled() does not exist on Symfony\Component\HttpFoundation\Response. ( Ignorable by Annotation )

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

85
        $response->setContent(null)->/** @scrutinizer ignore-call */ shouldBeCalled();

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...
86
        $response = $response->reveal();
0 ignored issues
show
Bug introduced by
The method reveal() does not exist on Symfony\Component\HttpFoundation\Response. ( Ignorable by Annotation )

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

86
        /** @scrutinizer ignore-call */ 
87
        $response = $response->reveal();

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...
87
88
89
        /** @var ResponseEvent $event */
0 ignored issues
show
Coding Style introduced by
Inline doc block comments are not allowed; use "/* Comment */" or "// Comment" instead
Loading history...
Coding Style introduced by
Block comments must be started with /*
Loading history...
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
90
        $event = $this->prophesize(ResponseEvent::class);
91
        $event->isMasterRequest()->shouldBeCalled()->willReturn(true);
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL should be uppercase as per the configured coding-style; instead of true please use TRUE.
Loading history...
92
        $event->getResponse()->shouldBeCalled()->willReturn($response);;
0 ignored issues
show
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
93
        return $event->reveal();
0 ignored issues
show
Bug introduced by
The method reveal() does not exist on Symfony\Component\HttpKernel\Event\ResponseEvent. ( Ignorable by Annotation )

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

93
        return $event->/** @scrutinizer ignore-call */ reveal();

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...
94
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end getEventMasterRequestMocked()
Loading history...
95
96
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
97
     * @return ResponseEvent
98
     */
99
    private function getEventNotMasterRequestMocked(): ResponseEvent
0 ignored issues
show
Coding Style introduced by
Private method name "AmpOptimizerSubscriberTest::getEventNotMasterRequestMocked" must be prefixed with an underscore
Loading history...
100
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
101
        /** @var ResponseEvent $event */
0 ignored issues
show
Coding Style introduced by
Inline doc block comments are not allowed; use "/* Comment */" or "// Comment" instead
Loading history...
Coding Style introduced by
Block comments must be started with /*
Loading history...
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
102
        $event = $this->prophesize(ResponseEvent::class);
103
        $event->isMasterRequest()->shouldBeCalled()->willReturn(false);
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL should be uppercase as per the configured coding-style; instead of false please use FALSE.
Loading history...
104
        $event->getResponse()->shouldNotBeCalled();
0 ignored issues
show
Bug introduced by
The method shouldNotBeCalled() does not exist on Symfony\Component\HttpFoundation\Response. ( Ignorable by Annotation )

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

104
        $event->getResponse()->/** @scrutinizer ignore-call */ shouldNotBeCalled();

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...
105
        return $event->reveal();
106
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end getEventNotMasterRequestMocked()
Loading history...
107
}
0 ignored issues
show
Coding Style introduced by
Expected //end class
Loading history...
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
108