Skip to content

Commit 94181b0

Browse files
committed
Adding the ability to clean out the compile dir
1 parent 05ffe8e commit 94181b0

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/Env.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

tests/EnvTest.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,31 @@
11
<?php
22
namespace JmesPath\Tests;
33

4+
use JmesPath\Env;
5+
use JmesPath\CompilerRuntime;
6+
47
class 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
}

0 commit comments

Comments
 (0)