Code Duplication    Length = 26-27 lines in 2 locations

Tests/EventListener/GeoBlockingKernelRequestListenerTest.php 2 locations

@@ 114-139 (lines=26) @@
111
        $geoBlockingListener->onKernelRequest($eventBlockMock);
112
    }
113
114
    public function testOnKernelRequestGeoBlocking_AnonOnlyNotLoggedIn()
115
    {
116
        $parameters = $this->getDefaultParams();
117
        $eventBlockMock = $this->getMockBuilder("Symfony\Component\HttpKernel\Event\GetResponseEvent")->disableOriginalConstructor()->getMock();
118
        $requestMock = $this->getMockBuilder("Symfony\Component\HttpFoundation\Request")->disableOriginalConstructor()->getMock();
119
        $loggerMock = $this->getMockBuilder("Psr\Log\LoggerInterface")->disableOriginalConstructor()->getMock();
120
121
        $containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\Container")->disableOriginalConstructor()->getMock();
122
        $securityContextMock = $this->getMockBuilder("Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage")->disableOriginalConstructor()->getMock();
123
        $tokenMock = $this->getMockBuilder("Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken")->disableOriginalConstructor()->getMock();
124
125
        $tokenMock->expects($this->once())->method("getUser")->will($this->returnValue(null));
126
        $securityContextMock->expects($this->once())->method("getToken")->will($this->returnValue($tokenMock));
127
        $containerMock->expects($this->once())->method("get")->will($this->returnValue($securityContextMock));
128
129
        $eventBlockMock->expects($this->once())->method("getRequestType")->will($this->returnValue(HttpKernelInterface::MASTER_REQUEST));
130
        $eventBlockMock->expects($this->once())->method("setResponse")->will($this->returnCallback(array($this, 'checkResponseCode')));
131
        $requestMock->expects($this->once())->method("getClientIp")->will($this->returnValue($this->usIP));
132
        $requestMock->expects($this->once())->method("get");
133
        $eventBlockMock->expects($this->once())->method("stopPropagation");
134
        $eventBlockMock->expects($this->once())->method("getRequest")->will($this->returnValue($requestMock));
135
136
        $geoBlockingListener = new GeoBlockingKernelRequestListener($this->getTemplatingMock(true), new DefaultLookupAdapter(), $loggerMock, $containerMock, $parameters);
137
        $geoBlockingListener->onKernelRequest($eventBlockMock);
138
139
    }
140
141
    public function testOnKernelRequestGeoBlocking_AnonOnlyLoggedIn()
142
    {
@@ 141-167 (lines=27) @@
138
139
    }
140
141
    public function testOnKernelRequestGeoBlocking_AnonOnlyLoggedIn()
142
    {
143
        $parameters = $this->getDefaultParams();
144
        $eventBlockMock = $this->getMockBuilder("Symfony\Component\HttpKernel\Event\GetResponseEvent")->disableOriginalConstructor()->getMock();
145
        $requestMock = $this->getMockBuilder("Symfony\Component\HttpFoundation\Request")->disableOriginalConstructor()->getMock();
146
147
        $loggerMock = $this->getMockBuilder("Psr\Log\LoggerInterface")->disableOriginalConstructor()->getMock();
148
149
        $containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\Container")->disableOriginalConstructor()->getMock();
150
        $securityContextMock = $this->getMockBuilder("Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage")->disableOriginalConstructor()->getMock();
151
        $tokenMock = $this->getMockBuilder("Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken")->disableOriginalConstructor()->getMock();
152
153
        $tokenMock->expects($this->once())->method("getUser")->will($this->returnValue($this->getMockBuilder("Symfony\Component\Security\Core\User\UserInterface")->disableOriginalConstructor()->getMock()));
154
        $securityContextMock->expects($this->once())->method("getToken")->will($this->returnValue($tokenMock));
155
        $containerMock->expects($this->once())->method("get")->will($this->returnValue($securityContextMock));
156
157
        $eventBlockMock->expects($this->once())->method("getRequestType")->will($this->returnValue(HttpKernelInterface::MASTER_REQUEST));
158
        $eventBlockMock->expects($this->once())->method("getRequest")->will($this->returnValue($requestMock));
159
           $requestMock->expects($this->never())->method("getClientIp")->will($this->returnValue($this->usIP));
160
        $requestMock->expects($this->never())->method("get");
161
        $eventBlockMock->expects($this->never())->method("setResponse");
162
        $eventBlockMock->expects($this->never())->method("stopPropagation");
163
164
        $geoBlockingListener = new GeoBlockingKernelRequestListener($this->getTemplatingMock(false), new DefaultLookupAdapter(), $loggerMock, $containerMock, $parameters);
165
        $geoBlockingListener->onKernelRequest($eventBlockMock);
166
167
    }
168
169
    public function testOnKernelRequestGeoBlocking_AllowPrivateIPs()
170
    {