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