Revert "Clean up"

This reverts commit c768180a70.
This commit is contained in:
Dan Harrin
2025-04-07 10:42:48 +01:00
parent 8624b4c660
commit 890f2e765d
2 changed files with 25 additions and 10 deletions
+13 -6
View File
@@ -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;
+12 -4
View File
@@ -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.",
);