Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix strict types in App::getTag() #1541

Merged
merged 13 commits into from
Dec 13, 2020
6 changes: 5 additions & 1 deletion src/Persistence/Ui.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class Ui extends \Atk4\Data\Persistence

/**
* This method contains the logic of casting generic values into user-friendly format.
*
* @return string|string[]
*/
public function _typecastSaveField(\Atk4\Data\Field $f, $value)
{
Expand Down Expand Up @@ -103,7 +105,9 @@ public function _typecastSaveField(\Atk4\Data\Field $f, $value)
break;
}

return $value;
return is_array($value)
? array_map(function ($v) { return (string) $v; }, $value)
: (string) $value;
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public function setSource(array $data, $fields = null)
{
$this->setModel(new Model(new Static_($data)), $fields);
$this->model->getField($this->model->id_field)->type = null; // TODO probably unwanted
$this->model->getField($this->model->id_field)->required = false; // TODO probably unwanted

return $this->model;
}
Expand Down
32 changes: 22 additions & 10 deletions tests/DemosTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,29 +237,41 @@ public function demoFilesProvider(): array
$excludeDirs = ['_demo-data', '_includes', '_unit-test', 'special'];
$excludeFiles = ['layout/layouts_error.php'];

// these tests require SessionTrait, more precisely session_start() which we do not support in non-HTTP testing
if (static::class === self::class) {
$excludeFiles[] = 'collection/tablefilter.php';
$excludeFiles[] = 'interactive/popup.php';
}

$files = [];
$files[] = ['index.php'];
$files[] = 'index.php';
foreach (array_diff(scandir(static::DEMOS_DIR), ['.', '..'], $excludeDirs) as $dir) {
if (!is_dir(static::DEMOS_DIR . '/' . $dir)) {
continue;
}

foreach (scandir(static::DEMOS_DIR . '/' . $dir) as $f) {
if (substr($f, -4) !== '.php' || in_array($dir . '/' . $f, $excludeFiles, true)) {
$path = $dir . '/' . $f;
if (substr($path, -4) !== '.php' || in_array($path, $excludeFiles, true)) {
continue;
}

$files[] = [$dir . '/' . $f];
$files[] = $path;
}
}

return $files;
// these tests require SessionTrait, more precisely session_start() which we do not support in non-HTTP testing
// always move these tests to the end, so data provider # stays same as much as possible across tests for fast skip
$httpOnlyFiles = ['collection/tablefilter.php', 'interactive/popup.php'];
foreach ($files as $k => $path) {
if (in_array($path, $httpOnlyFiles, true)) {
unset($files[$k]);
$files[] = $path;
}
}
if (static::class === self::class) {
foreach ($files as $k => $path) {
if (in_array($path, $httpOnlyFiles, true)) {
unset($files[$k]);
}
}
}

return array_map(function (string $v) { return [$v]; }, $files);
}

/**
Expand Down