@@ -850,6 +850,62 @@ public function test_factory_global_model_resolver()
850
850
$ this ->assertEquals (FactoryTestGuessModelFactory::new ()->modelName (), FactoryTestGuessModel::class);
851
851
}
852
852
853
+ public function test_factory_model_has_many_relationship_has_pending_attributes ()
854
+ {
855
+ FactoryTestUser::factory ()->has (new FactoryTestPostFactory (), 'postsWithFooBarBazAsTitle ' )->create ();
856
+
857
+ $ this ->assertEquals ('foo bar baz ' , FactoryTestPost::first ()->title );
858
+ }
859
+
860
+ public function test_factory_model_has_many_relationship_has_pending_attributes_override ()
861
+ {
862
+ FactoryTestUser::factory ()->has ((new FactoryTestPostFactory ())->state (['title ' => 'other title ' ]), 'postsWithFooBarBazAsTitle ' )->create ();
863
+
864
+ $ this ->assertEquals ('other title ' , FactoryTestPost::first ()->title );
865
+ }
866
+
867
+ public function test_factory_model_has_one_relationship_has_pending_attributes ()
868
+ {
869
+ FactoryTestUser::factory ()->has (new FactoryTestPostFactory (), 'postWithFooBarBazAsTitle ' )->create ();
870
+
871
+ $ this ->assertEquals ('foo bar baz ' , FactoryTestPost::first ()->title );
872
+ }
873
+
874
+ public function test_factory_model_has_one_relationship_has_pending_attributes_override ()
875
+ {
876
+ FactoryTestUser::factory ()->has ((new FactoryTestPostFactory ())->state (['title ' => 'other title ' ]), 'postWithFooBarBazAsTitle ' )->create ();
877
+
878
+ $ this ->assertEquals ('other title ' , FactoryTestPost::first ()->title );
879
+ }
880
+
881
+ public function test_factory_model_belongs_to_many_relationship_has_pending_attributes ()
882
+ {
883
+ FactoryTestUser::factory ()->has (new FactoryTestRoleFactory (), 'rolesWithFooBarBazAsName ' )->create ();
884
+
885
+ $ this ->assertEquals ('foo bar baz ' , FactoryTestRole::first ()->name );
886
+ }
887
+
888
+ public function test_factory_model_belongs_to_many_relationship_has_pending_attributes_override ()
889
+ {
890
+ FactoryTestUser::factory ()->has ((new FactoryTestRoleFactory ())->state (['name ' => 'other name ' ]), 'rolesWithFooBarBazAsName ' )->create ();
891
+
892
+ $ this ->assertEquals ('other name ' , FactoryTestRole::first ()->name );
893
+ }
894
+
895
+ public function test_factory_model_morph_many_relationship_has_pending_attributes ()
896
+ {
897
+ (new FactoryTestPostFactory ())->has (new FactoryTestCommentFactory (), 'commentsWithFooBarBazAsBody ' )->create ();
898
+
899
+ $ this ->assertEquals ('foo bar baz ' , FactoryTestComment::first ()->body );
900
+ }
901
+
902
+ public function test_factory_model_morph_many_relationship_has_pending_attributes_override ()
903
+ {
904
+ (new FactoryTestPostFactory ())->has ((new FactoryTestCommentFactory ())->state (['body ' => 'other body ' ]), 'commentsWithFooBarBazAsBody ' )->create ();
905
+
906
+ $ this ->assertEquals ('other body ' , FactoryTestComment::first ()->body );
907
+ }
908
+
853
909
/**
854
910
* Get a database connection instance.
855
911
*
@@ -895,11 +951,26 @@ public function posts()
895
951
return $ this ->hasMany (FactoryTestPost::class, 'user_id ' );
896
952
}
897
953
954
+ public function postsWithFooBarBazAsTitle ()
955
+ {
956
+ return $ this ->hasMany (FactoryTestPost::class, 'user_id ' )->withAttributes (['title ' => 'foo bar baz ' ]);
957
+ }
958
+
959
+ public function postWithFooBarBazAsTitle ()
960
+ {
961
+ return $ this ->hasOne (FactoryTestPost::class, 'user_id ' )->withAttributes (['title ' => 'foo bar baz ' ]);
962
+ }
963
+
898
964
public function roles ()
899
965
{
900
966
return $ this ->belongsToMany (FactoryTestRole::class, 'role_user ' , 'user_id ' , 'role_id ' )->withPivot ('admin ' );
901
967
}
902
968
969
+ public function rolesWithFooBarBazAsName ()
970
+ {
971
+ return $ this ->belongsToMany (FactoryTestRole::class, 'role_user ' , 'user_id ' , 'role_id ' )->withPivot ('admin ' )->withAttributes (['name ' => 'foo bar baz ' ]);
972
+ }
973
+
903
974
public function factoryTestRoles ()
904
975
{
905
976
return $ this ->belongsToMany (FactoryTestRole::class, 'role_user ' , 'user_id ' , 'role_id ' )->withPivot ('admin ' );
@@ -944,6 +1015,11 @@ public function comments()
944
1015
{
945
1016
return $ this ->morphMany (FactoryTestComment::class, 'commentable ' );
946
1017
}
1018
+
1019
+ public function commentsWithFooBarBazAsBody ()
1020
+ {
1021
+ return $ this ->morphMany (FactoryTestComment::class, 'commentable ' )->withAttributes (['body ' => 'foo bar baz ' ]);
1022
+ }
947
1023
}
948
1024
949
1025
class FactoryTestCommentFactory extends Factory
0 commit comments