3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ declare (strict_types=1 );
7
+
6
8
namespace Magento \CacheInvalidate \Test \Unit \Observer ;
7
9
10
+ use Magento \CacheInvalidate \Model \PurgeCache ;
11
+ use Magento \CacheInvalidate \Observer \InvalidateVarnishObserver ;
12
+ use Magento \Framework \App \Cache \Tag \Resolver ;
13
+ use Magento \Framework \Event ;
14
+ use Magento \Framework \Event \Observer ;
8
15
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
16
+ use Magento \PageCache \Model \Config ;
17
+ use Magento \Store \Model \Store ;
18
+ use PHPUnit \Framework \MockObject \MockObject ;
19
+ use PHPUnit \Framework \TestCase ;
9
20
10
- class InvalidateVarnishObserverTest extends \PHPUnit \Framework \TestCase
21
+ /**
22
+ * Test class for \Magento\CacheInvalidate\Observer\InvalidateVarnishObserver
23
+ */
24
+ class InvalidateVarnishObserverTest extends TestCase
11
25
{
12
- /** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\CacheInvalidate\Observer\InvalidateVarnishObserver */
13
- protected $ model ;
26
+ /**
27
+ * @var InvalidateVarnishObserver
28
+ */
29
+ private $ model ;
14
30
15
- /** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\Event\Observer */
16
- protected $ observerMock ;
31
+ /**
32
+ * @var Config|MockObject
33
+ */
34
+ private $ configMock ;
17
35
18
- /** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\PageCache\Model\Config */
19
- protected $ configMock ;
36
+ /**
37
+ * @var PurgeCache|MockObject
38
+ */
39
+ private $ purgeCacheMock ;
20
40
21
- /** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\CacheInvalidate\Model\PurgeCache */
22
- protected $ purgeCache ;
41
+ /**
42
+ * @var Resolver|MockObject
43
+ */
44
+ private $ tagResolverMock ;
23
45
24
- /** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\DataObject\ */
25
- protected $ observerObject ;
46
+ /**
47
+ * @var Observer|MockObject
48
+ */
49
+ private $ observerMock ;
26
50
27
- /** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\App\Cache\Tag\Resolver */
28
- private $ tagResolver ;
51
+ /**
52
+ * @var Store|MockObject
53
+ */
54
+ private $ observerObject ;
29
55
30
56
/**
31
- * Set up all mocks and data for test
57
+ * @inheritDoc
32
58
*/
33
59
protected function setUp ()
34
60
{
35
- $ helper = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
36
-
37
- $ this ->configMock = $ this ->createPartialMock (\Magento \PageCache \Model \Config::class, ['getType ' , 'isEnabled ' ]);
38
- $ this ->purgeCache = $ this ->createMock (\Magento \CacheInvalidate \Model \PurgeCache::class);
39
- $ this ->model = new \Magento \CacheInvalidate \Observer \InvalidateVarnishObserver (
40
- $ this ->configMock ,
41
- $ this ->purgeCache
42
- );
61
+ $ this ->configMock = $ this ->createPartialMock (Config::class, ['getType ' , 'isEnabled ' ]);
62
+ $ this ->purgeCacheMock = $ this ->createMock (PurgeCache::class);
63
+ $ this ->tagResolverMock = $ this ->createMock (Resolver::class);
43
64
44
- $ this ->tagResolver = $ this ->createMock (\ Magento \ Framework \ App \ Cache \ Tag \Resolver ::class);
45
- $ helper -> setBackwardCompatibleProperty ( $ this ->model , ' tagResolver ' , $ this ->tagResolver );
65
+ $ this ->observerMock = $ this ->createPartialMock (Observer ::class, [ ' getEvent ' ] );
66
+ $ this ->observerObject = $ this ->createMock (Store::class );
46
67
47
- $ this ->observerMock = $ this ->createPartialMock (\Magento \Framework \Event \Observer::class, ['getEvent ' ]);
48
- $ this ->observerObject = $ this ->createMock (\Magento \Store \Model \Store::class);
68
+ $ objectManager = new ObjectManager ($ this );
69
+ $ this ->model = $ objectManager ->getObject (
70
+ InvalidateVarnishObserver::class,
71
+ [
72
+ 'config ' => $ this ->configMock ,
73
+ 'purgeCache ' => $ this ->purgeCacheMock ,
74
+ 'tagResolver ' => $ this ->tagResolverMock
75
+ ]
76
+ );
49
77
}
50
78
51
79
/**
@@ -56,21 +84,21 @@ public function testInvalidateVarnish()
56
84
$ tags = ['cache_1 ' , 'cache_group ' ];
57
85
$ pattern = '((^|,)cache_1(,|$))|((^|,)cache_group(,|$)) ' ;
58
86
59
- $ this ->configMock ->expects ($ this ->once ())->method ('isEnabled ' )->will ( $ this -> returnValue ( true ) );
87
+ $ this ->configMock ->expects ($ this ->once ())->method ('isEnabled ' )->willReturn ( true );
60
88
$ this ->configMock ->expects (
61
89
$ this ->once ()
62
90
)->method (
63
91
'getType '
64
- )->will (
65
- $ this -> returnValue (\ Magento \ PageCache \ Model \ Config::VARNISH )
92
+ )->willReturn (
93
+ Config::VARNISH
66
94
);
67
95
68
- $ eventMock = $ this ->createPartialMock (\ Magento \ Framework \ Event::class, ['getObject ' ]);
69
- $ eventMock ->expects ($ this ->once ())->method ('getObject ' )->will ($ this ->returnValue ( $ this -> observerObject ) );
70
- $ this ->observerMock ->expects ($ this ->once ())->method ('getEvent ' )->will ( $ this -> returnValue ( $ eventMock) );
71
- $ this ->tagResolver ->expects ($ this ->once ())->method ('getTags ' )->with ($ this ->observerObject )
72
- ->will ( $ this -> returnValue ( $ tags) );
73
- $ this ->purgeCache ->expects ($ this ->once ())->method ('sendPurgeRequest ' )->with ($ pattern );
96
+ $ eventMock = $ this ->createPartialMock (Event::class, ['getObject ' ]);
97
+ $ eventMock ->expects ($ this ->once ())->method ('getObject ' )->willReturn ($ this ->observerObject );
98
+ $ this ->observerMock ->expects ($ this ->once ())->method ('getEvent ' )->willReturn ( $ eventMock );
99
+ $ this ->tagResolverMock ->expects ($ this ->once ())->method ('getTags ' )->with ($ this ->observerObject )
100
+ ->willReturn ( $ tags );
101
+ $ this ->purgeCacheMock ->expects ($ this ->once ())->method ('sendPurgeRequest ' )->with ($ pattern );
74
102
75
103
$ this ->model ->execute ($ this ->observerMock );
76
104
}
0 commit comments