66use Google \Cloud \Spanner \Result ;
77use Google \Cloud \Spanner \Timestamp ;
88use Google \Cloud \Spanner \Transaction ;
9+ use Illuminate \Support \Collection ;
910use MgCosta \Spanner \Builder \Builder ;
1011use MgCosta \Spanner \Builder \ParamCounter ;
1112use MgCosta \Spanner \Builder \Expression ;
@@ -613,6 +614,8 @@ public function testShouldReturnNullWhenCallingAggregateMethodWithoutResults()
613614 $ mockResult = m::mock (Result::class);
614615 $ mockResult ->shouldReceive ('getIterator ' )->andReturn (new ArrayIterator ([]));
615616 $ this ->mockedModel ->shouldReceive ('getPrimaryKey ' )->andReturn ('DummyID ' );
617+ $ this ->mockedModel ->shouldReceive ('newInstance ' )->andReturnSelf ();
618+ $ this ->mockedModel ->shouldReceive ('newCollection ' )->andReturn (new Collection ([]));
616619 $ this ->database ->shouldReceive ('execute ' )->andReturn ($ mockResult );
617620 $ result = $ this ->builder ->where ('age ' , '> ' , 35 )->count ();
618621 $ this ->assertEquals (null , $ result );
@@ -623,6 +626,9 @@ public function testShouldReturnAnIntegerWhenCallingCountMethod()
623626 $ mockResult = m::mock (Result::class);
624627 $ mockResult ->shouldReceive ('getIterator ' )->andReturn (new ArrayIterator ([['aggregate ' => 39 ]]));
625628 $ this ->mockedModel ->shouldReceive ('getPrimaryKey ' )->andReturn ('DummyID ' );
629+ $ this ->mockedModel ->shouldReceive ('newInstance ' )->andReturnSelf ();
630+ $ this ->mockedModel ->shouldReceive ('newFromBuilder ' )->andReturnSelf ();
631+ $ this ->mockedModel ->shouldReceive ('newCollection ' )->andReturn (new Collection ($ mockResult ));
626632 $ this ->database ->shouldReceive ('execute ' )->andReturn ($ mockResult );
627633 $ result = $ this ->builder ->where ('age ' , '> ' , 35 )->count ();
628634 $ this ->assertEquals (39 , $ result );
@@ -633,6 +639,9 @@ public function testShouldReturnAnIntegerWhenCallingMaxMethod()
633639 $ mockResult = m::mock (Result::class);
634640 $ mockResult ->shouldReceive ('getIterator ' )->andReturn (new ArrayIterator ([['aggregate ' => 200 ]]));
635641 $ this ->mockedModel ->shouldReceive ('getPrimaryKey ' )->andReturn ('DummyID ' );
642+ $ this ->mockedModel ->shouldReceive ('newInstance ' )->andReturnSelf ();
643+ $ this ->mockedModel ->shouldReceive ('newFromBuilder ' )->andReturnSelf ();
644+ $ this ->mockedModel ->shouldReceive ('newCollection ' )->andReturn (new Collection ($ mockResult ));
636645 $ this ->database ->shouldReceive ('execute ' )->andReturn ($ mockResult );
637646 $ result = $ this ->builder ->where ('age ' , '> ' , 35 )->max ('age ' );
638647 $ this ->assertEquals (200 , $ result );
@@ -643,6 +652,9 @@ public function testShouldReturnAnIntegerWhenCallingMinMethod()
643652 $ mockResult = m::mock (Result::class);
644653 $ mockResult ->shouldReceive ('getIterator ' )->andReturn (new ArrayIterator ([['aggregate ' => 20 ]]));
645654 $ this ->mockedModel ->shouldReceive ('getPrimaryKey ' )->andReturn ('DummyID ' );
655+ $ this ->mockedModel ->shouldReceive ('newInstance ' )->andReturnSelf ();
656+ $ this ->mockedModel ->shouldReceive ('newFromBuilder ' )->andReturnSelf ();
657+ $ this ->mockedModel ->shouldReceive ('newCollection ' )->andReturn (new Collection ($ mockResult ));
646658 $ this ->database ->shouldReceive ('execute ' )->andReturn ($ mockResult );
647659 $ result = $ this ->builder ->where ('age ' , '> ' , 35 )->min ('age ' );
648660 $ this ->assertEquals (20 , $ result );
@@ -653,6 +665,9 @@ public function testShouldReturnAnIntegerWhenCallingSumMethod()
653665 $ mockResult = m::mock (Result::class);
654666 $ mockResult ->shouldReceive ('getIterator ' )->andReturn (new ArrayIterator ([['aggregate ' => 333 ]]));
655667 $ this ->mockedModel ->shouldReceive ('getPrimaryKey ' )->andReturn ('DummyID ' );
668+ $ this ->mockedModel ->shouldReceive ('newInstance ' )->andReturnSelf ();
669+ $ this ->mockedModel ->shouldReceive ('newFromBuilder ' )->andReturnSelf ();
670+ $ this ->mockedModel ->shouldReceive ('newCollection ' )->andReturn (new Collection ($ mockResult ));
656671 $ this ->database ->shouldReceive ('execute ' )->andReturn ($ mockResult );
657672 $ result = $ this ->builder ->where ('age ' , '> ' , 35 )->sum ('age ' );
658673 $ this ->assertEquals (333 , $ result );
@@ -663,6 +678,9 @@ public function testShouldReturnAFloatWhenCallingAvgMethod()
663678 $ mockResult = m::mock (Result::class);
664679 $ mockResult ->shouldReceive ('getIterator ' )->andReturn (new ArrayIterator ([['aggregate ' => 333.67 ]]));
665680 $ this ->mockedModel ->shouldReceive ('getPrimaryKey ' )->andReturn ('DummyID ' );
681+ $ this ->mockedModel ->shouldReceive ('newInstance ' )->andReturnSelf ();
682+ $ this ->mockedModel ->shouldReceive ('newFromBuilder ' )->andReturnSelf ();
683+ $ this ->mockedModel ->shouldReceive ('newCollection ' )->andReturn (new Collection ($ mockResult ));
666684 $ this ->database ->shouldReceive ('execute ' )->andReturn ($ mockResult );
667685 $ result = $ this ->builder ->where ('age ' , '> ' , 35 )->avg ('age ' );
668686 $ this ->assertEquals (333.67 , $ result );
@@ -673,6 +691,9 @@ public function testShouldReturnAValueWhenCallingValueMethod()
673691 $ mockResult = m::mock (Result::class);
674692 $ mockResult ->shouldReceive ('getIterator ' )->andReturn (new ArrayIterator ([['columnA ' => 'A ' , 'columnB ' => 'B ' ]]));
675693 $ this ->mockedModel ->shouldReceive ('getPrimaryKey ' )->andReturn ('DummyID ' );
694+ $ this ->mockedModel ->shouldReceive ('newInstance ' )->andReturnSelf ();
695+ $ this ->mockedModel ->shouldReceive ('newFromBuilder ' )->andReturnSelf ();
696+ $ this ->mockedModel ->shouldReceive ('newCollection ' )->andReturn (new Collection ($ mockResult ));
676697 $ this ->database ->shouldReceive ('execute ' )->andReturn ($ mockResult );
677698 $ result = $ this ->builder ->where ('age ' , '> ' , 35 )->value ('columnA ' );
678699 $ this ->assertEquals ('A ' , $ result );
@@ -683,6 +704,9 @@ public function testShouldReturnACollectionWhenCallingFindMethodProperly()
683704 $ mockResult = m::mock (Result::class);
684705 $ mockResult ->shouldReceive ('getIterator ' )->andReturn ($ this ->getRandomData (55 ));
685706 $ this ->mockedModel ->shouldReceive ('getPrimaryKey ' )->andReturn ('DummyID ' );
707+ $ this ->mockedModel ->shouldReceive ('newInstance ' )->andReturnSelf ();
708+ $ this ->mockedModel ->shouldReceive ('newFromBuilder ' )->andReturnSelf ();
709+ $ this ->mockedModel ->shouldReceive ('newCollection ' )->andReturn (new Collection ($ mockResult ));
686710 $ this ->database ->shouldReceive ('execute ' )->andReturn ($ mockResult );
687711 $ result = $ this ->builder ->find ('55 ' );
688712 $ this ->assertIsArray ($ result );
0 commit comments