88use Illuminate \Support \Facades \Validator ;
99use LVR \CreditCard \Exceptions \CreditCardException ;
1010use Illuminate \Foundation \Http \Middleware \TrimStrings ;
11+ use LVR \CreditCard \Exceptions \CreditCardLengthException ;
12+ use LVR \CreditCard \Exceptions \CreditCardPatternException ;
13+ use LVR \CreditCard \Exceptions \CreditCardChecksumException ;
14+ use LVR \CreditCard \Exceptions \CreditCardCharactersException ;
1115use Illuminate \Foundation \Http \Middleware \ConvertEmptyStringsToNull ;
1216
1317abstract class BaseCardTests extends TestCase
@@ -76,7 +80,7 @@ public function it_recognises_valid_card_numbers()
7680 ['card_number ' => $ number ],
7781 ['card_number ' => new CardNumber ]
7882 )->passes (),
79- sprintf ('The number: "%s" is recognised as invalid but should be valid ' , $ number )
83+ sprintf ('The number: "%s" is recognized as invalid but should be valid ' , $ number )
8084 );
8185 });
8286 }
@@ -95,7 +99,7 @@ public function it_recognises_invalid_card_numbers()
9599 ['card_number ' => $ number ],
96100 ['card_number ' => [new CardNumber ]]
97101 )->fails (),
98- sprintf ('The number: "%s" is recognised as valid but should be invalid ' , $ number )
102+ sprintf ('The number: "%s" is recognized as valid but should be invalid ' , $ number )
99103 );
100104 });
101105 }
@@ -114,7 +118,7 @@ public function it_checks_number_length()
114118 $ this ->assertEquals (
115119 CardNumber::MSG_CARD_LENGTH_INVALID ,
116120 $ validator ->messages ()->first (),
117- sprintf ('The number: "%s" is not recognised as invalid length ' , $ number )
121+ sprintf ('The number: "%s" is not recognized as invalid length ' , $ number )
118122 );
119123 });
120124 }
@@ -157,8 +161,26 @@ public function it_should_not_match_other_cards()
157161 false ,
158162 sprintf ('%s cards ("%s") pattern matches %s card. ' , $ card , $ number , $ this ->instance )
159163 );
164+ } catch (CreditCardPatternException $ ex ) {
165+ $ this ->assertTrue (
166+ $ ex ->getMessage () === sprintf ('Wrong "%s" card pattern ' , $ number )
167+ );
168+ } catch (CreditCardLengthException $ ex ) {
169+ $ this ->assertTrue (
170+ $ ex ->getMessage () === sprintf ('Incorrect "%s" card length ' , $ number )
171+ );
172+ } catch (CreditCardChecksumException $ ex ) {
173+ $ this ->assertTrue (
174+ $ ex ->getMessage () === sprintf ('Invalid card number: "%s". Checksum is wrong ' , $ number )
175+ );
176+ } catch (CreditCardCharactersException $ ex ) {
177+ $ this ->assertTrue (
178+ $ ex ->getMessage () === sprintf ('Card number "%s" contains invalid characters ' , $ number )
179+ );
160180 } catch (CreditCardException $ ex ) {
161- $ this ->assertTrue ($ ex ->getMessage () === sprintf ('Wrong "%s" card pattern ' , $ number ));
181+ $ this ->assertTrue (
182+ $ ex ->getMessage () === 'Card number is not set '
183+ );
162184 }
163185 }
164186 });
0 commit comments