Skip to content

Commit

Permalink
Improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed Oct 7, 2024
1 parent 3bc2831 commit 0e065ed
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/Schema/Column/ArrayColumnSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ public function phpTypecast(mixed $value): array|null
return null;
}

if ($this->getType() === ColumnType::STRING) {
$column = $this->getColumn();

if ($column->getType() === ColumnType::STRING) {
return $value;
}

$column = $this->getColumn();

if ($this->dimension === 1 && $column->getType() !== ColumnType::JSON) {
return array_map($column->phpTypecast(...), $value);
}
Expand Down
6 changes: 2 additions & 4 deletions src/Schema/Column/StructuredColumnSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,12 @@ public function phpTypecast(mixed $value): array|null
$value = $this->getParser()->parse($value);
}

if (!is_iterable($value)) {
if (!is_array($value)) {
return null;
}

if (empty($this->columns)) {
return $value instanceof Traversable
? iterator_to_array($value)
: $value;
return $value;
}

$fields = [];
Expand Down
2 changes: 2 additions & 0 deletions tests/Db/Schema/ColumnSchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Yiisoft\Db\Tests\Db\Schema;

use ArrayIterator;
use PHPUnit\Framework\TestCase;
use Yiisoft\Db\Constraint\ForeignKeyConstraint;
use Yiisoft\Db\Exception\NotSupportedException;
Expand Down Expand Up @@ -357,6 +358,7 @@ public function testArrayColumnDbTypecastSimple()

$this->assertNull($arrayCol->dbTypecast(null));
$this->assertEquals(new ArrayExpression([]), $arrayCol->dbTypecast(''));
$this->assertEquals(new ArrayExpression([1, 2, 3]), $arrayCol->dbTypecast(new ArrayIterator([1, 2, 3])));
$this->assertSame($expression = new Expression('expression'), $arrayCol->dbTypecast($expression));
}

Expand Down

0 comments on commit 0e065ed

Please sign in to comment.