@@ -16,6 +16,7 @@ class ModelTest extends \PHPUnit\Framework\TestCase
1616 private $ services ;
1717 private $ pipesServices ;
1818 private $ pipesUsers ;
19+ private $ users ;
1920
2021 public function setup ()
2122 {
@@ -41,18 +42,23 @@ public function setup()
4142 'pipe_id ' => 1 ,
4243 'service_id ' => 1
4344 ];
44- $ this ->pipesUsers = [
45+ $ this ->pipesUsers = [[
4546 'id ' => 1 ,
4647 'pipe_id ' => 1 ,
4748 'user_id ' => 1 ,
4849 'last_run ' => '2017-07-04 10:20:24 ' ,
4950 'run_count ' => 3 ,
5051 'tracking_condition ' => '' ,
5152 'enabled ' => 1
52- ];
53+ ]];
54+ $ this ->users = [[
55+ 'id ' => 1 ,
56+ 'email ' => 'derek@grindaga.com '
57+ ]];
5358 $ this ->prophet = new Prophecy \Prophet ;
5459 $ this ->mysql = $ this ->prophet ->prophesize ("\MysqliDb " );
5560 $ this ->pipe = new Pipe ($ this ->mysql ->reveal ());
61+ $ this ->pipeUser = new PipeUser ($ this ->mysql ->reveal ());
5662 }
5763
5864 public function testCanInstantiate ()
@@ -219,4 +225,17 @@ public function testFieldsAreNotUnique()
219225 $ this ->expectExceptionMessage ('name must be unique for Pipe. ' );
220226 $ this ->pipe ->insert ($ pipe );
221227 }
228+
229+ public function testBelongsTo ()
230+ {
231+ $ this ->mysql ->where (\Prophecy \Argument::type ('string ' ), \Prophecy \Argument::type ('int ' ))->willReturn (true );
232+ $ this ->mysql ->where (\Prophecy \Argument::type ('string ' ), \Prophecy \Argument::type ('string ' ))->willReturn (true );
233+ $ this ->mysql ->join (\Prophecy \Argument::type ('string ' ), \Prophecy \Argument::type ('string ' ), \Prophecy \Argument::type ('string ' ))->willReturn (true );
234+ $ this ->mysql ->get (\Prophecy \Argument::exact ('pipes Pipe ' ))->willReturn ($ this ->pipes );
235+ $ this ->mysql ->get (\Prophecy \Argument::exact ('users User ' ))->willReturn ($ this ->users );
236+ $ this ->mysql ->get (\Prophecy \Argument::exact ('pipes_users PipeUser ' ))->willReturn ($ this ->pipesUsers );
237+
238+ $ pipeUsers = $ this ->pipeUser ->getAll ();
239+ $ this ->assertEquals (1 , $ pipeUsers [0 ]['pipe_id ' ]);
240+ }
222241}
0 commit comments