9
9
10
10
namespace OxidEsales \EshopCommunity \Tests \Integration \Internal \Framework \Templating \Cache ;
11
11
12
+ use OxidEsales \EshopCommunity \Internal \Framework \Templating \Cache \ShopTemplateCacheServiceInterface ;
12
13
use OxidEsales \EshopCommunity \Internal \Framework \Templating \Cache \TemplateCacheServiceInterface ;
13
- use OxidEsales \EshopCommunity \Internal \Transition \Utility \BasicContextInterface ;
14
+ use OxidEsales \EshopCommunity \Internal \Transition \Utility \ContextInterface ;
14
15
use OxidEsales \EshopCommunity \Tests \ContainerTrait ;
15
16
use PHPUnit \Framework \TestCase ;
16
17
use Symfony \Component \Filesystem \Filesystem ;
@@ -20,13 +21,13 @@ final class TemplateCacheServiceTest extends TestCase
20
21
{
21
22
use ContainerTrait;
22
23
23
- private string $ templateCachePath ;
24
+ private array $ shopsID ;
24
25
private Filesystem $ filesystem ;
25
26
26
27
protected function setUp (): void
27
28
{
28
29
$ this ->filesystem = new Filesystem ();
29
- $ this ->templateCachePath = $ this ->get (BasicContextInterface ::class)->getTemplateCacheDirectory ();
30
+ $ this ->shopsID = $ this ->get (ContextInterface ::class)->getAllShopIds ();
30
31
31
32
$ this ->clearTemplateCache ();
32
33
$ this ->populateTemplateCache ();
@@ -36,34 +37,48 @@ protected function setUp(): void
36
37
37
38
public function testInvalidateTemplateCache (): void
38
39
{
39
- $ this ->assertNotCount (0 , \glob ( $ this ->selectAllCacheFiles () ));
40
+ $ this ->assertNotEquals (0 , $ this ->countCacheFiles ( ));
40
41
41
42
$ this ->get (TemplateCacheServiceInterface::class)->invalidateTemplateCache ();
42
43
43
- self ::assertCount (0 , \glob ( $ this ->selectAllCacheFiles () ));
44
+ self ::assertEquals (0 , $ this ->countCacheFiles ( ));
44
45
}
45
46
46
47
private function clearTemplateCache (): void
47
48
{
48
- $ this ->filesystem ->remove ($ this ->selectAllCacheFiles ());
49
+ foreach ($ this ->shopsID as $ shopID ) {
50
+ $ this ->filesystem ->remove (
51
+ $ this ->get (ShopTemplateCacheServiceInterface::class)
52
+ ->getShopTemplateCacheDirectory ($ shopID )
53
+ );
54
+ }
49
55
}
50
56
51
- private function selectAllCacheFiles (): string
57
+ private function countCacheFiles (): int
52
58
{
53
- return "$ this ->templateCachePath /* " ;
59
+ $ files = 0 ;
60
+ foreach ($ this ->shopsID as $ shopID ) {
61
+ $ files += count (\glob ($ this ->get (ShopTemplateCacheServiceInterface::class)
62
+ ->getShopTemplateCacheDirectory ($ shopID )));
63
+ }
64
+ return $ files ;
54
65
}
55
66
56
67
private function populateTemplateCache (): void
57
68
{
58
69
$ numberOfTestFiles = 3 ;
59
- $ this ->filesystem ->mkdir ($ this ->templateCachePath );
60
- for ($ i = 0 ; $ i < $ numberOfTestFiles ; $ i ++) {
61
- $ this ->filesystem ->touch (
62
- Path::join (
63
- $ this ->templateCachePath ,
64
- uniqid ('template-file- ' , true )
65
- )
66
- );
70
+ foreach ($ this ->shopsID as $ shopID ) {
71
+ $ templateCachePath = $ this ->get (ShopTemplateCacheServiceInterface::class)
72
+ ->getShopTemplateCacheDirectory ($ shopID );
73
+ $ this ->filesystem ->mkdir ($ templateCachePath );
74
+ for ($ i = 0 ; $ i < $ numberOfTestFiles ; $ i ++) {
75
+ $ this ->filesystem ->touch (
76
+ Path::join (
77
+ $ templateCachePath ,
78
+ uniqid ('template-file- ' . $ shopID , true )
79
+ )
80
+ );
81
+ }
67
82
}
68
83
}
69
84
}
0 commit comments