Skip to content

Commit

Permalink
Merge pull request #1696 from propelorm/pr-1470
Browse files Browse the repository at this point in the history
Use temporal formatter in the toArray() generator
  • Loading branch information
dereuromark authored Jan 14, 2021
2 parents 09dfb2f + 1515de1 commit 91a1478
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 15 deletions.
6 changes: 1 addition & 5 deletions UPDATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,4 @@

## Propel Update Information

Any and all update information pertaining to `Propel` is now available on the
project website. Please reference the link below for details about updates,
new features, and backwards incompatabilities.

[**Propel Update Information**](http://propelorm.org/documentation/whats-new.html)
[**Propel Update Information**](https://github.com/propelorm/Propel2/releases)
3 changes: 1 addition & 2 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,7 @@
</NullArgument>
</file>
<file src="src/Propel/Runtime/ActiveQuery/ModelCriteria.php">
<UndefinedClass occurrences="2">
<code>$tableMap::addSelectColumns($this, $this-&gt;useAliasInSQL ? $this-&gt;modelAlias : null)</code>
<UndefinedClass occurrences="1">
<code>new $secondaryCriteriaClass()</code>
</UndefinedClass>
<UndefinedMethod occurrences="10">
Expand Down
2 changes: 1 addition & 1 deletion src/Propel/Generator/Builder/Om/ObjectBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3004,7 +3004,7 @@ public function toArray(\$keyType = TableMap::$defaultKeyType, \$includeLazyLoad
if ($col->isTemporalType()) {
$script .= "
if (\$result[\$keys[$num]] instanceof \DateTimeInterface) {
\$result[\$keys[$num]] = \$result[\$keys[$num]]->format('c');
\$result[\$keys[$num]] = \$result[\$keys[$num]]->format('" . $this->getTemporalFormatter($col) . "');
}
";
}
Expand Down
2 changes: 2 additions & 0 deletions src/Propel/Runtime/ActiveQuery/ModelCriteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,7 @@ public function addSelfSelectColumns($force = false)
return $this;
}

/** @var string $tableMap */
$tableMap = $this->modelTableMapName;
$tableMap::addSelectColumns($this, $this->useAliasInSQL ? $this->modelAlias : null);
$this->isSelfSelected = true;
Expand All @@ -973,6 +974,7 @@ public function removeSelfSelectColumns($force = false)
return $this;
}

/** @var string $tableMap */
$tableMap = $this->modelTableMapName;
$tableMap::removeSelectColumns($this, $this->useAliasInSQL ? $this->modelAlias : null);
$this->isSelfSelected = false;
Expand Down
11 changes: 10 additions & 1 deletion tests/Propel/Tests/Generator/Builder/Om/GeneratedObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Exception;
use MyNameSpace\TestKeyTypeTable;
use Propel\Generator\Config\QuickGeneratorConfig;
use Propel\Tests\Bookstore\BookClubList;
use Propel\Generator\Util\QuickBuilder;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\Adapter\Pdo\SqliteAdapter;
Expand Down Expand Up @@ -816,7 +817,15 @@ public function testToArrayDateTimeAsString()
$review = new Review();
$review->setReviewDate($date);

$this->assertEquals('2015-01-04T16:00:02+00:00', $review->toArray()['ReviewDate'], 'toArray() format temporal colums as ISO8601');
$bookstore = new Bookstore();
$bookstore->setStoreOpenTime($date);

$bookClubList = new BookClubList();
$bookClubList->setCreatedAt($date);

$this->assertEquals('2015-01-04', $review->toArray()['ReviewDate'], 'toArray() format colums of type DATE as Y-m-d');
$this->assertEquals('16:00:02.000000', $bookstore->toArray()['StoreOpenTime'], 'toArray() format toArray() colums of type TIME as H:i:s.u');
$this->assertEquals('2015-01-04 16:00:02.000000', $bookClubList->toArray()['CreatedAt'], 'toArray() format toArray() colums of type TIMESTAMP as Y-m-d H:i:s.u');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ public function testWithDateTimeToArrayWorks()

$ModelA = new SomeTableA();
$ModelA->setCreatedAt(clone $Date);
$this->assertSame(['Id' => null, 'CreatedAt' => $Date->format('c')], $ModelA->toArray());
$this->assertSame(['Id' => null, 'CreatedAt' => $Date->format('Y-m-d H:i:s.u')], $ModelA->toArray());

$ModelB = new SomeTableB();
$ModelB->setCreatedAt(clone $Date);
$this->assertSame(['Id' => null, 'CreatedAt' => $Date->format('c')], $ModelB->toArray());
$this->assertSame(['Id' => null, 'CreatedAt' => $Date->format('Y-m-d H:i:s.u')], $ModelB->toArray());
}
}
8 changes: 4 additions & 4 deletions tests/Propel/Tests/Issues/Issue1420Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
class Issue1420Test extends TestCase
{
protected function setUp()
protected function setUp(): void
{
parent::setUp();
if (!class_exists('\Table1420A')) {
Expand All @@ -34,7 +34,7 @@ protected function setUp()
<column name="id" primaryKey="true" type="INTEGER" />
<column name="table_1420_a_id" type="INTEGER" />
<column name="b_field" type="VARCHAR" size="10" />
<foreign-key foreignTable="table_1420_a" name="table_1420_b_fk1">
<reference local="table_1420_a_id" foreign="id"/>
</foreign-key>
Expand All @@ -43,7 +43,7 @@ protected function setUp()
<column name="id" primaryKey="true" type="INTEGER" />
<column name="table_1420_a_id" type="INTEGER" />
<column name="c_field" type="VARCHAR" size="10" />
<foreign-key foreignTable="table_1420_a" name="table_1420_c_fk1">
<reference local="table_1420_a_id" foreign="id"/>
</foreign-key>
Expand All @@ -54,7 +54,7 @@ protected function setUp()
}
}

protected function tearDown()
protected function tearDown(): void
{
parent::tearDown();
\Table1420CQuery::create()->deleteAll();
Expand Down

0 comments on commit 91a1478

Please sign in to comment.