I am using laravel 4 and creating a class under my own namespace. Inside this class there is a method that retrieves data and caches it. I also wrote a very small unit test to check if caching works. For some reason, caching does not work with unit testing, but it works when accessed through a browser. I even modified the driver app/config/testing/cache.phpto use apc instead of an array, and it still doesn't work.
Here is the code:
<?php namespace site;
use Cache;
class UserController {
public function testCaching( )
{
Cache::put('test', 'testing', 1);
if (Cache::has('test')) die("YES: " . Cache::get('test')); die("NO");
}
}
File routes.php(works via browser, result: "YES testing"):
Route::get('test-caching', 'site\UserController@register');
Test (does not work with phpunit, result: "NO"):
<?php namespace site;
use Illuminate\Foundation\Testing\TestCase;
class SiteTest extends TestCase {
public function it_caches_vendor_token()
{
$user = new UserController();
$user->testCaching();
}
}
Has anyone else experienced this issue? Any solutions?