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