@@ -66,6 +66,7 @@ public function testCompileCompilesFileAndReturnsContents()
66
66
$ compiler = new BladeCompiler ($ files = $ this ->getFiles (), __DIR__ );
67
67
$ files ->shouldReceive ('get ' )->once ()->with ('foo ' )->andReturn ('Hello World ' );
68
68
$ files ->shouldReceive ('exists ' )->once ()->with (__DIR__ )->andReturn (true );
69
+ $ files ->shouldReceive ('exists ' )->once ()->with (__DIR__ .'/ ' .hash ('xxh128 ' , 'v2foo ' ).'.php ' )->andReturn (false );
69
70
$ files ->shouldReceive ('put ' )->once ()->with (__DIR__ .'/ ' .hash ('xxh128 ' , 'v2foo ' ).'.php ' , 'Hello World<?php /**PATH foo ENDPATH**/ ?> ' );
70
71
$ compiler ->compile ('foo ' );
71
72
}
@@ -76,15 +77,42 @@ public function testCompileCompilesFileAndReturnsContentsCreatingDirectory()
76
77
$ files ->shouldReceive ('get ' )->once ()->with ('foo ' )->andReturn ('Hello World ' );
77
78
$ files ->shouldReceive ('exists ' )->once ()->with (__DIR__ )->andReturn (false );
78
79
$ files ->shouldReceive ('makeDirectory ' )->once ()->with (__DIR__ , 0777 , true , true );
80
+ $ files ->shouldReceive ('exists ' )->once ()->with (__DIR__ .'/ ' .hash ('xxh128 ' , 'v2foo ' ).'.php ' )->andReturn (false );
79
81
$ files ->shouldReceive ('put ' )->once ()->with (__DIR__ .'/ ' .hash ('xxh128 ' , 'v2foo ' ).'.php ' , 'Hello World<?php /**PATH foo ENDPATH**/ ?> ' );
80
82
$ compiler ->compile ('foo ' );
81
83
}
82
84
85
+ public function testCompileUpdatesCacheIfChanged ()
86
+ {
87
+ $ compiledContent = 'Hello World<?php /**PATH foo ENDPATH**/ ?> ' ;
88
+ $ compiler = new BladeCompiler ($ files = $ this ->getFiles (), __DIR__ );
89
+ $ files ->shouldReceive ('get ' )->once ()->with ('foo ' )->andReturn ('Hello World ' );
90
+ $ files ->shouldReceive ('exists ' )->once ()->with (__DIR__ )->andReturn (false );
91
+ $ files ->shouldReceive ('makeDirectory ' )->once ()->with (__DIR__ , 0777 , true , true );
92
+ $ files ->shouldReceive ('exists ' )->once ()->with ($ compiledPath )->andReturn (true );
93
+ $ files ->shouldReceive ('hash ' )->once ()->with ($ compiledPath , 'sha256 ' )->andReturn (hash ('sha256 ' , 'outdated content ' ));
94
+ $ files ->shouldReceive ('put ' )->once ()->with ($ compiledPath , __DIR__ .'/ ' .hash ('xxh128 ' , 'v2foo ' ).'.php ' );
95
+ $ compiler ->compile ('foo ' );
96
+ }
97
+
98
+ public function testCompileKeepsCacheIfUnchanged ()
99
+ {
100
+ $ compiledPath = __DIR__ .'/ ' .hash ('xxh128 ' , 'v2foo ' ).'.php ' ;
101
+ $ compiler = new BladeCompiler ($ files = $ this ->getFiles (), __DIR__ );
102
+ $ files ->shouldReceive ('get ' )->once ()->with ('foo ' )->andReturn ('Hello World ' );
103
+ $ files ->shouldReceive ('exists ' )->once ()->with (__DIR__ )->andReturn (false );
104
+ $ files ->shouldReceive ('makeDirectory ' )->once ()->with (__DIR__ , 0777 , true , true );
105
+ $ files ->shouldReceive ('exists ' )->once ()->with ($ compiledPath )->andReturn (true );
106
+ $ files ->shouldReceive ('hash ' )->once ()->with ($ compiledPath , 'sha256 ' )->andReturn (hash ('sha256 ' , 'Hello World<?php /**PATH foo ENDPATH**/ ?> ' ));
107
+ $ compiler ->compile ('foo ' );
108
+ }
109
+
83
110
public function testCompileCompilesAndGetThePath ()
84
111
{
85
112
$ compiler = new BladeCompiler ($ files = $ this ->getFiles (), __DIR__ );
86
113
$ files ->shouldReceive ('get ' )->once ()->with ('foo ' )->andReturn ('Hello World ' );
87
114
$ files ->shouldReceive ('exists ' )->once ()->with (__DIR__ )->andReturn (true );
115
+ $ files ->shouldReceive ('exists ' )->once ()->with (__DIR__ .'/ ' .hash ('xxh128 ' , 'v2foo ' ).'.php ' )->andReturn (false );
88
116
$ files ->shouldReceive ('put ' )->once ()->with (__DIR__ .'/ ' .hash ('xxh128 ' , 'v2foo ' ).'.php ' , 'Hello World<?php /**PATH foo ENDPATH**/ ?> ' );
89
117
$ compiler ->compile ('foo ' );
90
118
$ this ->assertSame ('foo ' , $ compiler ->getPath ());
@@ -102,6 +130,7 @@ public function testCompileWithPathSetBefore()
102
130
$ compiler = new BladeCompiler ($ files = $ this ->getFiles (), __DIR__ );
103
131
$ files ->shouldReceive ('get ' )->once ()->with ('foo ' )->andReturn ('Hello World ' );
104
132
$ files ->shouldReceive ('exists ' )->once ()->with (__DIR__ )->andReturn (true );
133
+ $ files ->shouldReceive ('exists ' )->once ()->with (__DIR__ .'/ ' .hash ('xxh128 ' , 'v2foo ' ).'.php ' )->andReturn (false );
105
134
$ files ->shouldReceive ('put ' )->once ()->with (__DIR__ .'/ ' .hash ('xxh128 ' , 'v2foo ' ).'.php ' , 'Hello World<?php /**PATH foo ENDPATH**/ ?> ' );
106
135
// set path before compilation
107
136
$ compiler ->setPath ('foo ' );
@@ -132,6 +161,7 @@ public function testIncludePathToTemplate($content, $compiled)
132
161
$ compiler = new BladeCompiler ($ files = $ this ->getFiles (), __DIR__ );
133
162
$ files ->shouldReceive ('get ' )->once ()->with ('foo ' )->andReturn ($ content );
134
163
$ files ->shouldReceive ('exists ' )->once ()->with (__DIR__ )->andReturn (true );
164
+ $ files ->shouldReceive ('exists ' )->once ()->with (__DIR__ .'/ ' .hash ('xxh128 ' , 'v2foo ' ).'.php ' )->andReturn (false );
135
165
$ files ->shouldReceive ('put ' )->once ()->with (__DIR__ .'/ ' .hash ('xxh128 ' , 'v2foo ' ).'.php ' , $ compiled );
136
166
137
167
$ compiler ->compile ('foo ' );
@@ -187,6 +217,7 @@ public function testDontIncludeEmptyPath()
187
217
$ compiler = new BladeCompiler ($ files = $ this ->getFiles (), __DIR__ );
188
218
$ files ->shouldReceive ('get ' )->once ()->with ('' )->andReturn ('Hello World ' );
189
219
$ files ->shouldReceive ('exists ' )->once ()->with (__DIR__ )->andReturn (true );
220
+ $ files ->shouldReceive ('exists ' )->once ()->with (__DIR__ .'/ ' .hash ('xxh128 ' , 'v2 ' ).'.php ' )->andReturn (false );
190
221
$ files ->shouldReceive ('put ' )->once ()->with (__DIR__ .'/ ' .hash ('xxh128 ' , 'v2 ' ).'.php ' , 'Hello World ' );
191
222
$ compiler ->setPath ('' );
192
223
$ compiler ->compile ();
@@ -197,6 +228,7 @@ public function testDontIncludeNullPath()
197
228
$ compiler = new BladeCompiler ($ files = $ this ->getFiles (), __DIR__ );
198
229
$ files ->shouldReceive ('get ' )->once ()->with (null )->andReturn ('Hello World ' );
199
230
$ files ->shouldReceive ('exists ' )->once ()->with (__DIR__ )->andReturn (true );
231
+ $ files ->shouldReceive ('exists ' )->once ()->with (__DIR__ .'/ ' .hash ('xxh128 ' , 'v2foo ' ).'.php ' )->andReturn (false );
200
232
$ files ->shouldReceive ('put ' )->once ()->with (__DIR__ .'/ ' .hash ('xxh128 ' , 'v2 ' ).'.php ' , 'Hello World ' );
201
233
$ compiler ->setPath (null );
202
234
$ compiler ->compile ();
0 commit comments