1414use Hawkbit \Database \ConnectionManager ;
1515use Hawkbit \Database \Tests \Stubs \PostEntity ;
1616use Hawkbit \Database \Tests \Stubs \PostMapper ;
17+ use Hawkbit \Database \Tests \Stubs \UserEntity ;
18+ use Hawkbit \Database \Tests \Stubs \UserMapper ;
1719
1820class IntegrationTest extends \PHPUnit_Framework_TestCase
1921{
@@ -35,6 +37,7 @@ protected function setUp()
3537 ]);
3638
3739 $ connection ->getMapperLocator ()->register (PostMapper::class);
40+ $ connection ->getMapperLocator ()->register (UserMapper::class);
3841
3942 $ connection ->exec ('CREATE TABLE post (id INTEGER PRIMARY KEY, content TEXT) ' );
4043 $ connection ->exec ('CREATE TABLE user (id INTEGER PRIMARY KEY, username VARCHAR) ' );
@@ -109,8 +112,11 @@ public function testMapperIntegration()
109112 public function testUoWIntegration ()
110113 {
111114 $ connection = $ this ->connection ;
112- /** @var PostMapper $mapper */
113- $ mapper = $ connection ->loadMapper (PostEntity::class);
115+ /** @var PostMapper $postMapper */
116+ $ postMapper = $ connection ->loadMapper (PostEntity::class);
117+
118+ /** @var UserMapper $userMapper */
119+ $ userMapper = $ connection ->loadMapper (UserEntity::class);
114120 $ unitOfWork = $ connection ->createUnitOfWork ();
115121
116122 $ contentFromAnyOtherSource = [
@@ -119,25 +125,57 @@ public function testUoWIntegration()
119125 'Hello 2 ' ,
120126 ];
121127
128+ $ userFromAnyOtherSource = [
129+ 'Jake ' ,
130+ 'Andy ' ,
131+ 'Dave ' ,
132+ ];
133+
122134 foreach ($ contentFromAnyOtherSource as $ content ) {
123135 /** @var PostEntity $entity */
124- $ entity = $ mapper ->createEntity ();
136+ $ entity = $ postMapper ->createEntity ();
125137 $ entity ->setContent ($ content );
126138 $ unitOfWork ->create ($ entity );
127139 }
128140
141+ foreach ($ userFromAnyOtherSource as $ content ) {
142+ /** @var UserEntity $entity */
143+ $ entity = $ userMapper ->createEntity ();
144+ $ entity ->setUsername ($ content );
145+ $ unitOfWork ->create ($ entity );
146+ }
147+
129148 $ this ->assertTrue ($ unitOfWork ->commit ());
130149
131150 // test find commited entities
132151 foreach ($ contentFromAnyOtherSource as $ content ) {
133- $ foundEntity = $ mapper ->select (function (QueryBuilder $ query ) use ($ content ) {
152+ /** @var PostEntity $foundPostEntity */
153+ $ foundPostEntity = $ postMapper ->select (function (QueryBuilder $ query ) use ($ content ) {
134154 $ query ->where ($ query ->expr ()->eq ('content ' , $ query ->createPositionalParameter ($ content , Type::STRING )));
135155 }, ['* ' ], true );
136156
137157 // test object has been found in database
138- $ foundResult = $ mapper ->getGateway ()->select ()->where ('content = ? ' )->setParameter (0 , $ content , Type::STRING )->execute ()->fetch ();
139- $ this ->assertEquals ((int )$ foundResult ['id ' ], $ foundEntity ->getId ());
140- $ this ->assertEquals ($ foundResult ['content ' ], $ foundEntity ->getContent ());
158+ $ foundResult = $ postMapper ->getGateway ()->select ()->where ('content = ? ' )->setParameter (0 , $ content , Type::STRING )->execute ()->fetch ();
159+ $ this ->assertEquals ((int )$ foundResult ['id ' ], $ foundPostEntity ->getId ());
160+ $ this ->assertEquals ($ foundResult ['content ' ], $ foundPostEntity ->getContent ());
161+ }
162+
163+ // test find commited entities
164+ foreach ($ userFromAnyOtherSource as $ user ) {
165+
166+ /** @var UserEntity $foundUserEntity */
167+ $ foundUserEntity = $ userMapper ->select (function (QueryBuilder $ query ) use ($ user ) {
168+ $ query ->where ($ query ->expr ()->eq ('username ' , $ query ->createPositionalParameter ($ user , Type::STRING )));
169+ }, ['* ' ], true );
170+
171+ // test object has been found in database
172+ $ foundResult = $ userMapper ->getGateway ()->select ()->where ('username = ? ' )->setParameter (0 , $ user , Type::STRING )->execute ()->fetch ();
173+ $ this ->assertEquals ((int )$ foundResult ['id ' ], $ foundUserEntity ->getId ());
174+ $ this ->assertEquals ($ foundResult ['username ' ], $ foundUserEntity ->getUsername ());
175+ }
176+
177+ if (true ){
178+
141179 }
142180 }
143181}
0 commit comments