@@ -659,6 +659,54 @@ public function testPluckReturnsTheDateAttributesOfAModel()
659
659
$ this ->assertEquals (['date_2010-01-01 00:00:00 ' , 'date_2011-01-01 00:00:00 ' ], $ builder ->pluck ('created_at ' )->all ());
660
660
}
661
661
662
+ public function testQualifiedPluckReturnsTheMutatedAttributesOfAModel ()
663
+ {
664
+ $ model = $ this ->getMockModel ();
665
+ $ model ->shouldReceive ('qualifyColumn ' )->with ('name ' )->andReturn ('foo_table.name ' );
666
+
667
+ $ builder = $ this ->getBuilder ();
668
+ $ builder ->getQuery ()->shouldReceive ('pluck ' )->with ($ model ->qualifyColumn ('name ' ), '' )->andReturn (new BaseCollection (['bar ' , 'baz ' ]));
669
+ $ builder ->setModel ($ model );
670
+ $ builder ->getModel ()->shouldReceive ('hasGetMutator ' )->with ('name ' )->andReturn (true );
671
+ $ builder ->getModel ()->shouldReceive ('newFromBuilder ' )->with (['name ' => 'bar ' ])->andReturn (new EloquentBuilderTestPluckStub (['name ' => 'bar ' ]));
672
+ $ builder ->getModel ()->shouldReceive ('newFromBuilder ' )->with (['name ' => 'baz ' ])->andReturn (new EloquentBuilderTestPluckStub (['name ' => 'baz ' ]));
673
+
674
+ $ this ->assertEquals (['foo_bar ' , 'foo_baz ' ], $ builder ->pluck ($ model ->qualifyColumn ('name ' ))->all ());
675
+ }
676
+
677
+ public function testQualifiedPluckReturnsTheCastedAttributesOfAModel ()
678
+ {
679
+ $ model = $ this ->getMockModel ();
680
+ $ model ->shouldReceive ('qualifyColumn ' )->with ('name ' )->andReturn ('foo_table.name ' );
681
+
682
+ $ builder = $ this ->getBuilder ();
683
+ $ builder ->getQuery ()->shouldReceive ('pluck ' )->with ($ model ->qualifyColumn ('name ' ), '' )->andReturn (new BaseCollection (['bar ' , 'baz ' ]));
684
+ $ builder ->setModel ($ model );
685
+ $ builder ->getModel ()->shouldReceive ('hasGetMutator ' )->with ('name ' )->andReturn (false );
686
+ $ builder ->getModel ()->shouldReceive ('hasCast ' )->with ('name ' )->andReturn (true );
687
+ $ builder ->getModel ()->shouldReceive ('newFromBuilder ' )->with (['name ' => 'bar ' ])->andReturn (new EloquentBuilderTestPluckStub (['name ' => 'bar ' ]));
688
+ $ builder ->getModel ()->shouldReceive ('newFromBuilder ' )->with (['name ' => 'baz ' ])->andReturn (new EloquentBuilderTestPluckStub (['name ' => 'baz ' ]));
689
+
690
+ $ this ->assertEquals (['foo_bar ' , 'foo_baz ' ], $ builder ->pluck ($ model ->qualifyColumn ('name ' ))->all ());
691
+ }
692
+
693
+ public function testQualifiedPluckReturnsTheDateAttributesOfAModel ()
694
+ {
695
+ $ model = $ this ->getMockModel ();
696
+ $ model ->shouldReceive ('qualifyColumn ' )->with ('created_at ' )->andReturn ('foo_table.created_at ' );
697
+
698
+ $ builder = $ this ->getBuilder ();
699
+ $ builder ->getQuery ()->shouldReceive ('pluck ' )->with ($ model ->qualifyColumn ('created_at ' ), '' )->andReturn (new BaseCollection (['2010-01-01 00:00:00 ' , '2011-01-01 00:00:00 ' ]));
700
+ $ builder ->setModel ($ model );
701
+ $ builder ->getModel ()->shouldReceive ('hasGetMutator ' )->with ('created_at ' )->andReturn (false );
702
+ $ builder ->getModel ()->shouldReceive ('hasCast ' )->with ('created_at ' )->andReturn (false );
703
+ $ builder ->getModel ()->shouldReceive ('getDates ' )->andReturn (['created_at ' ]);
704
+ $ builder ->getModel ()->shouldReceive ('newFromBuilder ' )->with (['created_at ' => '2010-01-01 00:00:00 ' ])->andReturn (new EloquentBuilderTestPluckDatesStub (['created_at ' => '2010-01-01 00:00:00 ' ]));
705
+ $ builder ->getModel ()->shouldReceive ('newFromBuilder ' )->with (['created_at ' => '2011-01-01 00:00:00 ' ])->andReturn (new EloquentBuilderTestPluckDatesStub (['created_at ' => '2011-01-01 00:00:00 ' ]));
706
+
707
+ $ this ->assertEquals (['date_2010-01-01 00:00:00 ' , 'date_2011-01-01 00:00:00 ' ], $ builder ->pluck ($ model ->qualifyColumn ('created_at ' ))->all ());
708
+ }
709
+
662
710
public function testPluckWithoutModelGetterJustReturnsTheAttributesFoundInDatabase ()
663
711
{
664
712
$ builder = $ this ->getBuilder ();
0 commit comments