mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
@@ -74,7 +74,7 @@ trait HasCellState
|
||||
return $this->evaluate($this->defaultState);
|
||||
}
|
||||
|
||||
public function getState(bool $isCached = true): mixed
|
||||
public function getState(): mixed
|
||||
{
|
||||
$record = $this->getRecord();
|
||||
|
||||
@@ -84,7 +84,7 @@ trait HasCellState
|
||||
|
||||
$recordKey = (string) $record->getKey();
|
||||
|
||||
if ($isCached && array_key_exists($recordKey, $this->cachedState)) {
|
||||
if (array_key_exists($recordKey, $this->cachedState)) {
|
||||
return $this->cachedState[$recordKey];
|
||||
}
|
||||
|
||||
@@ -103,10 +103,6 @@ trait HasCellState
|
||||
$state = $this->getDefaultState();
|
||||
}
|
||||
|
||||
if (! $isCached) {
|
||||
return $state;
|
||||
}
|
||||
|
||||
return $this->cachedState[$recordKey] = $state;
|
||||
}
|
||||
|
||||
@@ -146,6 +142,17 @@ trait HasCellState
|
||||
return $state->all();
|
||||
}
|
||||
|
||||
public function clearCache(): static
|
||||
{
|
||||
if (! app()->isRunningUnitTests()) {
|
||||
throw new Exception('Clearing cache is only available in unit tests.');
|
||||
}
|
||||
|
||||
$this->cachedState = [];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function separator(string | Closure | null $separator = ','): static
|
||||
{
|
||||
$this->separator = $separator;
|
||||
|
||||
@@ -180,7 +180,9 @@ class TestsColumns
|
||||
|
||||
$livewireClass = $this->instance()::class;
|
||||
|
||||
$state = $column->getState(isCached: false);
|
||||
$column->clearCache();
|
||||
|
||||
$state = $column->getState();
|
||||
|
||||
if (is_array($state)) {
|
||||
$state = json_encode($state);
|
||||
@@ -216,7 +218,9 @@ class TestsColumns
|
||||
|
||||
$livewireClass = $this->instance()::class;
|
||||
|
||||
$state = $column->getState(isCached: false);
|
||||
$column->clearCache();
|
||||
|
||||
$state = $column->getState();
|
||||
|
||||
if (is_array($state)) {
|
||||
$state = json_encode($state);
|
||||
@@ -252,9 +256,11 @@ class TestsColumns
|
||||
|
||||
$livewireClass = $this->instance()::class;
|
||||
|
||||
$column->clearCache();
|
||||
|
||||
Assert::assertEquals(
|
||||
$value,
|
||||
$column->formatState($column->getState(isCached: false)),
|
||||
$column->formatState($column->getState()),
|
||||
message: "Failed asserting that a table column with name [{$name}] has a formatted state of [{$value}] for record [{$record->getKey()}] on the [{$livewireClass}] component.",
|
||||
);
|
||||
|
||||
@@ -279,8 +285,10 @@ class TestsColumns
|
||||
|
||||
$livewireClass = $this->instance()::class;
|
||||
|
||||
$column->clearCache();
|
||||
|
||||
Assert::assertFalse(
|
||||
$column->formatState($column->getState(isCached: false)) == $value,
|
||||
$column->formatState($column->getState()) == $value,
|
||||
message: "Failed asserting that a table column with name [{$name}] does not have a formatted state of [{$value}] for record [{$record->getKey()}] on the [{$livewireClass}] component.",
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user