File tree Expand file tree Collapse file tree 2 files changed +33
-2
lines changed
Expand file tree Collapse file tree 2 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -45,4 +45,22 @@ public static function createRuntime()
4545 default : return new CompilerRuntime ($ compileDir );
4646 }
4747 }
48+
49+ /**
50+ * Delete all previously compiled JMESPath files from the JP_COMPILE_DIR
51+ * directory or sys_get_temp_dir().
52+ *
53+ * @return int Returns the number of deleted files.
54+ */
55+ public static function cleanCompileDir ()
56+ {
57+ $ total = 0 ;
58+ $ compileDir = getenv (self ::COMPILE_DIR ) ?: sys_get_temp_dir ();
59+ foreach (glob ("{$ compileDir }/jmespath_*.php " ) as $ file ) {
60+ $ total ++;
61+ unlink ($ file );
62+ }
63+
64+ return $ total ;
65+ }
4866}
Original file line number Diff line number Diff line change 11<?php
22namespace JmesPath \Tests ;
33
4+ use JmesPath \Env ;
5+ use JmesPath \CompilerRuntime ;
6+
47class EnvTest extends \PHPUnit_Framework_TestCase
58{
69 public function testSearchesInput ()
710 {
811 $ data = array ('foo ' => 123 );
9- $ this ->assertEquals (123 , \ JmesPath \ Env::search ('foo ' , $ data ));
10- $ this ->assertEquals (123 , \ JmesPath \ Env::search ('foo ' , $ data ));
12+ $ this ->assertEquals (123 , Env::search ('foo ' , $ data ));
13+ $ this ->assertEquals (123 , Env::search ('foo ' , $ data ));
1114 }
1215
1316 public function testSearchesWithFunction ()
1417 {
1518 $ data = array ('foo ' => 123 );
1619 $ this ->assertEquals (123 , \JmesPath \search ('foo ' , $ data ));
1720 }
21+
22+ public function testCleansCompileDir ()
23+ {
24+ $ dir = sys_get_temp_dir ();
25+ $ runtime = new CompilerRuntime ($ dir );
26+ $ runtime ('@ ' , []);
27+ $ this ->assertNotEmpty (glob ($ dir . '/jmespath_*.php ' ));
28+ $ this ->assertGreaterThan (0 , Env::cleanCompileDir ());
29+ $ this ->assertEmpty (glob ($ dir . '/jmespath_*.php ' ));
30+ }
1831}
You can’t perform that action at this time.
0 commit comments