Should fix tests.

This commit is contained in:
James Cole
2015-06-03 21:15:52 +02:00
parent a7f6848e53
commit 409ec2e086
21 changed files with 151 additions and 132 deletions

View File

@@ -4,6 +4,7 @@ namespace FireflyIII\Support;
use Auth;
use Cache;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
use Illuminate\Support\Collection;
@@ -17,6 +18,8 @@ use Preferences as Prefs;
class CacheProperties
{
/** @var string */
protected $md5 = '';
/** @var Collection */
protected $properties;
@@ -38,39 +41,62 @@ class CacheProperties
$this->properties->push($property);
}
/**
* @return mixed
*/
public function get()
{
return Cache::get($this->md5);
}
/**
* @return string
*/
public function md5()
public function getMd5()
{
return $this->md5;
}
/**
* @return bool
*/
public function has()
{
$this->md5();
return Cache::has($this->md5);
}
/**
* @return void
*/
private function md5()
{
$string = '';
//Log::debug('--- building string ---');
foreach ($this->properties as $property) {
if ($property instanceof Collection || $property instanceof EloquentCollection) {
$string .= print_r($property->toArray(), true);
$this->md5 .= print_r($property->toArray(), true);
continue;
}
if ($property instanceof Carbon) {
$string .= $property->toRfc3339String();
$this->md5 .= $property->toRfc3339String();
continue;
}
if (is_array($property)) {
$string .= print_r($property, true);
$this->md5 .= print_r($property, true);
continue;
}
if (is_object($property)) {
$string .= $property->__toString();
$this->md5 .= $property->__toString();
}
if (is_array($property)) {
$string .= print_r($property, true);
$this->md5 .= print_r($property, true);
}
$string .= (string)$property;
$this->md5 .= (string)$property;
}
return md5($string);
$this->md5 = md5($this->md5);
}
}

View File

@@ -30,10 +30,10 @@ class Steam
$properties->addProperty('balance');
$properties->addProperty($date);
$properties->addProperty($ignoreVirtualBalance);
$md5 = $properties->md5();
if (Cache::has($md5)) {
return Cache::get($md5);
if ($properties->has()) {
return $properties->get();
}
$md5 = $properties->getMd5();
// find the first known transaction on this account:

View File

@@ -33,10 +33,10 @@ class Journal extends Twig_Extension
$prop = new CacheProperties();
$prop->addProperty($journal->id);
$prop->addProperty('typeIcon');
$md5 = $prop->md5();
if (Cache::has($md5)) {
return Cache::get($md5);
if ($prop->has()) {
return $prop->get();
}
$md5 = $prop->getMd5();
$type = $journal->transactionType->type;