Skip to content

Commit

Permalink
Merge c73d245 into 1b91945
Browse files Browse the repository at this point in the history
  • Loading branch information
homersimpsons committed Jan 16, 2020
2 parents 1b91945 + c73d245 commit 4ff84f7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
13 changes: 12 additions & 1 deletion src/Utils/BeanDescriptor.php
Expand Up @@ -8,6 +8,7 @@
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
use Doctrine\DBAL\Types\Type;
use JsonSerializable;
use Mouf\Database\SchemaAnalyzer\SchemaAnalyzer;
use PhpParser\Comment\Doc;
Expand Down Expand Up @@ -1291,7 +1292,17 @@ private function generateFindByDaoCodeForIndex(Index $index, string $beanNamespa
foreach ($elements as $element) {
$params[] = $element->getParamAnnotation();
if ($element instanceof ScalarBeanPropertyDescriptor) {
$filterArrayCode .= ' '.var_export($element->getColumnName(), true).' => '.$element->getVariableName().",\n";
$typeName = $element->getDatabaseType()->getName();
if ($typeName === Type::DATETIME_IMMUTABLE) {
$filterArrayCode .= sprintf(
" %s => \$this->tdbmService->getConnection()->convertToDatabaseValue(%s,%s),\n",
var_export($element->getColumnName(), true),
$element->getVariableName(),
var_export($typeName, true)
);
} else {
$filterArrayCode .= ' '.var_export($element->getColumnName(), true).' => '.$element->getVariableName().",\n";
}
} elseif ($element instanceof ObjectBeanPropertyDescriptor) {
$foreignKey = $element->getForeignKey();
$columns = SafeFunctions::arrayCombine($foreignKey->getLocalColumns(), $foreignKey->getForeignColumns());
Expand Down
10 changes: 10 additions & 0 deletions src/Utils/ScalarBeanPropertyDescriptor.php
Expand Up @@ -73,6 +73,16 @@ public function getPhpType(): string
return TDBMDaoGenerator::dbalTypeToPhpType($type);
}

/**
* Returns the Database type for the property
*
* @return Type
*/
public function getDatabaseType(): Type
{
return $this->column->getType();
}

/**
* Returns true if the property is compulsory (and therefore should be fetched in the constructor).
*
Expand Down
2 changes: 1 addition & 1 deletion tests/TDBMAbstractServiceTest.php
Expand Up @@ -266,7 +266,7 @@ private static function initSchema(Connection $connection): void
}

$db->table('person')
->column('modified_at')->datetime()->null()
->column('modified_at')->datetime()->null()->index()
->column('order')->integer()->null();


Expand Down
13 changes: 11 additions & 2 deletions tests/TDBMDaoGeneratorTest.php
Expand Up @@ -76,6 +76,7 @@
use TheCodingMachine\TDBM\Test\Dao\Generated\UserBaseDao;
use TheCodingMachine\TDBM\Test\Dao\InheritedObjectDao;
use TheCodingMachine\TDBM\Test\Dao\NodeDao;
use TheCodingMachine\TDBM\Test\Dao\PersonDao;
use TheCodingMachine\TDBM\Test\Dao\RefNoPrimKeyDao;
use TheCodingMachine\TDBM\Test\Dao\RoleDao;
use TheCodingMachine\TDBM\Test\Dao\StateDao;
Expand Down Expand Up @@ -747,8 +748,9 @@ public function testFindFromRawSqlOrderByUserCount(): void
$countryDao = new TestCountryDao($this->tdbmService);
$countries = $countryDao->getCountriesByUserCount();

$this->assertCount(4, $countries);
for ($i = 1; $i < count($countries); $i++) {
$nbCountries = 4;
$this->assertCount($nbCountries, $countries);
for ($i = 1; $i < $nbCountries; $i++) {
$this->assertLessThanOrEqual($countries[$i - 1]->getUsers()->count(), $countries[$i]->getUsers()->count());
}
}
Expand Down Expand Up @@ -2169,4 +2171,11 @@ public function testMethodNameConflictsBetweenRegularAndAutoPivotProperties()
$artist->getChildrenByArtistsRelations(); // auto-pivot relationship
$this->assertEquals(1, 1);
}

public function testFindByDateTime(): void
{
$personDao = new PersonDao($this->tdbmService);
$personDao->findByModifiedAt(new \DateTimeImmutable())->count();
$this->assertTrue(true);
}
}

0 comments on commit 4ff84f7

Please sign in to comment.