├── .gitignore ├── .scrutinizer.yml ├── .styleci.yml ├── .travis.yml ├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── composer.json ├── phpunit.xml ├── src ├── config │ ├── .gitkeep │ └── countries.php └── package │ ├── Console │ └── Commands │ │ ├── Base.php │ │ └── Update.php │ ├── Facade.php │ ├── Http │ └── Controllers │ │ └── Flag.php │ └── ServiceProvider.php └── tests ├── CountriesTest.php ├── TestCase.php ├── ValidationTest.php └── bootstrap.php /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | /coverage 3 | /tmp 4 | /src/data/tmp 5 | /src/data/third-party/ 6 | composer.phar 7 | composer.lock 8 | .phpunit.result.cache 9 | -------------------------------------------------------------------------------- /.scrutinizer.yml: -------------------------------------------------------------------------------- 1 | checks: 2 | php: 3 | remove_extra_empty_lines: true 4 | remove_php_closing_tag: true 5 | remove_trailing_whitespace: true 6 | fix_use_statements: 7 | remove_unused: true 8 | preserve_multiple: false 9 | preserve_blanklines: true 10 | order_alphabetically: true 11 | fix_php_opening_tag: true 12 | fix_linefeed: true 13 | fix_line_ending: true 14 | fix_identation_4spaces: true 15 | fix_doc_comments: true 16 | 17 | filter: 18 | paths: [src/*] 19 | excluded_paths: ["tests/*"] 20 | 21 | coding_style: 22 | php: { } 23 | 24 | tools: 25 | external_code_coverage: true 26 | -------------------------------------------------------------------------------- /.styleci.yml: -------------------------------------------------------------------------------- 1 | preset: laravel 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 7.0 5 | - 7.1 6 | - 7.2 7 | - 7.3 8 | # - nightly 9 | 10 | env: 11 | matrix: 12 | - COMPOSER_FLAGS="" 13 | 14 | # This triggers builds to run on the new TravisCI infrastructure. 15 | # See: http://docs.travis-ci.com/user/workers/container-based-infrastructure/ 16 | sudo: false 17 | 18 | ## Cache composer 19 | cache: 20 | directories: 21 | - $HOME/.composer/cache 22 | 23 | before_script: 24 | - '[[ "$TRAVIS_PHP_VERSION" == "7.2" || "$TRAVIS_PHP_VERSION" == "nightly" ]] || phpenv config-rm xdebug.ini' 25 | - travis_retry composer self-update 26 | - travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-dist 27 | 28 | script: 29 | - travis_wait vendor/bin/phpunit --coverage-clover=coverage.clover 30 | 31 | after_script: 32 | - | 33 | if [[ "$TRAVIS_PHP_VERSION" == '7.2' ]]; then 34 | wget https://scrutinizer-ci.com/ocular.phar 35 | php ocular.phar code-coverage:upload --format=php-clover coverage.clover 36 | fi 37 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## 0.6.0 - 2018-08-19 4 | ### Changed 5 | - Please check countries package changelog 6 | ### Breaking Change 7 | If you are using this package caching system, you have to Updated cache.services in the contries.php configuration file. Ensure to update your configuration the below before updating: 8 | ``` 9 | 'cache' => [ 10 | 'service' => PragmaRX\Countries\Package\Services\Cache\Service::class, 11 | ] 12 | ``` 13 | 14 | ## 0.1.0 - 2018-01-22 15 | ### Added 16 | - First version 17 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016, Antonio Carlos Ribeiro 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 8 | 9 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 10 | 11 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 12 | 13 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | Countries for Laravel 3 |

4 | 5 | ![World Map](https://raw.githubusercontent.com/antonioribeiro/countries/master/docs/world-map-political-of-the-2013-nations-online-project-best.jpg) 6 | 7 |

8 | Latest Stable Version 9 | License 10 | Code Quality 11 | Build 12 |

13 |

14 | Coverage 15 | PHP 16 | Downloads 17 | StyleCI 18 |

19 | 20 | ### What does it gives you? 21 | 22 | This package has all sorts of information about countries: 23 | 24 | | info | items | 25 | ------------------|-------:| 26 | | taxes | 32 | 27 | | geometry maps | 248 | 28 | | topology maps | 248 | 29 | | currencies | 256 | 30 | | countries | 266 | 31 | | timezones | 423 | 32 | | borders | 649 | 33 | | flags | 1,570 | 34 | | states | 4,526 | 35 | | cities | 7,376 | 36 | | timezones times | 81,153 | 37 | 38 | ### Validation 39 | 40 | The validation is extending Laravel's validation, so you can use it like any other validation rules, like 41 | 42 | ```php 43 | /** 44 | * Store a new blog post. 45 | * 46 | * @param Request $request 47 | * @return Response 48 | */ 49 | public function store(Request $request) 50 | { 51 | $this->validate($request, [ 52 | 'title' => 'required|unique:posts|max:255', 53 | 'body' => 'required', 54 | 'country' => 'country' //Checks if valid name.common 55 | ]); 56 | 57 | // The blog post is valid, store in database... 58 | } 59 | ``` 60 | 61 | Which validation rules there is and what there name should be, can all be configured in the configuration file. 62 | 63 | ```php 64 | 'validation' => [ 65 | 'rules' => [ 66 | 'countryCommon' => 'name.common' 67 | ] 68 | ] 69 | ``` 70 | 71 | By changing the configuration like this, we can now access the property `name.common`, by the validation rule `countryCommon` 72 | 73 | You have to define all the validations rules in settings, only a few is defined by default, the default is 74 | 75 | ```php 76 | 'rules' => [ 77 | 'country' => 'name.common', 78 | 'cca2', 79 | 'cca3', 80 | 'ccn3', 81 | 'cioc', 82 | 'currencies' => 'ISO4217', 83 | 'language', 84 | 'language_short' => 'ISO639_3', 85 | ] 86 | ``` 87 | 88 | ### Documentation 89 | 90 | This package is a Laravel bridge, please refer to the [main package repository](https://github.com/antonioribeiro/countries) for more information and docs. 91 | 92 | ## Requirements 93 | 94 | - PHP 7.0+ 95 | - Laravel 5.5+ 96 | 97 | ## Installing 98 | 99 | Use Composer to install it: 100 | 101 | ``` 102 | composer require pragmarx/countries-laravel 103 | ``` 104 | 105 | ## Publishing assets 106 | 107 | You can publish configuration by doing: 108 | ``` 109 | php artisan vendor:publish --provider=PragmaRX\\CountriesLaravel\\Package\\ServiceProvider 110 | ``` 111 | 112 | ## Usage 113 | 114 | After installing you'll have access to the Countries Façade, and the package is based on Laravel Collections, so you basically have access to all methods in Collections, like 115 | 116 | ```php 117 | $france = Countries::where('name.common', 'France'); 118 | ``` 119 | 120 | ## Flag routes 121 | 122 | You can refer directly to an SVG flag by linking 123 | 124 | ``` 125 | /pragmarx/countries/flag/download/.svg 126 | /pragmarx/countries/flag/file/.svg 127 | ``` 128 | 129 | Examples: 130 | 131 | ``` 132 | https://laravel.com/pragmarx/countries/flag/download/usa.svg 133 | https://laravel.com/pragmarx/countries/flag/file/usa.svg 134 | ``` 135 | 136 | http://pragmarx.test/pragmarx/countries/flag/file/usa.svg 137 | 138 | These routes can be turned off in the configuration file: 139 | 140 | ```php 141 | 'routes' => [ 142 | 'enabled' => false, 143 | ] 144 | ``` 145 | 146 | ## Author 147 | 148 | [Antonio Carlos Ribeiro](http://twitter.com/iantonioribeiro) 149 | 150 | ## License 151 | 152 | Countries is licensed under the MIT License - see the `LICENSE` file for details 153 | 154 | ## Contributing 155 | 156 | Pull requests and issues are more than welcome. 157 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pragmarx/countries-laravel", 3 | 4 | "description": "Countries for Laravel", 5 | 6 | "keywords": [ 7 | "laravel", 8 | "countries", 9 | "borders", 10 | "cities", 11 | "currencies", 12 | "flag", 13 | "geometry", 14 | "states", 15 | "taxes", 16 | "timezones", 17 | "topology" 18 | ], 19 | 20 | "license": "BSD-3-Clause", 21 | 22 | "authors": [ 23 | { 24 | "name": "Antonio Carlos Ribeiro", 25 | "email": "acr@antoniocarlosribeiro.com", 26 | "role": "Creator" 27 | } 28 | ], 29 | 30 | "require": { 31 | "php": ">=7.0", 32 | "laravel/framework": ">=5.3", 33 | "psr/simple-cache": "^1.0", 34 | "pragmarx/coollection": ">=0.6", 35 | "pragmarx/countries": ">=0.5.8" 36 | }, 37 | 38 | "require-dev": { 39 | "orchestra/testbench": "~3.0|~4.0|~5.0", 40 | "phpunit/phpunit": "~6.0|~7.0|~8.0|~9.0", 41 | "squizlabs/php_codesniffer": "^2.3", 42 | "colinodell/json5": "^1.0", 43 | "gasparesganga/php-shapefile": "^2.3" 44 | }, 45 | 46 | "autoload": { 47 | "psr-4": { 48 | "PragmaRX\\CountriesLaravel\\Package\\": "src/package" 49 | } 50 | }, 51 | 52 | "autoload-dev": { 53 | "psr-4": { 54 | "PragmaRX\\CountriesLaravel\\Tests\\": "tests/" 55 | } 56 | }, 57 | 58 | "scripts": { 59 | "test": "phpunit", 60 | "check-style": "phpcs -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src test", 61 | "fix-style": "phpcbf -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src test" 62 | }, 63 | 64 | "extra": { 65 | "laravel": { 66 | "providers": [ 67 | "PragmaRX\\CountriesLaravel\\Package\\ServiceProvider" 68 | ], 69 | "aliases": { 70 | "Countries": "PragmaRX\\CountriesLaravel\\Package\\Facade" 71 | } 72 | } 73 | }, 74 | 75 | "minimum-stability": "dev", 76 | 77 | "prefer-stable": true 78 | } 79 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | ./tests 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/config/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antonioribeiro/countries-laravel/0d83b2f197e5244ddc17885caf9fe96a31306693/src/config/.gitkeep -------------------------------------------------------------------------------- /src/config/countries.php: -------------------------------------------------------------------------------- 1 | [ 6 | 'enabled' => true, 7 | 8 | 'service' => PragmaRX\Countries\Package\Services\Cache\Service::class, 9 | 10 | 'duration' => 180, 11 | 12 | 'directory' => sys_get_temp_dir().'/__PRAGMARX_COUNTRIES__/cache', 13 | ], 14 | 15 | 'hydrate' => [ 16 | 'before' => true, 17 | 18 | 'after' => true, 19 | 20 | 'elements' => [ 21 | 'borders' => false, 22 | 'cities' => false, 23 | 'currencies' => false, 24 | 'flag' => false, 25 | 'geometry' => false, 26 | 'states' => false, 27 | 'taxes' => false, 28 | 'timezones' => false, 29 | 'timezones_times' => false, 30 | 'topology' => false, 31 | ], 32 | ], 33 | 34 | 'maps' => [ 35 | 'lca3' => 'cca3', 36 | 'currencies' => 'currency', 37 | ], 38 | 39 | 'routes' => [ 40 | 'enabled' => true, 41 | ], 42 | 43 | 'validation' => [ 44 | 'enabled' => true, 45 | 'rules' => [ 46 | 'country' => 'name.common', 47 | 'name' => 'name.common', 48 | 'nameCommon' => 'name.common', 49 | 'cca2', 50 | 'cca3', 51 | 'ccn3', 52 | 'cioc', 53 | 'currencies' => 'ISO4217', 54 | 'language_short' => 'ISO639_3', 55 | ], 56 | ], 57 | 58 | ]; 59 | -------------------------------------------------------------------------------- /src/package/Console/Commands/Base.php: -------------------------------------------------------------------------------- 1 | update($this); 40 | 41 | $this->info('Updated.'); 42 | } 43 | 44 | /** 45 | * Execute the console command. 46 | */ 47 | public function handle() 48 | { 49 | $this->fire(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/package/Facade.php: -------------------------------------------------------------------------------- 1 | first()->hydrateFlag(); 24 | } 25 | 26 | /** 27 | * Download flag action. 28 | * 29 | * @param $cca3 30 | * @return \Symfony\Component\HttpFoundation\BinaryFileResponse 31 | */ 32 | public function download($cca3) 33 | { 34 | return response()->download($this->getFlagPath($cca3)); 35 | } 36 | 37 | /** 38 | * File flag action. 39 | * 40 | * @param $cca3 41 | * @return \Symfony\Component\HttpFoundation\BinaryFileResponse 42 | */ 43 | public function file($cca3) 44 | { 45 | return response()->file($this->getFlagPath($cca3)); 46 | } 47 | 48 | /** 49 | * Get the flag path. 50 | * 51 | * @param $cca3 52 | * @return mixed 53 | */ 54 | protected function getFlagPath($cca3) 55 | { 56 | return $this->findCountryByCca3($cca3)->flag->svg_path; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/package/ServiceProvider.php: -------------------------------------------------------------------------------- 1 | publishes([ 34 | $this->getPackageConfigFile() => config_path('countries.php'), 35 | ], 'config'); 36 | } 37 | 38 | /** 39 | * Get the package config file path. 40 | * 41 | * @return string 42 | */ 43 | protected function getPackageConfigFile() 44 | { 45 | return __DIR__.'/../config/countries.php'; 46 | } 47 | 48 | /** 49 | * Merge configuration. 50 | */ 51 | protected function mergeConfig() 52 | { 53 | $this->mergeConfigFrom( 54 | $this->getPackageConfigFile(), 'countries' 55 | ); 56 | } 57 | 58 | /** 59 | * Bootstrap any application services. 60 | * 61 | * @return void 62 | */ 63 | public function boot() 64 | { 65 | if (config('countries.validation.enabled')) { 66 | $this->addValidators(); 67 | } 68 | } 69 | 70 | /** 71 | * Register any application services. 72 | * 73 | * @return void 74 | */ 75 | public function register() 76 | { 77 | $this->configurePaths(); 78 | 79 | $this->mergeConfig(); 80 | 81 | $this->registerService(); 82 | 83 | $this->registerUpdateCommand(); 84 | 85 | if (config('countries.routes.enabled')) { 86 | $this->registerRoutes(); 87 | } 88 | } 89 | 90 | /** 91 | * Register routes. 92 | */ 93 | protected function registerRoutes() 94 | { 95 | Route::get( 96 | '/pragmarx/countries/flag/file/{cca3}.svg', 97 | [ 98 | 'name' => 'pragmarx.countries.flag.file', 99 | 'uses' => '\PragmaRX\CountriesLaravel\Package\Http\Controllers\Flag@file', 100 | ] 101 | ); 102 | 103 | Route::get( 104 | '/pragmarx/countries/flag/download/{cca3}.svg', 105 | [ 106 | 'name' => 'pragmarx.countries.flag.download', 107 | 'uses' => '\PragmaRX\CountriesLaravel\Package\Http\Controllers\Flag@download', 108 | ] 109 | ); 110 | } 111 | 112 | /** 113 | * Register the service. 114 | */ 115 | protected function registerService() 116 | { 117 | $this->app->singleton('pragmarx.countries', function () { 118 | $hydrator = new Hydrator($config = new Config(config())); 119 | 120 | $cache = new Cache($config, app(config('countries.cache.service'))); 121 | 122 | $helper = new Helper($config); 123 | 124 | $repository = new Repository($cache, $hydrator, $helper, $config); 125 | 126 | $hydrator->setRepository($repository); 127 | 128 | return new CountriesService($config, $cache, $helper, $hydrator, $repository); 129 | }); 130 | } 131 | 132 | /** 133 | * Add validators. 134 | */ 135 | protected function addValidators() 136 | { 137 | foreach (config('countries.validation.rules') as $ruleName => $countryAttribute) { 138 | if (is_int($ruleName)) { 139 | $ruleName = $countryAttribute; 140 | } 141 | 142 | Validator::extend($ruleName, function ($attribute, $value) use ($countryAttribute) { 143 | return ! CountriesFacade::where($countryAttribute, $value)->isEmpty(); 144 | }, 'The :attribute must be a valid '.$ruleName.'.'); 145 | } 146 | } 147 | 148 | /** 149 | * Register update command. 150 | */ 151 | protected function registerUpdateCommand() 152 | { 153 | $this->app->singleton($command = 'countries.update.command', function () { 154 | return new Update(); 155 | }); 156 | 157 | $this->commands($command); 158 | } 159 | 160 | /** 161 | * Get the services provided by the provider. 162 | * 163 | * @return array 164 | */ 165 | public function provides() 166 | { 167 | return [ 168 | 'pragmarx.countries', 169 | 'countries.update.command', 170 | ]; 171 | } 172 | } 173 | -------------------------------------------------------------------------------- /tests/CountriesTest.php: -------------------------------------------------------------------------------- 1 | first(); 13 | 14 | $this->assertEquals($country->name->common, 'Brazil'); 15 | } 16 | 17 | public function testCountryHydration() 18 | { 19 | $country = Countries::where('name.common', 'Italy')->first()->hydrateBorders(); 20 | 21 | $this->assertEquals($country->name->common, 'Italy'); 22 | 23 | $this->assertEquals(6, $country->borders->count()); 24 | 25 | $this->assertEquals('Austria', $country->borders->first()->name->common); 26 | } 27 | 28 | public function testRoutes() 29 | { 30 | $crawler = $this->call('GET', 'pragmarx/countries/flag/file/usa.svg'); 31 | 32 | $this->assertEquals(false, $crawler->getContent()); 33 | 34 | $crawler = $this->call('GET', 'pragmarx/countries/flag/download/usa.svg'); 35 | 36 | $this->assertEquals(false, $crawler->getContent()); 37 | 38 | $crawler = $this->call('GET', 'pragmarx/countries/flag/file/xxx.svg'); 39 | 40 | $this->assertStringStartsWith('getContent()); 41 | } 42 | 43 | public function testCountEverything() 44 | { 45 | config(['countries.cache.enabled' => false]); 46 | 47 | ini_set('memory_limit', '2048M'); 48 | 49 | $results = [ 50 | 'countries' => 0, 51 | 'borders' => 0, 52 | 'cities' => 0, 53 | 'currencies' => 0, 54 | 'flags' => 0, 55 | 'geometry map' => 0, 56 | 'states' => 0, 57 | 'taxes' => 0, 58 | 'timezones' => 0, 59 | 'timezones times' => 0, 60 | 'topology map' => 0, 61 | ]; 62 | 63 | Countries::all()->map(function ($country) use (&$results) { 64 | $results['countries']++; 65 | 66 | $results['borders'] = $results['borders'] + $country->hydrate('borders')->borders->count(); 67 | 68 | $results['cities'] = $results['cities'] + $country->hydrate('cities')->cities->count(); 69 | 70 | $results['currencies'] = $results['currencies'] + $country->hydrate('currencies')->currencies->count(); 71 | 72 | $results['flags'] = $results['flags'] + $country->hydrate('flag')->flag->count(); 73 | 74 | $results['states'] = $results['states'] + $country->hydrate('states')->states->count(); 75 | 76 | $results['timezones'] = $results['timezones'] + $country->hydrate('timezones')->timezones->count(); 77 | 78 | $results['taxes'] = $results['taxes'] + $country->hydrate('taxes')->taxes->count(); 79 | 80 | $results['geometry map'] = $results['geometry map'] + ((string) $country->hydrate('geometry')->geometry == '' ? 0 : 1); 81 | 82 | $results['topology map'] = $results['topology map'] + ((string) $country->hydrate('topology')->topology == '' ? 0 : 1); 83 | 84 | $country = $country->hydrate(['timezones', 'timezones_times']); 85 | 86 | $results['timezones times'] = $results['timezones times'] + $country->timezones->reduce(function ($carry, $timezone) { 87 | return $timezone->times->count(); 88 | }, 0); 89 | }); 90 | 91 | $results = coollect($results)->sort(); 92 | 93 | $this->assertEquals($results->toArray(), [ 94 | 'taxes' => 33, 95 | 'geometry map' => 250, 96 | 'topology map' => 250, 97 | 'currencies' => 267, 98 | 'countries' => 267, 99 | 'timezones' => 425, 100 | 'borders' => 649, 101 | 'flags' => 1842, 102 | 'states' => 4526, 103 | 'cities' => 7393, 104 | 'timezones times' => 79594, 105 | ]); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /tests/TestCase.php: -------------------------------------------------------------------------------- 1 | 'Brazil'], ['country' => 'country']); 15 | $this->assertTrue($validator->passes()); 16 | 17 | // Valid country 18 | /** @var \Illuminate\Validation\Validator $validator */ 19 | $validator = Validator::make(['country' => 'Brazil'], ['country' => 'nameCommon']); 20 | $this->assertTrue($validator->passes()); 21 | 22 | // Valid country 23 | /** @var \Illuminate\Validation\Validator $validator */ 24 | $validator = Validator::make(['country' => 'Brazil'], ['country' => 'name']); 25 | $this->assertTrue($validator->passes()); 26 | 27 | // Change to Invalid country 28 | $validator->setData(['country' => 'NotACountry']); 29 | $this->assertFalse($validator->passes()); 30 | } 31 | 32 | public function testISOA3Rule() 33 | { 34 | // Valid country 35 | /** @var \Illuminate\Validation\Validator $validator */ 36 | $validator = Validator::make(['country' => 'BRA'], ['country' => 'cca3']); 37 | $this->assertTrue($validator->passes()); 38 | 39 | // Change to Invalid country 40 | $validator->setData(['country' => 'NotACountry']); 41 | $this->assertFalse($validator->passes()); 42 | } 43 | 44 | public function testCurrency() 45 | { 46 | // Valid currency 47 | $validator = Validator::make(['country' => 'EUR'], ['country' => 'currencies']); 48 | $this->assertTrue($validator->passes()); 49 | 50 | // Change to invalid currency 51 | $validator->setData(['country' => 'NotACountry']); 52 | $this->assertFalse($validator->passes()); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /tests/bootstrap.php: -------------------------------------------------------------------------------- 1 |