@@ -629,4 +629,94 @@ public function it_cannot_call_disallowed_builder_method()
629629
630630 UserA::clientQuery ();
631631 }
632+
633+ /** @test */
634+ public function it_can_call_named_scopes_on_model ()
635+ {
636+ $ connection = $ this ->newConnectionMock ();
637+ $ connection ->shouldReceive ('clientQuery ' )->with ([
638+ 'TableName ' => 'User ' ,
639+ 'KeyConditionExpression ' => '#1 = :1 ' ,
640+ 'FilterExpression ' => '#2 = :2 ' ,
641+ 'ExpressionAttributeNames ' => [
642+ '#1 ' => 'partition ' ,
643+ '#2 ' => 'status '
644+ ],
645+ 'ExpressionAttributeValues ' => [
646+ ':1 ' => [
647+ 'S ' => 'test '
648+ ],
649+ ':2 ' => [
650+ 'S ' => 'active '
651+ ]
652+ ]
653+ ])->andReturn ($ this ->sampleAwsResult ())->once ();
654+ $ this ->setConnectionResolver ($ connection );
655+
656+ UserA::keyCondition ('partition ' , '= ' , 'test ' )->active ()->query ();
657+ }
658+
659+ /** @test */
660+ public function it_can_call_named_scopes_with_parameters_on_model ()
661+ {
662+ $ connection = $ this ->newConnectionMock ();
663+ $ connection ->shouldReceive ('clientQuery ' )->with ([
664+ 'TableName ' => 'User ' ,
665+ 'KeyConditionExpression ' => '#1 = :1 ' ,
666+ 'FilterExpression ' => '#2 = :2 ' ,
667+ 'ExpressionAttributeNames ' => [
668+ '#1 ' => 'partition ' ,
669+ '#2 ' => 'name '
670+ ],
671+ 'ExpressionAttributeValues ' => [
672+ ':1 ' => [
673+ 'S ' => 'test '
674+ ],
675+ ':2 ' => [
676+ 'S ' => 'John '
677+ ]
678+ ]
679+ ])->andReturn ($ this ->sampleAwsResult ())->once ();
680+ $ this ->setConnectionResolver ($ connection );
681+
682+ UserA::keyCondition ('partition ' , '= ' , 'test ' )->byName ('John ' )->query ();
683+ }
684+
685+ /** @test */
686+ public function it_can_chain_multiple_scopes ()
687+ {
688+ $ connection = $ this ->newConnectionMock ();
689+ $ connection ->shouldReceive ('clientQuery ' )->with ([
690+ 'TableName ' => 'User ' ,
691+ 'KeyConditionExpression ' => '#1 = :1 ' ,
692+ 'FilterExpression ' => '#2 = :2 and #3 = :3 ' ,
693+ 'ExpressionAttributeNames ' => [
694+ '#1 ' => 'partition ' ,
695+ '#2 ' => 'status ' ,
696+ '#3 ' => 'name '
697+ ],
698+ 'ExpressionAttributeValues ' => [
699+ ':1 ' => [
700+ 'S ' => 'test '
701+ ],
702+ ':2 ' => [
703+ 'S ' => 'active '
704+ ],
705+ ':3 ' => [
706+ 'S ' => 'John '
707+ ]
708+ ]
709+ ])->andReturn ($ this ->sampleAwsResult ())->once ();
710+ $ this ->setConnectionResolver ($ connection );
711+
712+ UserA::keyCondition ('partition ' , '= ' , 'test ' )->active ()->byName ('John ' )->query ();
713+ }
714+
715+ /** @test */
716+ public function it_cannot_call_non_existent_scope_on_model ()
717+ {
718+ $ this ->expectException (BadMethodCallException::class);
719+
720+ UserA::nonExistentScope ();
721+ }
632722}
0 commit comments