I am using laravel 4 and created a class under its own namespace. Within this class there's 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 when unit testing, but does work when accessing through browser. I even modified app/config/testing/cache.php
driver to use apc instead of array and it still doesn't work.
Here's 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");
}
}
The routes.php
file (works through browser, result: 'YES testing'):
Route::get('test-caching', 'site\UserController@register');
The test (does not work with phpunit, result: 'NO'):
<?php namespace site;
use Illuminate\Foundation\Testing\TestCase;
class SiteTest extends TestCase {
/** @test */
public function it_caches_vendor_token()
{
$user = new UserController();
$user->testCaching();
}
}
Did anyone else experience this problem? Any solutions?