Unittest laravel cache issue

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 {
    /** @test */
    public function it_caches_vendor_token()
    {   
        $user = new UserController();
        $user->testCaching();
    }
}

Has anyone else experienced this issue? Any solutions?

+4
1

Cache, ...

, . , (Cache, Eloquent, Log ..). , TestCase ,

use Illuminate\Foundation\Testing\TestCase as BaseCase;

class TestCase extends BaseCase
{
    /**
     * The base URL to use while testing the application.
     *
     * @var string
     */
     protected $baseUrl = 'http://localhost.dev';

     /**
     * Creates the application.
     *
     * @return \Illuminate\Foundation\Application
     */
     public function createApplication()
     {
         $app = include __DIR__.'/../bootstrap/app.php';

         $app->make(\Illuminate\Contracts\Console\Kernel::class)->bootstrap();

         return $app;
     }
}

:

class MyBrandNewTest extends TestCase {

    public function setUp()
    {
        parent::setUp();
    }
}

parent:: setUp() setUp BaseTest, .

0

All Articles