8 use Zend\Uri\UriFactory;
26 $socketFactoryMock = $this->createMock(\
Magento\CacheInvalidate\Model\SocketFactory::class);
27 $this->socketAdapterMock = $this->createMock(\
Zend\Http\Client\Adapter\Socket::class);
28 $this->socketAdapterMock->expects($this->once())
29 ->method(
'setOptions')
30 ->with([
'timeout' => 10]);
31 $socketFactoryMock->expects($this->once())
33 ->willReturn($this->socketAdapterMock);
35 $this->loggerMock = $this->createMock(\
Magento\Framework\Cache\InvalidateLogger::class);
36 $this->cacheServer = $this->createMock(\
Magento\PageCache\Model\Cache\Server::class);
38 $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
40 \
Magento\CacheInvalidate\Model\PurgeCache::class,
42 'cacheServer' => $this->cacheServer,
43 'socketAdapterFactory' => $socketFactoryMock,
44 'logger' => $this->loggerMock,
56 foreach ($hosts as $host) {
58 $uris[] = UriFactory::factory(
'')->setHost($host[
'host'])
62 $this->cacheServer->expects($this->once())
67 foreach ($uris as $uri) {
68 $this->socketAdapterMock->expects($this->at(
$i++))
70 ->with($uri->getHost(), $uri->getPort());
71 $this->socketAdapterMock->expects($this->at(
$i++))
73 ->with(
'PURGE', $uri,
'1.1', [
'X-Magento-Tags-Pattern' =>
'tags',
'Host' => $uri->getHost()]);
74 $this->socketAdapterMock->expects($this->at(
$i++))
78 $this->socketAdapterMock->expects($this->exactly(count($uris)))
81 $this->loggerMock->expects($this->once())
84 $this->assertTrue($this->model->sendPurgeRequest(
'tags'));
94 [[
'host' =>
'127.0.0.1',
'port' => 8080]]
98 [
'host' =>
'127.0.0.1',
'port' => 8080],
99 [
'host' =>
'127.0.0.2',
'port' => 1234],
108 $uris[] = UriFactory::factory(
'')->setHost(
'127.0.0.1')
112 $this->cacheServer->expects($this->once())
115 $this->socketAdapterMock->method(
'connect')
116 ->willThrowException(
new \
Zend\Http\Client\Adapter\Exception\RuntimeException());
117 $this->loggerMock->expects($this->never())
119 $this->loggerMock->expects($this->once())
120 ->method(
'critical');
122 $this->assertFalse($this->model->sendPurgeRequest(
'tags'));
testSendPurgeRequest($hosts)
testSendPurgeRequestWithException()
sendPurgeRequestDataProvider()