22
22
namespace TheCodingMachine \TDBM ;
23
23
24
24
use Psr \Log \LogLevel ;
25
+ use Psr \Log \NullLogger ;
25
26
use Wa72 \SimpleLogger \ArrayLogger ;
26
27
27
28
class TDBMServiceTest extends TDBMAbstractServiceTest
@@ -682,7 +683,7 @@ public function testFindObjectsFromSql(): void
682
683
*/
683
684
public function testFindObjectsFromSqlBadTableName (): void
684
685
{
685
- $ this ->expectException (' TheCodingMachine\TDBM\ TDBMException' );
686
+ $ this ->expectException (TDBMException::class );
686
687
$ this ->tdbmService ->findObjectsFromSql (
687
688
'#{azerty ' ,
688
689
'roles JOIN roles_rights ON roles.id = roles_rights.role_id JOIN rights ON rights.label = roles_rights.right_label ' ,
@@ -698,7 +699,7 @@ public function testFindObjectsFromSqlBadTableName(): void
698
699
*/
699
700
public function testFindObjectsFromSqlGroupBy (): void
700
701
{
701
- $ this ->expectException (' TheCodingMachine\TDBM\ TDBMException' );
702
+ $ this ->expectException (TDBMException::class );
702
703
$ roles = $ this ->tdbmService ->findObjectsFromSql (
703
704
'roles ' ,
704
705
'roles JOIN roles_rights ON roles.id = roles_rights.role_id JOIN rights ON rights.label = roles_rights.right_label ' ,
@@ -709,6 +710,20 @@ public function testFindObjectsFromSqlGroupBy(): void
709
710
$ role = $ roles [0 ];
710
711
}
711
712
713
+ /**
714
+ *
715
+ * @throws TDBMException
716
+ */
717
+ public function testFindObjectsFromRawSqlBadTableName (): void
718
+ {
719
+ $ this ->expectException (TDBMException::class);
720
+ $ this ->tdbmService ->findObjectsFromRawSql (
721
+ '#{azerty ' ,
722
+ 'roles JOIN roles_rights ON roles.id = roles_rights.role_id JOIN rights ON rights.label = roles_rights.right_label WHERE rights.label = :right ' ,
723
+ array ('right ' => 'CAN_SING ' )
724
+ );
725
+ }
726
+
712
727
public function testFindObjectFromSql (): void
713
728
{
714
729
$ role = $ this ->tdbmService ->findObjectFromSql (
@@ -790,4 +805,40 @@ public function testFindObjectsFromSqlCountWithOneToManyLink(): void
790
805
791
806
$ this ->assertEquals (3 , $ countries ->count ());
792
807
}
808
+
809
+ public function testBuildFilterFromFilterBagIterator (): void
810
+ {
811
+ $ tdbmService = new TDBMService (new Configuration ('TheCodingMachine \\TDBM \\Test \\Dao \\Bean ' , 'TheCodingMachine \\TDBM \\Test \\Dao ' , 'TheCodingMachine \\TDBM \\Test \\ResultIterator ' , self ::getConnection (), $ this ->getNamingStrategy (), null , null , new NullLogger ()));
812
+
813
+ [$ sql , $ parameters , $ counter ] = $ tdbmService ->buildFilterFromFilterBag (new \ArrayIterator (['id ' => 1 ]), self ::getConnection ()->getDatabasePlatform ());
814
+ $ this ->assertRegExp ('/\(.id. = :tdbmparam1\)/ ' , $ sql );
815
+ $ this ->assertEquals ($ parameters ['tdbmparam1 ' ], 1 );
816
+ }
817
+
818
+ public function testFindObjectsMethodWithoutResultIteratorClass (): void
819
+ {
820
+ $ this ->expectException (TDBMInvalidArgumentException::class);
821
+ $ this ->expectExceptionMessageRegExp ('/^\$resultIteratorClass should be a ` ' . preg_quote (ResultIterator::class, '/ ' ) . '`. `(.*)` provided\.$/ ' );
822
+ $ tdbmService = new TDBMService (new Configuration ('TheCodingMachine \\TDBM \\Test \\Dao \\Bean ' , 'TheCodingMachine \\TDBM \\Test \\Dao ' , 'TheCodingMachine \\TDBM \\Test \\ResultIterator ' , self ::getConnection (), $ this ->getNamingStrategy (), null , null , new NullLogger ()));
823
+
824
+ $ tdbmService ->findObjects ('' , null , [], null , [], null , null , self ::class);
825
+ }
826
+
827
+ public function testFindObjectsFromSqlMethodWithoutResultIteratorClass (): void
828
+ {
829
+ $ this ->expectException (TDBMInvalidArgumentException::class);
830
+ $ this ->expectExceptionMessageRegExp ('/^\$resultIteratorClass should be a ` ' . preg_quote (ResultIterator::class, '/ ' ) . '`. `(.*)` provided\.$/ ' );
831
+ $ tdbmService = new TDBMService (new Configuration ('TheCodingMachine \\TDBM \\Test \\Dao \\Bean ' , 'TheCodingMachine \\TDBM \\Test \\Dao ' , 'TheCodingMachine \\TDBM \\Test \\ResultIterator ' , self ::getConnection (), $ this ->getNamingStrategy (), null , null , new NullLogger ()));
832
+
833
+ $ tdbmService ->findObjectsFromSql ('' , '' , null , [], null , null , null , self ::class);
834
+ }
835
+
836
+ public function testFindObjectsFromRawSqlMethodWithoutResultIteratorClass (): void
837
+ {
838
+ $ this ->expectException (TDBMInvalidArgumentException::class);
839
+ $ this ->expectExceptionMessageRegExp ('/^\$resultIteratorClass should be a ` ' . preg_quote (ResultIterator::class, '/ ' ) . '`. `(.*)` provided\.$/ ' );
840
+ $ tdbmService = new TDBMService (new Configuration ('TheCodingMachine \\TDBM \\Test \\Dao \\Bean ' , 'TheCodingMachine \\TDBM \\Test \\Dao ' , 'TheCodingMachine \\TDBM \\Test \\ResultIterator ' , self ::getConnection (), $ this ->getNamingStrategy (), null , null , new NullLogger ()));
841
+
842
+ $ tdbmService ->findObjectsFromRawSql ('' , '' , [], null , null , null , self ::class);
843
+ }
793
844
}
0 commit comments