IbanValidatorTest.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Validator\Tests\Constraints;
  11. use Symfony\Component\Validator\Constraints\Iban;
  12. use Symfony\Component\Validator\Constraints\IbanValidator;
  13. use Symfony\Component\Validator\Validation;
  14. class IbanValidatorTest extends AbstractConstraintValidatorTest
  15. {
  16. protected function getApiVersion()
  17. {
  18. return Validation::API_VERSION_2_5;
  19. }
  20. protected function createValidator()
  21. {
  22. return new IbanValidator();
  23. }
  24. public function testNullIsValid()
  25. {
  26. $this->validator->validate(null, new Iban());
  27. $this->assertNoViolation();
  28. }
  29. public function testEmptyStringIsValid()
  30. {
  31. $this->validator->validate('', new Iban());
  32. $this->assertNoViolation();
  33. }
  34. /**
  35. * @dataProvider getValidIbans
  36. */
  37. public function testValidIbans($iban)
  38. {
  39. $this->validator->validate($iban, new Iban());
  40. $this->assertNoViolation();
  41. }
  42. public function getValidIbans()
  43. {
  44. return array(
  45. array('CH9300762011623852957'), // Switzerland without spaces
  46. array('CH93 0076 2011 6238 5295 7'), // Switzerland with multiple spaces
  47. // Country list
  48. // http://www.rbs.co.uk/corporate/international/g0/guide-to-international-business/regulatory-information/iban/iban-example.ashx
  49. array('AL47 2121 1009 0000 0002 3569 8741'), //Albania
  50. array('AD12 0001 2030 2003 5910 0100'), //Andorra
  51. array('AT61 1904 3002 3457 3201'), //Austria
  52. array('AZ21 NABZ 0000 0000 1370 1000 1944'), //Azerbaijan
  53. array('BH67 BMAG 0000 1299 1234 56'), //Bahrain
  54. array('BE62 5100 0754 7061'), //Belgium
  55. array('BA39 1290 0794 0102 8494'), //Bosnia and Herzegovina
  56. array('BG80 BNBG 9661 1020 3456 78'), //Bulgaria
  57. array('BY 13 NBRB 3600 900000002Z00AB00'), //Belarus
  58. array('BY13 NBRB 3600 900000002Z00AB00'), //Belarus
  59. array('BY22NB23324232T78YR7823HR32U'), //Belarus
  60. array('HR12 1001 0051 8630 0016 0'), //Croatia
  61. array('CY17 0020 0128 0000 0012 0052 7600'), //Cyprus
  62. array('CZ65 0800 0000 1920 0014 5399'), //Czech Republic
  63. array('DK50 0040 0440 1162 43'), //Denmark
  64. array('EE38 2200 2210 2014 5685'), //Estonia
  65. array('FO97 5432 0388 8999 44'), //Faroe Islands
  66. array('FI21 1234 5600 0007 85'), //Finland
  67. array('FR14 2004 1010 0505 0001 3M02 606'), //France
  68. array('GE29 NB00 0000 0101 9049 17'), //Georgia
  69. array('DE89 3704 0044 0532 0130 00'), //Germany
  70. array('GI75 NWBK 0000 0000 7099 453'), //Gibraltar
  71. array('GR16 0110 1250 0000 0001 2300 695'), //Greece
  72. array('GL56 0444 9876 5432 10'), //Greenland
  73. array('HU42 1177 3016 1111 1018 0000 0000'), //Hungary
  74. array('IS14 0159 2600 7654 5510 7303 39'), //Iceland
  75. array('IE29 AIBK 9311 5212 3456 78'), //Ireland
  76. array('IL62 0108 0000 0009 9999 999'), //Israel
  77. array('IT40 S054 2811 1010 0000 0123 456'), //Italy
  78. array('LV80 BANK 0000 4351 9500 1'), //Latvia
  79. array('LB62 0999 0000 0001 0019 0122 9114'), //Lebanon
  80. array('LI21 0881 0000 2324 013A A'), //Liechtenstein
  81. array('LT12 1000 0111 0100 1000'), //Lithuania
  82. array('LU28 0019 4006 4475 0000'), //Luxembourg
  83. array('MK072 5012 0000 0589 84'), //Macedonia
  84. array('MT84 MALT 0110 0001 2345 MTLC AST0 01S'), //Malta
  85. array('MU17 BOMM 0101 1010 3030 0200 000M UR'), //Mauritius
  86. array('MD24 AG00 0225 1000 1310 4168'), //Moldova
  87. array('MC93 2005 2222 1001 1223 3M44 555'), //Monaco
  88. array('ME25 5050 0001 2345 6789 51'), //Montenegro
  89. array('NL39 RABO 0300 0652 64'), //Netherlands
  90. array('NO93 8601 1117 947'), //Norway
  91. array('PK36 SCBL 0000 0011 2345 6702'), //Pakistan
  92. array('PL60 1020 1026 0000 0422 7020 1111'), //Poland
  93. array('PT50 0002 0123 1234 5678 9015 4'), //Portugal
  94. array('RO49 AAAA 1B31 0075 9384 0000'), //Romania
  95. array('SM86 U032 2509 8000 0000 0270 100'), //San Marino
  96. array('SA03 8000 0000 6080 1016 7519'), //Saudi Arabia
  97. array('RS35 2600 0560 1001 6113 79'), //Serbia
  98. array('SK31 1200 0000 1987 4263 7541'), //Slovak Republic
  99. array('SI56 1910 0000 0123 438'), //Slovenia
  100. array('ES80 2310 0001 1800 0001 2345'), //Spain
  101. array('SE35 5000 0000 0549 1000 0003'), //Sweden
  102. array('CH93 0076 2011 6238 5295 7'), //Switzerland
  103. array('TN59 1000 6035 1835 9847 8831'), //Tunisia
  104. array('TR33 0006 1005 1978 6457 8413 26'), //Turkey
  105. array('AE07 0331 2345 6789 0123 456'), //UAE
  106. array('GB12 CPBK 0892 9965 0449 91'), //United Kingdom
  107. //Extended country list
  108. //http://www.nordea.com/Our+services/International+products+and+services/Cash+Management/IBAN+countries/908462.html
  109. // https://www.swift.com/sites/default/files/resources/iban_registry.pdf
  110. array('AO06000600000100037131174'), //Angola
  111. array('AZ21NABZ00000000137010001944'), //Azerbaijan
  112. array('BH29BMAG1299123456BH00'), //Bahrain
  113. array('BJ11B00610100400271101192591'), //Benin
  114. array('BR9700360305000010009795493P1'), // Brazil
  115. array('BR1800000000141455123924100C2'), // Brazil
  116. array('VG96VPVG0000012345678901'), //British Virgin Islands
  117. array('BF1030134020015400945000643'), //Burkina Faso
  118. array('BI43201011067444'), //Burundi
  119. array('CM2110003001000500000605306'), //Cameroon
  120. array('CV64000300004547069110176'), //Cape Verde
  121. array('FR7630007000110009970004942'), //Central African Republic
  122. array('CG5230011000202151234567890'), //Congo
  123. array('CR05015202001026284066'), //Costa Rica
  124. array('DO28BAGR00000001212453611324'), //Dominican Republic
  125. array('GT82TRAJ01020000001210029690'), //Guatemala
  126. array('IR580540105180021273113007'), //Iran
  127. array('IL620108000000099999999'), //Israel
  128. array('CI05A00060174100178530011852'), //Ivory Coast
  129. array('JO94CBJO0010000000000131000302'), // Jordan
  130. array('KZ176010251000042993'), //Kazakhstan
  131. array('KW74NBOK0000000000001000372151'), //Kuwait
  132. array('LB30099900000001001925579115'), //Lebanon
  133. array('MG4600005030010101914016056'), //Madagascar
  134. array('ML03D00890170001002120000447'), //Mali
  135. array('MR1300012000010000002037372'), //Mauritania
  136. array('MU17BOMM0101101030300200000MUR'), //Mauritius
  137. array('MZ59000100000011834194157'), //Mozambique
  138. array('PS92PALS000000000400123456702'), //Palestinian Territory
  139. array('QA58DOHB00001234567890ABCDEFG'), //Qatar
  140. array('XK051212012345678906'), //Republic of Kosovo
  141. array('PT50000200000163099310355'), //Sao Tome and Principe
  142. array('SA0380000000608010167519'), //Saudi Arabia
  143. array('SN12K00100152000025690007542'), //Senegal
  144. array('TL380080012345678910157'), //Timor-Leste
  145. array('TN5914207207100707129648'), //Tunisia
  146. array('TR330006100519786457841326'), //Turkey
  147. array('UA213223130000026007233566001'), //Ukraine
  148. array('AE260211000000230064016'), //United Arab Emirates
  149. );
  150. }
  151. /**
  152. * @dataProvider getIbansWithInvalidFormat
  153. */
  154. public function testIbansWithInvalidFormat($iban)
  155. {
  156. $this->assertViolationRaised($iban, Iban::INVALID_FORMAT_ERROR);
  157. }
  158. public function getIbansWithInvalidFormat()
  159. {
  160. return array(
  161. array('AL47 2121 1009 0000 0002 3569 874'), //Albania
  162. array('AD12 0001 2030 2003 5910 010'), //Andorra
  163. array('AT61 1904 3002 3457 320'), //Austria
  164. array('AZ21 NABZ 0000 0000 1370 1000 194'), //Azerbaijan
  165. array('AZ21 N1BZ 0000 0000 1370 1000 1944'), //Azerbaijan
  166. array('BH67 BMAG 0000 1299 1234 5'), //Bahrain
  167. array('BH67 B2AG 0000 1299 1234 56'), //Bahrain
  168. array('BE62 5100 0754 7061 2'), //Belgium
  169. array('BA39 1290 0794 0102 8494 4'), //Bosnia and Herzegovina
  170. array('BG80 BNBG 9661 1020 3456 7'), //Bulgaria
  171. array('BG80 B2BG 9661 1020 3456 78'), //Bulgaria
  172. array('BY 13 NBRB 3600 900000002Z00AB001'), //Belarus
  173. array('BY 13 NBRB 3600 900000002Z00AB0'), //Belarus
  174. array('BYRO NBRB 3600 900000002Z00AB0'), //Belarus
  175. array('BY 13 3600 NBRB 900000002Z00AB05'), //Belarus
  176. array('HR12 1001 0051 8630 0016 01'), //Croatia
  177. array('CY17 0020 0128 0000 0012 0052 7600 1'), //Cyprus
  178. array('CZ65 0800 0000 1920 0014 5399 1'), //Czech Republic
  179. array('DK50 0040 0440 1162 431'), //Denmark
  180. array('EE38 2200 2210 2014 5685 1'), //Estonia
  181. array('FO97 5432 0388 8999 441'), //Faroe Islands
  182. array('FI21 1234 5600 0007 851'), //Finland
  183. array('FR14 2004 1010 0505 0001 3M02 6061'), //France
  184. array('GE29 NB00 0000 0101 9049 171'), //Georgia
  185. array('DE89 3704 0044 0532 0130 001'), //Germany
  186. array('GI75 NWBK 0000 0000 7099 4531'), //Gibraltar
  187. array('GR16 0110 1250 0000 0001 2300 6951'), //Greece
  188. array('GL56 0444 9876 5432 101'), //Greenland
  189. array('HU42 1177 3016 1111 1018 0000 0000 1'), //Hungary
  190. array('IS14 0159 2600 7654 5510 7303 391'), //Iceland
  191. array('IE29 AIBK 9311 5212 3456 781'), //Ireland
  192. array('IL62 0108 0000 0009 9999 9991'), //Israel
  193. array('IT40 S054 2811 1010 0000 0123 4561'), //Italy
  194. array('LV80 BANK 0000 4351 9500 11'), //Latvia
  195. array('LB62 0999 0000 0001 0019 0122 9114 1'), //Lebanon
  196. array('LI21 0881 0000 2324 013A A1'), //Liechtenstein
  197. array('LT12 1000 0111 0100 1000 1'), //Lithuania
  198. array('LU28 0019 4006 4475 0000 1'), //Luxembourg
  199. array('MK072 5012 0000 0589 84 1'), //Macedonia
  200. array('MT84 MALT 0110 0001 2345 MTLC AST0 01SA'), //Malta
  201. array('MU17 BOMM 0101 1010 3030 0200 000M URA'), //Mauritius
  202. array('MD24 AG00 0225 1000 1310 4168 1'), //Moldova
  203. array('MC93 2005 2222 1001 1223 3M44 5551'), //Monaco
  204. array('ME25 5050 0001 2345 6789 511'), //Montenegro
  205. array('NL39 RABO 0300 0652 641'), //Netherlands
  206. array('NO93 8601 1117 9471'), //Norway
  207. array('PK36 SCBL 0000 0011 2345 6702 1'), //Pakistan
  208. array('PL60 1020 1026 0000 0422 7020 1111 1'), //Poland
  209. array('PT50 0002 0123 1234 5678 9015 41'), //Portugal
  210. array('RO49 AAAA 1B31 0075 9384 0000 1'), //Romania
  211. array('SM86 U032 2509 8000 0000 0270 1001'), //San Marino
  212. array('SA03 8000 0000 6080 1016 7519 1'), //Saudi Arabia
  213. array('RS35 2600 0560 1001 6113 791'), //Serbia
  214. array('SK31 1200 0000 1987 4263 7541 1'), //Slovak Republic
  215. array('SI56 1910 0000 0123 4381'), //Slovenia
  216. array('ES80 2310 0001 1800 0001 2345 1'), //Spain
  217. array('SE35 5000 0000 0549 1000 0003 1'), //Sweden
  218. array('CH93 0076 2011 6238 5295 71'), //Switzerland
  219. array('TN59 1000 6035 1835 9847 8831 1'), //Tunisia
  220. array('TR33 0006 1005 1978 6457 8413 261'), //Turkey
  221. array('AE07 0331 2345 6789 0123 4561'), //UAE
  222. array('GB12 CPBK 0892 9965 0449 911'), //United Kingdom
  223. //Extended country list
  224. array('AO060006000001000371311741'), //Angola
  225. array('AZ21NABZ000000001370100019441'), //Azerbaijan
  226. array('BH29BMAG1299123456BH001'), //Bahrain
  227. array('BJ11B006101004002711011925911'), //Benin
  228. array('BR9700360305000010009795493P11'), // Brazil
  229. array('BR1800000000141455123924100C21'), // Brazil
  230. array('VG96VPVG00000123456789011'), //British Virgin Islands
  231. array('BF10301340200154009450006431'), //Burkina Faso
  232. array('BI432010110674441'), //Burundi
  233. array('CM21100030010005000006053061'), //Cameroon
  234. array('CV640003000045470691101761'), //Cape Verde
  235. array('FR76300070001100099700049421'), //Central African Republic
  236. array('CG52300110002021512345678901'), //Congo
  237. array('CR05152020010262840661'), //Costa Rica
  238. array('CR0515202001026284066'), //Costa Rica
  239. array('DO28BAGR000000012124536113241'), //Dominican Republic
  240. array('GT82TRAJ010200000012100296901'), //Guatemala
  241. array('IR5805401051800212731130071'), //Iran
  242. array('IL6201080000000999999991'), //Israel
  243. array('CI05A000601741001785300118521'), //Ivory Coast
  244. array('JO94CBJO00100000000001310003021'), // Jordan
  245. array('KZ1760102510000429931'), //Kazakhstan
  246. array('KW74NBOK00000000000010003721511'), //Kuwait
  247. array('LB300999000000010019255791151'), //Lebanon
  248. array('MG46000050300101019140160561'), //Madagascar
  249. array('ML03D008901700010021200004471'), //Mali
  250. array('MR13000120000100000020373721'), //Mauritania
  251. array('MU17BOMM0101101030300200000MUR1'), //Mauritius
  252. array('MZ590001000000118341941571'), //Mozambique
  253. array('PS92PALS0000000004001234567021'), //Palestinian Territory
  254. array('QA58DOHB00001234567890ABCDEFG1'), //Qatar
  255. array('XK0512120123456789061'), //Republic of Kosovo
  256. array('PT500002000001630993103551'), //Sao Tome and Principe
  257. array('SA03800000006080101675191'), //Saudi Arabia
  258. array('SN12K001001520000256900075421'), //Senegal
  259. array('TL3800800123456789101571'), //Timor-Leste
  260. array('TN59142072071007071296481'), //Tunisia
  261. array('TR3300061005197864578413261'), //Turkey
  262. array('UA21AAAA1300000260072335660012'), //Ukraine
  263. array('AE2602110000002300640161'), //United Arab Emirates
  264. );
  265. }
  266. /**
  267. * @dataProvider getIbansWithValidFormatButIncorrectChecksum
  268. */
  269. public function testIbansWithValidFormatButIncorrectChecksum($iban)
  270. {
  271. $this->assertViolationRaised($iban, Iban::CHECKSUM_FAILED_ERROR);
  272. }
  273. public function getIbansWithValidFormatButIncorrectChecksum()
  274. {
  275. return array(
  276. array('AL47 2121 1009 0000 0002 3569 8742'), //Albania
  277. array('AD12 0001 2030 2003 5910 0101'), //Andorra
  278. array('AT61 1904 3002 3457 3202'), //Austria
  279. array('AZ21 NABZ 0000 0000 1370 1000 1945'), //Azerbaijan
  280. array('BH67 BMAG 0000 1299 1234 57'), //Bahrain
  281. array('BE62 5100 0754 7062'), //Belgium
  282. array('BA39 1290 0794 0102 8495'), //Bosnia and Herzegovina
  283. array('BG80 BNBG 9661 1020 3456 79'), //Bulgaria
  284. array('BY90 NBRB 3600 900000002Z00AB00'), //Belarus
  285. array('HR12 1001 0051 8630 0016 1'), //Croatia
  286. array('CY17 0020 0128 0000 0012 0052 7601'), //Cyprus
  287. array('CZ65 0800 0000 1920 0014 5398'), //Czech Republic
  288. array('DK50 0040 0440 1162 44'), //Denmark
  289. array('EE38 2200 2210 2014 5684'), //Estonia
  290. array('FO97 5432 0388 8999 43'), //Faroe Islands
  291. array('FI21 1234 5600 0007 84'), //Finland
  292. array('FR14 2004 1010 0505 0001 3M02 605'), //France
  293. array('GE29 NB00 0000 0101 9049 16'), //Georgia
  294. array('DE89 3704 0044 0532 0130 01'), //Germany
  295. array('GI75 NWBK 0000 0000 7099 452'), //Gibraltar
  296. array('GR16 0110 1250 0000 0001 2300 694'), //Greece
  297. array('GL56 0444 9876 5432 11'), //Greenland
  298. array('HU42 1177 3016 1111 1018 0000 0001'), //Hungary
  299. array('IS14 0159 2600 7654 5510 7303 38'), //Iceland
  300. array('IE29 AIBK 9311 5212 3456 79'), //Ireland
  301. array('IL62 0108 0000 0009 9999 998'), //Israel
  302. array('IT40 S054 2811 1010 0000 0123 457'), //Italy
  303. array('LV80 BANK 0000 4351 9500 2'), //Latvia
  304. array('LB62 0999 0000 0001 0019 0122 9115'), //Lebanon
  305. array('LI21 0881 0000 2324 013A B'), //Liechtenstein
  306. array('LT12 1000 0111 0100 1001'), //Lithuania
  307. array('LU28 0019 4006 4475 0001'), //Luxembourg
  308. array('MK072 5012 0000 0589 85'), //Macedonia
  309. array('MT84 MALT 0110 0001 2345 MTLC AST0 01T'), //Malta
  310. array('MU17 BOMM 0101 1010 3030 0200 000M UP'), //Mauritius
  311. array('MD24 AG00 0225 1000 1310 4169'), //Moldova
  312. array('MC93 2005 2222 1001 1223 3M44 554'), //Monaco
  313. array('ME25 5050 0001 2345 6789 52'), //Montenegro
  314. array('NL39 RABO 0300 0652 65'), //Netherlands
  315. array('NO93 8601 1117 948'), //Norway
  316. array('PK36 SCBL 0000 0011 2345 6703'), //Pakistan
  317. array('PL60 1020 1026 0000 0422 7020 1112'), //Poland
  318. array('PT50 0002 0123 1234 5678 9015 5'), //Portugal
  319. array('RO49 AAAA 1B31 0075 9384 0001'), //Romania
  320. array('SM86 U032 2509 8000 0000 0270 101'), //San Marino
  321. array('SA03 8000 0000 6080 1016 7518'), //Saudi Arabia
  322. array('RS35 2600 0560 1001 6113 78'), //Serbia
  323. array('SK31 1200 0000 1987 4263 7542'), //Slovak Republic
  324. array('SI56 1910 0000 0123 439'), //Slovenia
  325. array('ES80 2310 0001 1800 0001 2346'), //Spain
  326. array('SE35 5000 0000 0549 1000 0004'), //Sweden
  327. array('CH93 0076 2011 6238 5295 8'), //Switzerland
  328. array('TN59 1000 6035 1835 9847 8832'), //Tunisia
  329. array('TR33 0006 1005 1978 6457 8413 27'), //Turkey
  330. array('AE07 0331 2345 6789 0123 457'), //UAE
  331. array('GB12 CPBK 0892 9965 0449 92'), //United Kingdom
  332. //Extended country list
  333. array('AO06000600000100037131175'), //Angola
  334. array('AZ21NABZ00000000137010001945'), //Azerbaijan
  335. array('BH29BMAG1299123456BH01'), //Bahrain
  336. array('BJ11B00610100400271101192592'), //Benin
  337. array('BR9700360305000010009795493P2'), // Brazil
  338. array('BR1800000000141455123924100C3'), // Brazil
  339. array('VG96VPVG0000012345678902'), //British Virgin Islands
  340. array('BF1030134020015400945000644'), //Burkina Faso
  341. array('BI43201011067445'), //Burundi
  342. array('CM2110003001000500000605307'), //Cameroon
  343. array('CV64000300004547069110177'), //Cape Verde
  344. array('FR7630007000110009970004943'), //Central African Republic
  345. array('CG5230011000202151234567891'), //Congo
  346. array('CR96042332432534543564'), //Costa Rica
  347. array('DO28BAGR00000001212453611325'), //Dominican Republic
  348. array('GT82TRAJ01020000001210029691'), //Guatemala
  349. array('IR580540105180021273113008'), //Iran
  350. array('IL620108000000099999998'), //Israel
  351. array('CI05A00060174100178530011853'), //Ivory Coast
  352. array('JO94CBJO0010000000000131000303'), // Jordan
  353. array('KZ176010251000042994'), //Kazakhstan
  354. array('KW74NBOK0000000000001000372152'), //Kuwait
  355. array('LB30099900000001001925579116'), //Lebanon
  356. array('MG4600005030010101914016057'), //Madagascar
  357. array('ML03D00890170001002120000448'), //Mali
  358. array('MR1300012000010000002037373'), //Mauritania
  359. array('MU17BOMM0101101030300200000MUP'), //Mauritius
  360. array('MZ59000100000011834194158'), //Mozambique
  361. array('PS92PALS000000000400123456703'), //Palestinian Territory
  362. array('QA58DOHB00001234567890ABCDEFH'), //Qatar
  363. array('XK051212012345678907'), //Republic of Kosovo
  364. array('PT50000200000163099310356'), //Sao Tome and Principe
  365. array('SA0380000000608010167518'), //Saudi Arabia
  366. array('SN12K00100152000025690007543'), //Senegal
  367. array('TL380080012345678910158'), //Timor-Leste
  368. array('TN5914207207100707129649'), //Tunisia
  369. array('TR330006100519786457841327'), //Turkey
  370. array('UA213223130000026007233566002'), //Ukraine
  371. array('AE260211000000230064017'), //United Arab Emirates
  372. );
  373. }
  374. /**
  375. * @dataProvider getUnsupportedCountryCodes
  376. */
  377. public function testIbansWithUnsupportedCountryCode($countryCode)
  378. {
  379. $this->assertViolationRaised($countryCode.'260211000000230064016', Iban::NOT_SUPPORTED_COUNTRY_CODE_ERROR);
  380. }
  381. public function getUnsupportedCountryCodes()
  382. {
  383. return array(
  384. array('AG'),
  385. array('AI'),
  386. array('AQ'),
  387. array('AS'),
  388. array('AW'),
  389. );
  390. }
  391. public function testIbansWithInvalidCharacters()
  392. {
  393. $this->assertViolationRaised('CH930076201162385295]', Iban::INVALID_CHARACTERS_ERROR);
  394. }
  395. /**
  396. * @dataProvider getIbansWithInvalidCountryCode
  397. */
  398. public function testIbansWithInvalidCountryCode($iban)
  399. {
  400. $this->assertViolationRaised($iban, Iban::INVALID_COUNTRY_CODE_ERROR);
  401. }
  402. public function getIbansWithInvalidCountryCode()
  403. {
  404. return array(
  405. array('0750447346'),
  406. array('2X0750447346'),
  407. array('A20750447346'),
  408. );
  409. }
  410. private function assertViolationRaised($iban, $code)
  411. {
  412. $constraint = new Iban(array(
  413. 'message' => 'myMessage',
  414. ));
  415. $this->validator->validate($iban, $constraint);
  416. $this->buildViolation('myMessage')
  417. ->setParameter('{{ value }}', '"'.$iban.'"')
  418. ->setCode($code)
  419. ->assertRaised();
  420. }
  421. }