Skip to content

Commit 4b64f55

Browse files
committed
Improving code coverage
1 parent 38c74ec commit 4b64f55

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace TheCodingMachine\TDBM\QueryFactory;
4+
5+
use Doctrine\DBAL\Schema\Schema;
6+
use PHPUnit\Framework\TestCase;
7+
use TheCodingMachine\TDBM\TDBMAbstractServiceTest;
8+
use TheCodingMachine\TDBM\TDBMException;
9+
10+
class FindObjectsFromRawSqlQueryFactoryTest extends TDBMAbstractServiceTest
11+
{
12+
13+
public function testGetSubQueryColumnDescriptors()
14+
{
15+
$queryFactory = new FindObjectsFromRawSqlQueryFactory($this->tdbmService, $this->createMock(Schema::class), 'foo', 'bar');
16+
$this->expectException(TDBMException::class);
17+
$queryFactory->getSubQueryColumnDescriptors();
18+
}
19+
20+
public function testGetMagicSqlSubQuery()
21+
{
22+
$queryFactory = new FindObjectsFromRawSqlQueryFactory($this->tdbmService, $this->createMock(Schema::class), 'foo', 'bar');
23+
$this->expectException(TDBMException::class);
24+
$queryFactory->getMagicSqlSubQuery();
25+
26+
}
27+
}

tests/TDBMDaoGeneratorTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2189,7 +2189,7 @@ public function testSQLCountWithArray(): void
21892189
/**
21902190
* @depends testDaoGeneration
21912191
*/
2192-
public function testSubQueryWithFind()
2192+
public function testSubQueryWithFind(): void
21932193
{
21942194
$userDao = new TestUserDao($this->tdbmService);
21952195
$articleDao = new TestArticleSubQueryDao($this->tdbmService, $userDao);
@@ -2204,4 +2204,13 @@ public function testSubQueryWithFind()
22042204
$this->assertCount(1, $results);
22052205
$this->assertSame('Foo', $results[0]->getContent());
22062206
}
2207+
2208+
public function testSubQueryExceptionOnPrimaryKeysWithMultipleColumns(): void
2209+
{
2210+
$stateDao = new StateDao($this->tdbmService);
2211+
$states = $stateDao->findAll();
2212+
$this->expectException(TDBMException::class);
2213+
$this->expectExceptionMessage('You cannot use in a sub-query a table that has a primary key on more that 1 column.');
2214+
$states->_getSubQuery();
2215+
}
22072216
}

0 commit comments

Comments
 (0)