Skip to content

Commit

Permalink
Merge pull request #45 from flofloflo/hotfix/laravel54-app-share
Browse files Browse the repository at this point in the history
Fixed Tests for initial support for Laravel 5.4 (#44)
  • Loading branch information
spiritix authored Jul 20, 2017
2 parents 4610fe6 + a1cf7e0 commit d957f1c
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 22 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"phpunit/phpunit": "~5.0",
"codeclimate/php-test-reporter": "dev-master",
"orchestra/testbench": "~3.0",
"laracasts/TestDummy": "~2.3"
"laracasts/TestDummy": "~2.3",
"orchestra/database": "~3.1"
},
"suggest": {
"ext-phpiredis": "Allows faster serialization and deserialization of the Redis protocol",
Expand Down
8 changes: 4 additions & 4 deletions src/Spiritix/LadaCache/LadaCacheServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function provides()
private function registerSingletons()
{
$this->app->singleton('lada.redis', function($app) {
return new Redis(config('lada-cache.prefix'));
return new Redis();
});

$this->app->singleton('lada.cache', function($app) {
Expand Down Expand Up @@ -135,15 +135,15 @@ private function registerConnections()
*/
private function registerCommand()
{
$this->app['command.lada-cache.flush'] = $this->app->share(function() {
$this->app->singleton('command.lada-cache.flush', function() {
return new FlushCommand();
});

$this->app['command.lada-cache.enable'] = $this->app->share(function() {
$this->app->singleton('command.lada-cache.enable', function() {
return new EnableCommand();
});

$this->app['command.lada-cache.disable'] = $this->app->share(function() {
$this->app->singleton('command.lada-cache.disable', function() {
return new DisableCommand();
});

Expand Down
12 changes: 6 additions & 6 deletions src/Spiritix/LadaCache/QueryHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,21 @@ public function cacheQuery($queryClosure)
$this->constructCollector();

/* @var Reflector $reflector */
$reflector = app()->make(Reflector::class, [$this->builder]);
$reflector = new Reflector($this->builder);

/* @var Manager $manager */
$manager = app()->make(Manager::class, [$reflector]);
$manager = new Manager($reflector);

// If cache is disabled, abort already here to save time
if (!$manager->shouldCache()) {
return $queryClosure();
}

/* @var Hasher $hasher */
$hasher = app()->make(Hasher::class, [$reflector]);
$hasher = new Hasher($reflector);

/* @var Tagger $tagger */
$tagger = app()->make(Tagger::class, [$reflector]);
$tagger = new Tagger($reflector);

$result = null;
$key = $hasher->getHash();
Expand Down Expand Up @@ -138,10 +138,10 @@ public function invalidateQuery($statementType, $values = [])
$this->constructCollector();

/* @var Reflector $reflector */
$reflector = app()->make(Reflector::class, [$this->builder, $statementType, $values]);
$reflector = new Reflector($this->builder, $statementType, $values);

/* @var Tagger $tagger */
$tagger = app()->make(Tagger::class, [$reflector]);
$tagger = new Tagger($reflector);

$hashes = $this->invalidator->invalidate($tagger->getTags());

Expand Down
5 changes: 2 additions & 3 deletions src/Spiritix/LadaCache/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ class Redis
/**
* Initialize Redis handler.
*
* @param string $prefix
*/
public function __construct($prefix)
public function __construct()
{
$this->prefix = (string) $prefix;
$this->prefix = config('lada-cache.prefix');
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ public function testTruncate()
private function hasQuery(QueryBuilder $builder)
{
/* @var Reflector $reflector */
$reflector = app()->make(Reflector::class, [$builder]);
$reflector = new Reflector($builder);

/* @var Hasher $hasher */
$hasher = app()->make(Hasher::class, [$reflector]);
$hasher = new Hasher($reflector);

return $this->cache->has($hasher->getHash());
}
Expand Down
3 changes: 2 additions & 1 deletion tests/RedisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public function setUp()
{
parent::setUp();

$this->redis = new Redis('prefix:');
$this->redis = new Redis();
$this->redis->prefix = 'prefix:';
}

public function testPrefix()
Expand Down
4 changes: 2 additions & 2 deletions tests/TaggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -611,10 +611,10 @@ private function getRowTag($table, $rowId)
private function getTags($tableBuilder, $sqlOperation = Reflector::QUERY_TYPE_SELECT, $values = [])
{
/** @var Reflector $reflector */
$reflector = app(Reflector::class, [$tableBuilder->getQuery(), $sqlOperation, $values]);
$reflector = new Reflector($tableBuilder->getQuery(), $sqlOperation, $values);

/** @var Tagger $tagger */
$tagger = app(Tagger::class, [$reflector]);
$tagger = new Tagger($reflector);

return $tagger->getTags();
}
Expand Down
10 changes: 7 additions & 3 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Support\Facades\DB;
use Laracasts\TestDummy\Factory;
use Spiritix\LadaCache\LadaCacheServiceProvider;
use Orchestra\Database\ConsoleServiceProvider;

class TestCase extends \Orchestra\Testbench\TestCase
{
Expand All @@ -14,9 +15,9 @@ public function setUp()
{
parent::setUp();

$this->artisan('migrate', [
$this->loadMigrationsFrom([
'--database' => 'testing',
'--realpath' => realpath(__DIR__ . '/../database/migrations'),
'--realpath' => realpath(__DIR__.'/../database/migrations'),
]);

$this->factory = new Factory(__DIR__ . '/../database/factories');
Expand All @@ -33,7 +34,10 @@ public function tearDown()

protected function getPackageProviders($app)
{
return [LadaCacheServiceProvider::class];
return [
LadaCacheServiceProvider::class,
ConsoleServiceProvider::class
];
}

protected function getEnvironmentSetUp($app)
Expand Down

0 comments on commit d957f1c

Please sign in to comment.