| 1 | <?php |
||||||
| 2 | |||||||
| 3 | declare(strict_types=1); |
||||||
| 4 | |||||||
| 5 | /* |
||||||
| 6 | * This file is part of Ekino New Relic bundle. |
||||||
| 7 | * |
||||||
| 8 | * (c) Ekino - Thomas Rabaix <[email protected]> |
||||||
| 9 | * |
||||||
| 10 | * For the full copyright and license information, please view the LICENSE |
||||||
| 11 | * file that was distributed with this source code. |
||||||
| 12 | */ |
||||||
| 13 | |||||||
| 14 | namespace Ekino\NewRelicBundle\Tests\Twig; |
||||||
| 15 | |||||||
| 16 | use Ekino\NewRelicBundle\NewRelic\Config; |
||||||
| 17 | use Ekino\NewRelicBundle\NewRelic\NewRelicInteractorInterface; |
||||||
| 18 | use Ekino\NewRelicBundle\Twig\NewRelicExtension; |
||||||
| 19 | use PHPUnit\Framework\TestCase; |
||||||
|
0 ignored issues
–
show
|
|||||||
| 20 | |||||||
| 21 | class NewRelicExtensionTest extends TestCase |
||||||
| 22 | { |
||||||
| 23 | /** |
||||||
| 24 | * @var \Ekino\NewRelicBundle\NewRelic\Config |
||||||
| 25 | */ |
||||||
| 26 | private $newRelic; |
||||||
| 27 | |||||||
| 28 | /** |
||||||
| 29 | * @var \Ekino\NewRelicBundle\NewRelic\NewRelicInteractorInterface |
||||||
| 30 | */ |
||||||
| 31 | private $interactor; |
||||||
| 32 | |||||||
| 33 | protected function setUp(): void |
||||||
| 34 | { |
||||||
| 35 | $this->newRelic = $this->getMockBuilder(Config::class) |
||||||
| 36 | ->setMethods(['getCustomMetrics', 'getCustomParameters']) |
||||||
| 37 | ->disableOriginalConstructor() |
||||||
| 38 | ->getMock(); |
||||||
| 39 | $this->interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); |
||||||
| 40 | } |
||||||
| 41 | |||||||
| 42 | /** |
||||||
| 43 | * Tests the initial values returned by state methods. |
||||||
| 44 | */ |
||||||
| 45 | public function testInitialSetup() |
||||||
| 46 | { |
||||||
| 47 | $extension = new NewRelicExtension( |
||||||
| 48 | $this->newRelic, |
||||||
| 49 | $this->interactor |
||||||
| 50 | ); |
||||||
| 51 | |||||||
| 52 | $this->assertFalse($extension->isHeaderCalled()); |
||||||
| 53 | $this->assertFalse($extension->isFooterCalled()); |
||||||
| 54 | $this->assertFalse($extension->isUsed()); |
||||||
| 55 | } |
||||||
| 56 | |||||||
| 57 | public function testHeaderException() |
||||||
| 58 | { |
||||||
| 59 | $extension = new NewRelicExtension( |
||||||
| 60 | $this->newRelic, |
||||||
| 61 | $this->interactor |
||||||
| 62 | ); |
||||||
| 63 | |||||||
| 64 | $this->newRelic->expects($this->once()) |
||||||
|
0 ignored issues
–
show
The method
expects() does not exist on Ekino\NewRelicBundle\NewRelic\Config.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
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...
|
|||||||
| 65 | ->method('getCustomMetrics') |
||||||
| 66 | ->willReturn([]); |
||||||
| 67 | |||||||
| 68 | $this->newRelic->expects($this->once()) |
||||||
| 69 | ->method('getCustomParameters') |
||||||
| 70 | ->willReturn([]); |
||||||
| 71 | |||||||
| 72 | $this->expectException(\RuntimeException::class); |
||||||
| 73 | |||||||
| 74 | $extension->getNewrelicBrowserTimingHeader(); |
||||||
| 75 | $extension->getNewrelicBrowserTimingHeader(); |
||||||
| 76 | } |
||||||
| 77 | |||||||
| 78 | public function testFooterException() |
||||||
| 79 | { |
||||||
| 80 | $extension = new NewRelicExtension( |
||||||
| 81 | $this->newRelic, |
||||||
| 82 | $this->interactor |
||||||
| 83 | ); |
||||||
| 84 | |||||||
| 85 | $this->newRelic->expects($this->once()) |
||||||
| 86 | ->method('getCustomMetrics') |
||||||
| 87 | ->willReturn([]); |
||||||
| 88 | |||||||
| 89 | $this->newRelic->expects($this->once()) |
||||||
| 90 | ->method('getCustomParameters') |
||||||
| 91 | ->willReturn([]); |
||||||
| 92 | |||||||
| 93 | $this->expectException(\RuntimeException::class); |
||||||
| 94 | |||||||
| 95 | $extension->getNewrelicBrowserTimingHeader(); |
||||||
| 96 | $extension->getNewrelicBrowserTimingHeader(); |
||||||
| 97 | } |
||||||
| 98 | |||||||
| 99 | public function testPreparingOfInteractor() |
||||||
| 100 | { |
||||||
| 101 | $headerValue = '__HEADER__TIMING__'; |
||||||
| 102 | $footerValue = '__FOOTER__TIMING__'; |
||||||
| 103 | |||||||
| 104 | $extension = new NewRelicExtension( |
||||||
| 105 | $this->newRelic, |
||||||
| 106 | $this->interactor, |
||||||
| 107 | true |
||||||
| 108 | ); |
||||||
| 109 | |||||||
| 110 | $this->newRelic->expects($this->once()) |
||||||
| 111 | ->method('getCustomMetrics') |
||||||
| 112 | ->willReturn([ |
||||||
| 113 | 'a' => 'b', |
||||||
| 114 | 'c' => 'd', |
||||||
| 115 | ]); |
||||||
| 116 | |||||||
| 117 | $this->newRelic->expects($this->once()) |
||||||
| 118 | ->method('getCustomParameters') |
||||||
| 119 | ->willReturn([ |
||||||
| 120 | 'e' => 'f', |
||||||
| 121 | 'g' => 'h', |
||||||
| 122 | 'i' => 'j', |
||||||
| 123 | ]); |
||||||
| 124 | |||||||
| 125 | $this->interactor->expects($this->once()) |
||||||
|
0 ignored issues
–
show
The method
expects() does not exist on Ekino\NewRelicBundle\New...elicInteractorInterface.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
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...
|
|||||||
| 126 | ->method('disableAutoRum'); |
||||||
| 127 | |||||||
| 128 | $this->interactor->expects($this->exactly(2)) |
||||||
| 129 | ->method('addCustomMetric'); |
||||||
| 130 | |||||||
| 131 | $this->interactor->expects($this->exactly(3)) |
||||||
| 132 | ->method('addCustomParameter'); |
||||||
| 133 | |||||||
| 134 | $this->interactor->expects($this->once()) |
||||||
| 135 | ->method('getBrowserTimingHeader') |
||||||
| 136 | ->willReturn($headerValue); |
||||||
| 137 | |||||||
| 138 | $this->interactor->expects($this->once()) |
||||||
| 139 | ->method('getBrowserTimingFooter') |
||||||
| 140 | ->willReturn($footerValue); |
||||||
| 141 | |||||||
| 142 | $this->assertSame($headerValue, $extension->getNewrelicBrowserTimingHeader()); |
||||||
| 143 | $this->assertTrue($extension->isHeaderCalled()); |
||||||
| 144 | $this->assertFalse($extension->isFooterCalled()); |
||||||
| 145 | |||||||
| 146 | $this->assertSame($footerValue, $extension->getNewrelicBrowserTimingFooter()); |
||||||
| 147 | $this->assertTrue($extension->isHeaderCalled()); |
||||||
| 148 | $this->assertTrue($extension->isFooterCalled()); |
||||||
| 149 | } |
||||||
| 150 | } |
||||||
| 151 |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths