11<?php
22
33use AMBERSIVE \Tests \TestCase ;
4-
54use AMBERSIVE \VatValidator \Classes \VatValidator ;
6-
75use VatValidator as VV ;
86
97class VatValidatorTest extends TestCase
108{
11-
129 private VatValidator $ validator ;
1310
1411 protected function setUp (): void
1512 {
1613 parent ::setUp ();
1714
1815 $ mockedResult = [
19- " countryCode " => " AT " ,
20- " vatNumber " => " U69434328 " ,
21- " requestDate " => " 2020-07-10+02:00 " ,
22- " valid " => false ,
23- " name " => " --- " ,
24- " address " => " --- "
16+ ' countryCode ' => ' AT ' ,
17+ ' vatNumber ' => ' U69434328 ' ,
18+ ' requestDate ' => ' 2020-07-10+02:00 ' ,
19+ ' valid ' => false ,
20+ ' name ' => ' --- ' ,
21+ ' address ' => ' --- ' ,
2522 ];
2623
2724 $ client = $ this ->getMockFromWsdl (
28- __DIR__ .'/../checkVatService.wsdl ' , 'checkVat ' . md5 ( time ().rand ())
25+ __DIR__ .'/../checkVatService.wsdl ' , 'checkVat ' . md5 (time ().rand ())
2926 );
3027
3128 $ client
@@ -36,37 +33,39 @@ protected function setUp(): void
3633 }
3734
3835 /**
39- * Test if the the method will throw an exeception cause the id complete wrong
36+ * Test if the the method will throw an exeception cause the id complete wrong.
4037 */
41- public function testIfVatValidatorThrowsExceptionIfInvalidVatId ():void {
38+ public function testIfVatValidatorThrowsExceptionIfInvalidVatId ():void
39+ {
4240 $ this ->expectException (\Symfony \Component \HttpKernel \Exception \HttpException::class);
43- $ result = $ this ->validator ->check (" TEST " );
41+ $ result = $ this ->validator ->check (' TEST ' );
4442 }
4543
4644 /**
47- * Test if the vat return invalid if the id seems to be in the right structure but is wrong
45+ * Test if the vat return invalid if the id seems to be in the right structure but is wrong.
4846 */
49- public function testIfVatValidatorWillNotThrowExeceptionIfTheVatIdIsWrong ():void {
50- $ result = $ this ->validator ->check ("ATU69434328 " );
47+ public function testIfVatValidatorWillNotThrowExeceptionIfTheVatIdIsWrong ():void
48+ {
49+ $ result = $ this ->validator ->check ('ATU69434328 ' );
5150 $ this ->assertNotNull ($ result );
52- $ this ->assertEquals (false , $ result ->isValid ());
51+ $ this ->assertEquals (false , $ result ->isValid ());
5352 }
5453
5554 /**
56- * Test if the validator returns the correct company profile
55+ * Test if the validator returns the correct company profile.
5756 */
58- public function testIfVatValidatorReturnsValidObject ():void {
59-
57+ public function testIfVatValidatorReturnsValidObject ():void
58+ {
6059 $ mockedResult = [
61- " countryCode " => " AT " ,
62- " vatNumber " => " U69434329 " ,
63- " valid " => true ,
64- " name " => " PICAPIPE GmbH " ,
65- " address " => " Geylinggasse 15-17 \\nAT-1130 Wien "
60+ ' countryCode ' => ' AT ' ,
61+ ' vatNumber ' => ' U69434329 ' ,
62+ ' valid ' => true ,
63+ ' name ' => ' PICAPIPE GmbH ' ,
64+ ' address ' => ' Geylinggasse 15-17 \\nAT-1130 Wien ' ,
6665 ];
6766
6867 $ client = $ this ->getMockFromWsdl (
69- __DIR__ .'/../checkVatService.wsdl ' , 'checkVat ' . md5 ( time ().rand ())
68+ __DIR__ .'/../checkVatService.wsdl ' , 'checkVat ' . md5 (time ().rand ())
7069 );
7170
7271 $ client
@@ -75,79 +74,118 @@ public function testIfVatValidatorReturnsValidObject():void {
7574
7675 $ validator = new VatValidator ($ client );
7776
78- $ result = $ validator ->check (" ATU69434329 " );
77+ $ result = $ validator ->check (' ATU69434329 ' );
7978 $ this ->assertNotNull ($ result );
80- $ this ->assertEquals (" AT " , $ result ->getCountry ());
79+ $ this ->assertEquals (' AT ' , $ result ->getCountry ());
8180 $ this ->assertEquals (true , $ result ->isValid ());
82- $ this ->assertEquals ("PICAPIPE GmbH " , $ result ->getName ());
83-
81+ $ this ->assertEquals ('PICAPIPE GmbH ' , $ result ->getName ());
8482 }
8583
8684 /**
87- * Test if the Facade is working
85+ * Test if the Facade is working.
8886 */
89- public function testIfFacadeIsWorking ():void {
90- $ result = VV ::check ("ATU69434329 " );
91- $ this ->assertEquals ("AT " , $ result ->getCountry ());
87+ public function testIfFacadeIsWorking ():void
88+ {
89+ $ result = VV ::check ('ATU69434329 ' );
90+ $ this ->assertEquals ('AT ' , $ result ->getCountry ());
9291 $ this ->assertEquals (true , $ result ->isValid ());
93- $ this ->assertEquals (" PICAPIPE GmbH " , $ result ->getName ());
92+ $ this ->assertEquals (' PICAPIPE GmbH ' , $ result ->getName ());
9493 }
95-
96- public function testIfValidationExtentionsWorks ():void {
9794
98- // Prepare
95+ public function testIfValidationExtentionsWorks ():void
96+ {
97+
98+ // Prepare
9999 $ data = [
100- 'vatid ' => 'ATU69434329 '
100+ 'vatid ' => 'ATU69434329 ' ,
101101 ];
102102
103103 $ rules = [
104- 'vatid ' => 'vat_eu '
104+ 'vatid ' => 'vat_eu ' ,
105105 ];
106106
107107 // Execute
108108 $ validator = Validator::make ($ data , $ rules );
109109
110110 // Test
111111 $ this ->assertFalse ($ validator ->fails ());
112-
113112 }
114113
115- public function testIfValidationExtentionsWorksButReturnsInvalid ():void {
114+ public function testIfValidationExtentionsWorksButReturnsInvalid ():void
115+ {
116116
117- // Prepare
117+ // Prepare
118118 $ data = [
119- 'vatid ' => 'ATU69434328 '
119+ 'vatid ' => 'ATU69434328 ' ,
120120 ];
121121
122122 $ rules = [
123- 'vatid ' => 'vat_eu '
123+ 'vatid ' => 'vat_eu ' ,
124124 ];
125125
126126 // Execute
127127 $ validator = Validator::make ($ data , $ rules );
128128
129129 // Test
130130 $ this ->assertTrue ($ validator ->fails ());
131-
132131 }
133132
134- public function testIfValidationExtentionsWorksButReturnsInvalidEvenIfPassedValueIsTotallyWrong ():void {
133+ public function testIfValidationExtentionsWorksButReturnsInvalidEvenIfPassedValueIsTotallyWrong ():void
134+ {
135135
136- // Prepare
136+ // Prepare
137137 $ data = [
138- 'vatid ' => 'XXX '
138+ 'vatid ' => 'XXX ' ,
139139 ];
140140
141141 $ rules = [
142- 'vatid ' => 'vat_eu '
142+ 'vatid ' => 'vat_eu ' ,
143143 ];
144144
145145 // Execute
146146 $ validator = Validator::make ($ data , $ rules );
147147
148148 // Test
149149 $ this ->assertTrue ($ validator ->fails ());
150+ }
150151
152+ public function testIfValidationExtensionWorksWithVatEuIf ():void
153+ {
154+
155+ // Prepare
156+ $ data = [
157+ 'vatid ' => 'XXX ' ,
158+ 'company ' => true ,
159+ ];
160+
161+ $ rules = [
162+ 'vatid ' => 'vat_eu_if:company,true ' ,
163+ ];
164+
165+ // Execute
166+ $ validator = Validator::make ($ data , $ rules );
167+
168+ // Test
169+ $ this ->assertTrue ($ validator ->fails ());
151170 }
152171
153- }
172+ public function testIfValidadtionExtensionsIsValidIfRequiredIfIsFalse ():void
173+ {
174+
175+ // Prepare
176+ $ data = [
177+ 'vatid ' => 'XXX ' ,
178+ 'company ' => false ,
179+ ];
180+
181+ $ rules = [
182+ 'vatid ' => 'vat_eu_if:company,true ' ,
183+ ];
184+
185+ // Execute
186+ $ validator = Validator::make ($ data , $ rules );
187+
188+ // Test
189+ $ this ->assertFalse ($ validator ->fails ());
190+ }
191+ }
0 commit comments