Skip to content

Commit 6c56e6a

Browse files
committed
created a unit test for the bug: count doesn't work when fetching objects from a findFromRawSQL on inherited tables
1 parent fd8845b commit 6c56e6a

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ vendor/*
1313
/.travis/
1414
/vendor-bin/require-checker/vendor/
1515
/vendor-bin/couscous/vendor/
16-
.phpunit.result.cache
16+
.phpunit.result.cache
17+
tdbm.lock.yml

tests/Dao/TestPersonDao.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/*
3+
* This file has been automatically generated by TDBM.
4+
* You can edit this file as it will not be overwritten.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace TheCodingMachine\TDBM\Dao;
10+
11+
use TheCodingMachine\TDBM\ResultIterator;
12+
use TheCodingMachine\TDBM\Test\Dao\Generated\PersonBaseDao;
13+
14+
/**
15+
* The ContactDao class will maintain the persistence of ContactBean class into the contact table.
16+
*/
17+
class TestPersonDao extends PersonBaseDao
18+
{
19+
public function testFindFromRawSQLONInherited(): ResultIterator
20+
{
21+
$sql = '
22+
SELECT DISTINCT person.*, contact.*, users.*
23+
FROM person JOIN contact ON person.id = contact.id
24+
JOIN users ON contact.id = users.id
25+
WHERE TRUE
26+
';
27+
28+
return $this->findFromRawSql($sql, []);
29+
}
30+
}

tests/TDBMDaoGeneratorTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use ReflectionMethod;
3333
use TheCodingMachine\TDBM\Dao\TestArticleDao;
3434
use TheCodingMachine\TDBM\Dao\TestCountryDao;
35+
use TheCodingMachine\TDBM\Dao\TestPersonDao;
3536
use TheCodingMachine\TDBM\Dao\TestRoleDao;
3637
use TheCodingMachine\TDBM\Dao\TestUserDao;
3738
use TheCodingMachine\TDBM\Fixtures\Interfaces\TestUserDaoInterface;
@@ -2178,4 +2179,13 @@ public function testFindByDateTime(): void
21782179
$personDao->findByModifiedAt(new \DateTimeImmutable())->count();
21792180
$this->assertTrue(true);
21802181
}
2182+
2183+
public function testFindFromRawSQLOnInheritance(): void
2184+
{
2185+
$dao = new TestPersonDao($this->tdbmService);
2186+
$objects = $dao->testFindFromRawSQLONInherited();
2187+
2188+
$this->assertNotNull($objects->first());
2189+
$this->assertNotEquals(0, $objects->count());
2190+
}
21812191
}

0 commit comments

Comments
 (0)