diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml new file mode 100644 index 0000000..66fe497 --- /dev/null +++ b/.github/workflows/run-tests.yml @@ -0,0 +1,51 @@ +name: run-tests + +on: + push: + pull_request: + schedule: + - cron: '0 0 * * *' + +jobs: + run-tests: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + php: [7.4, 7.3, 7.2, 7.1] + laravel: [8.*, 7.*, 6.*, 5.8.*] + dependency-version: [prefer-lowest, prefer-stable] + include: + - laravel: 8.* + testbench: 6.* + - laravel: 7.* + testbench: 5.* + - laravel: 6.* + testbench: 4.* + + name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Cache dependencies + uses: actions/cache@v2 + with: + path: ~/.composer/cache/files + key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: mbstring, pdo, pdo_sqlite + coverage: none + + - name: Install dependencies + run: | + composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update + composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest + + - name: Execute tests + run: vendor/bin/phpunit \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..382f5a0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/vendor +.phpunit.result.cache +composer.lock \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..3050d2b --- /dev/null +++ b/composer.json @@ -0,0 +1,39 @@ +{ + "name": "danharrin/squire", + "description": "A collection of static Eloquent models for common fixture data.", + "keywords": [ + "squire", + "squire", + "eloquent", + "laravel" + ], + "homepage": "https://github.com/danharrin/squire", + "type": "library", + "license": "MIT", + "authors": [ + { + "name": "Dan Harrin", + "email": "dan@danharrin.com" + } + ], + "require": { + "php": "^7.1.3", + "calebporzio/sushi": "^2.1", + "illuminate/database": "^5.8 || ^6.0 || ^7.0 || ^8.0", + "illuminate/support": "^5.8 || ^6.0 || ^7.0 || ^8.0" + }, + "require-dev": { + "orchestra/testbench": "^6.2", + "phpunit/phpunit": "^9.4" + }, + "autoload": { + "psr-4": { + "Squire\\": "src" + } + }, + "config": { + "sort-packages": true + }, + "minimum-stability": "dev", + "prefer-stable": true +} diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..290242a --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,13 @@ + + + + + src + + + + + tests + + + diff --git a/resources/countries.php b/resources/countries.php new file mode 100644 index 0000000..410a5f6 --- /dev/null +++ b/resources/countries.php @@ -0,0 +1,1214 @@ + 'af', + 'dial_code' => '93', + 'name' => 'Afghanistan', + ], + [ + 'id' => 'ax', + 'dial_code' => '358', + 'name' => 'Aland Islands', + ], + [ + 'id' => 'al', + 'dial_code' => '355', + 'name' => 'Albania', + ], + [ + 'id' => 'dz', + 'dial_code' => '213', + 'name' => 'Algeria', + ], + [ + 'id' => 'as', + 'dial_code' => '1684', + 'name' => 'AmericanSamoa', + ], + [ + 'id' => 'ad', + 'dial_code' => '376', + 'name' => 'Andorra', + ], + [ + 'id' => 'ao', + 'dial_code' => '244', + 'name' => 'Angola', + ], + [ + 'id' => 'ai', + 'dial_code' => '1264', + 'name' => 'Anguilla', + ], + [ + 'id' => 'aq', + 'dial_code' => '672', + 'name' => 'Antarctica', + ], + [ + 'id' => 'ag', + 'dial_code' => '1268', + 'name' => 'Antigua and Barbuda', + ], + [ + 'id' => 'ar', + 'dial_code' => '54', + 'name' => 'Argentina', + ], + [ + 'id' => 'am', + 'dial_code' => '374', + 'name' => 'Armenia', + ], + [ + 'id' => 'aw', + 'dial_code' => '297', + 'name' => 'Aruba', + ], + [ + 'id' => 'au', + 'dial_code' => '61', + 'name' => 'Australia', + ], + [ + 'id' => 'at', + 'dial_code' => '43', + 'name' => 'Austria', + ], + [ + 'id' => 'az', + 'dial_code' => '994', + 'name' => 'Azerbaijan', + ], + [ + 'id' => 'bs', + 'dial_code' => '1242', + 'name' => 'Bahamas', + ], + [ + 'id' => 'bh', + 'dial_code' => '973', + 'name' => 'Bahrain', + ], + [ + 'id' => 'bd', + 'dial_code' => '880', + 'name' => 'Bangladesh', + ], + [ + 'id' => 'bb', + 'dial_code' => '1246', + 'name' => 'Barbados', + ], + [ + 'id' => 'by', + 'dial_code' => '375', + 'name' => 'Belarus', + ], + [ + 'id' => 'be', + 'dial_code' => '32', + 'name' => 'Belgium', + ], + [ + 'id' => 'bz', + 'dial_code' => '501', + 'name' => 'Belize', + ], + [ + 'id' => 'bj', + 'dial_code' => '229', + 'name' => 'Benin', + ], + [ + 'id' => 'bm', + 'dial_code' => '1441', + 'name' => 'Bermuda', + ], + [ + 'id' => 'bt', + 'dial_code' => '975', + 'name' => 'Bhutan', + ], + [ + 'id' => 'bo', + 'dial_code' => '591', + 'name' => 'Bolivia, Plurinational State of bolivia', + ], + [ + 'id' => 'ba', + 'dial_code' => '387', + 'name' => 'Bosnia and Herzegovina', + ], + [ + 'id' => 'bw', + 'dial_code' => '267', + 'name' => 'Botswana', + ], + [ + 'id' => 'br', + 'dial_code' => '55', + 'name' => 'Brazil', + ], + [ + 'id' => 'io', + 'dial_code' => '246', + 'name' => 'British Indian Ocean Territory', + ], + [ + 'id' => 'bn', + 'dial_code' => '673', + 'name' => 'Brunei Darussalam', + ], + [ + 'id' => 'bg', + 'dial_code' => '359', + 'name' => 'Bulgaria', + ], + [ + 'id' => 'bf', + 'dial_code' => '226', + 'name' => 'Burkina Faso', + ], + [ + 'id' => 'bi', + 'dial_code' => '257', + 'name' => 'Burundi', + ], + [ + 'id' => 'kh', + 'dial_code' => '855', + 'name' => 'Cambodia', + ], + [ + 'id' => 'cm', + 'dial_code' => '237', + 'name' => 'Cameroon', + ], + [ + 'id' => 'ca', + 'dial_code' => '1', + 'name' => 'Canada', + ], + [ + 'id' => 'cv', + 'dial_code' => '238', + 'name' => 'Cape Verde', + ], + [ + 'id' => 'ky', + 'dial_code' => ' 345', + 'name' => 'Cayman Islands', + ], + [ + 'id' => 'cf', + 'dial_code' => '236', + 'name' => 'Central African Republic', + ], + [ + 'id' => 'td', + 'dial_code' => '235', + 'name' => 'Chad', + ], + [ + 'id' => 'cl', + 'dial_code' => '56', + 'name' => 'Chile', + ], + [ + 'id' => 'cn', + 'dial_code' => '86', + 'name' => 'China', + ], + [ + 'id' => 'cx', + 'dial_code' => '61', + 'name' => 'Christmas Island', + ], + [ + 'id' => 'cc', + 'dial_code' => '61', + 'name' => 'Cocos (Keeling) Islands', + ], + [ + 'id' => 'co', + 'dial_code' => '57', + 'name' => 'Colombia', + ], + [ + 'id' => 'km', + 'dial_code' => '269', + 'name' => 'Comoros', + ], + [ + 'id' => 'cg', + 'dial_code' => '242', + 'name' => 'Congo', + ], + [ + 'id' => 'cd', + 'dial_code' => '243', + 'name' => 'Congo, The Democratic Republic of the Congo', + ], + [ + 'id' => 'ck', + 'dial_code' => '682', + 'name' => 'Cook Islands', + ], + [ + 'id' => 'cr', + 'dial_code' => '506', + 'name' => 'Costa Rica', + ], + [ + 'id' => 'ci', + 'dial_code' => '225', + 'name' => 'Cote d\'Ivoire', + ], + [ + 'id' => 'hr', + 'dial_code' => '385', + 'name' => 'Croatia', + ], + [ + 'id' => 'cu', + 'dial_code' => '53', + 'name' => 'Cuba', + ], + [ + 'id' => 'cy', + 'dial_code' => '357', + 'name' => 'Cyprus', + ], + [ + 'id' => 'cz', + 'dial_code' => '420', + 'name' => 'Czech Republic', + ], + [ + 'id' => 'dk', + 'dial_code' => '45', + 'name' => 'Denmark', + ], + [ + 'id' => 'dj', + 'dial_code' => '253', + 'name' => 'Djibouti', + ], + [ + 'id' => 'dm', + 'dial_code' => '1767', + 'name' => 'Dominica', + ], + [ + 'id' => 'do', + 'dial_code' => '1849', + 'name' => 'Dominican Republic', + ], + [ + 'id' => 'ec', + 'dial_code' => '593', + 'name' => 'Ecuador', + ], + [ + 'id' => 'eg', + 'dial_code' => '20', + 'name' => 'Egypt', + ], + [ + 'id' => 'sv', + 'dial_code' => '503', + 'name' => 'El Salvador', + ], + [ + 'id' => 'gq', + 'dial_code' => '240', + 'name' => 'Equatorial Guinea', + ], + [ + 'id' => 'er', + 'dial_code' => '291', + 'name' => 'Eritrea', + ], + [ + 'id' => 'ee', + 'dial_code' => '372', + 'name' => 'Estonia', + ], + [ + 'id' => 'et', + 'dial_code' => '251', + 'name' => 'Ethiopia', + ], + [ + 'id' => 'fk', + 'dial_code' => '500', + 'name' => 'Falkland Islands (Malvinas)', + ], + [ + 'id' => 'fo', + 'dial_code' => '298', + 'name' => 'Faroe Islands', + ], + [ + 'id' => 'fj', + 'dial_code' => '679', + 'name' => 'Fiji', + ], + [ + 'id' => 'fi', + 'dial_code' => '358', + 'name' => 'Finland', + ], + [ + 'id' => 'fr', + 'dial_code' => '33', + 'name' => 'France', + ], + [ + 'id' => 'gf', + 'dial_code' => '594', + 'name' => 'French Guiana', + ], + [ + 'id' => 'pf', + 'dial_code' => '689', + 'name' => 'French Polynesia', + ], + [ + 'id' => 'ga', + 'dial_code' => '241', + 'name' => 'Gabon', + ], + [ + 'id' => 'gm', + 'dial_code' => '220', + 'name' => 'Gambia', + ], + [ + 'id' => 'ge', + 'dial_code' => '995', + 'name' => 'Georgia', + ], + [ + 'id' => 'de', + 'dial_code' => '49', + 'name' => 'Germany', + ], + [ + 'id' => 'gh', + 'dial_code' => '233', + 'name' => 'Ghana', + ], + [ + 'id' => 'gi', + 'dial_code' => '350', + 'name' => 'Gibraltar', + ], + [ + 'id' => 'gr', + 'dial_code' => '30', + 'name' => 'Greece', + ], + [ + 'id' => 'gl', + 'dial_code' => '299', + 'name' => 'Greenland', + ], + [ + 'id' => 'gd', + 'dial_code' => '1473', + 'name' => 'Grenada', + ], + [ + 'id' => 'gp', + 'dial_code' => '590', + 'name' => 'Guadeloupe', + ], + [ + 'id' => 'gu', + 'dial_code' => '1671', + 'name' => 'Guam', + ], + [ + 'id' => 'gt', + 'dial_code' => '502', + 'name' => 'Guatemala', + ], + [ + 'id' => 'gg', + 'dial_code' => '44', + 'name' => 'Guernsey', + ], + [ + 'id' => 'gn', + 'dial_code' => '224', + 'name' => 'Guinea', + ], + [ + 'id' => 'gw', + 'dial_code' => '245', + 'name' => 'Guinea-Bissau', + ], + [ + 'id' => 'gy', + 'dial_code' => '592', + 'name' => 'Guyana', + ], + [ + 'id' => 'ht', + 'dial_code' => '509', + 'name' => 'Haiti', + ], + [ + 'id' => 'va', + 'dial_code' => '379', + 'name' => 'Holy See (Vatican City State)', + ], + [ + 'id' => 'hn', + 'dial_code' => '504', + 'name' => 'Honduras', + ], + [ + 'id' => 'hk', + 'dial_code' => '852', + 'name' => 'Hong Kong', + ], + [ + 'id' => 'hu', + 'dial_code' => '36', + 'name' => 'Hungary', + ], + [ + 'id' => 'is', + 'dial_code' => '354', + 'name' => 'Iceland', + ], + [ + 'id' => 'in', + 'dial_code' => '91', + 'name' => 'India', + ], + [ + 'id' => 'id', + 'dial_code' => '62', + 'name' => 'Indonesia', + ], + [ + 'id' => 'ir', + 'dial_code' => '98', + 'name' => 'Iran, Islamic Republic of Persian Gulf', + ], + [ + 'id' => 'iq', + 'dial_code' => '964', + 'name' => 'Iraq', + ], + [ + 'id' => 'ie', + 'dial_code' => '353', + 'name' => 'Ireland', + ], + [ + 'id' => 'im', + 'dial_code' => '44', + 'name' => 'Isle of Man', + ], + [ + 'id' => 'il', + 'dial_code' => '972', + 'name' => 'Israel', + ], + [ + 'id' => 'it', + 'dial_code' => '39', + 'name' => 'Italy', + ], + [ + 'id' => 'jm', + 'dial_code' => '1876', + 'name' => 'Jamaica', + ], + [ + 'id' => 'jp', + 'dial_code' => '81', + 'name' => 'Japan', + ], + [ + 'id' => 'je', + 'dial_code' => '44', + 'name' => 'Jersey', + ], + [ + 'id' => 'jo', + 'dial_code' => '962', + 'name' => 'Jordan', + ], + [ + 'id' => 'kz', + 'dial_code' => '7', + 'name' => 'Kazakhstan', + ], + [ + 'id' => 'ke', + 'dial_code' => '254', + 'name' => 'Kenya', + ], + [ + 'id' => 'ki', + 'dial_code' => '686', + 'name' => 'Kiribati', + ], + [ + 'id' => 'kp', + 'dial_code' => '850', + 'name' => 'Korea, Democratic People\'s Republic of Korea', + ], + [ + 'id' => 'kr', + 'dial_code' => '82', + 'name' => 'Korea, Republic of South Korea', + ], + [ + 'id' => 'kw', + 'dial_code' => '965', + 'name' => 'Kuwait', + ], + [ + 'id' => 'kg', + 'dial_code' => '996', + 'name' => 'Kyrgyzstan', + ], + [ + 'id' => 'la', + 'dial_code' => '856', + 'name' => 'Laos', + ], + [ + 'id' => 'lv', + 'dial_code' => '371', + 'name' => 'Latvia', + ], + [ + 'id' => 'lb', + 'dial_code' => '961', + 'name' => 'Lebanon', + ], + [ + 'id' => 'ls', + 'dial_code' => '266', + 'name' => 'Lesotho', + ], + [ + 'id' => 'lr', + 'dial_code' => '231', + 'name' => 'Liberia', + ], + [ + 'id' => 'ly', + 'dial_code' => '218', + 'name' => 'Libyan Arab Jamahiriya', + ], + [ + 'id' => 'li', + 'dial_code' => '423', + 'name' => 'Liechtenstein', + ], + [ + 'id' => 'lt', + 'dial_code' => '370', + 'name' => 'Lithuania', + ], + [ + 'id' => 'lu', + 'dial_code' => '352', + 'name' => 'Luxembourg', + ], + [ + 'id' => 'mo', + 'dial_code' => '853', + 'name' => 'Macao', + ], + [ + 'id' => 'mk', + 'dial_code' => '389', + 'name' => 'Macedonia', + ], + [ + 'id' => 'mg', + 'dial_code' => '261', + 'name' => 'Madagascar', + ], + [ + 'id' => 'mw', + 'dial_code' => '265', + 'name' => 'Malawi', + ], + [ + 'id' => 'my', + 'dial_code' => '60', + 'name' => 'Malaysia', + ], + [ + 'id' => 'mv', + 'dial_code' => '960', + 'name' => 'Maldives', + ], + [ + 'id' => 'ml', + 'dial_code' => '223', + 'name' => 'Mali', + ], + [ + 'id' => 'mt', + 'dial_code' => '356', + 'name' => 'Malta', + ], + [ + 'id' => 'mh', + 'dial_code' => '692', + 'name' => 'Marshall Islands', + ], + [ + 'id' => 'mq', + 'dial_code' => '596', + 'name' => 'Martinique', + ], + [ + 'id' => 'mr', + 'dial_code' => '222', + 'name' => 'Mauritania', + ], + [ + 'id' => 'mu', + 'dial_code' => '230', + 'name' => 'Mauritius', + ], + [ + 'id' => 'yt', + 'dial_code' => '262', + 'name' => 'Mayotte', + ], + [ + 'id' => 'mx', + 'dial_code' => '52', + 'name' => 'Mexico', + ], + [ + 'id' => 'fm', + 'dial_code' => '691', + 'name' => 'Micronesia, Federated States of Micronesia', + ], + [ + 'id' => 'md', + 'dial_code' => '373', + 'name' => 'Moldova', + ], + [ + 'id' => 'mc', + 'dial_code' => '377', + 'name' => 'Monaco', + ], + [ + 'id' => 'mn', + 'dial_code' => '976', + 'name' => 'Mongolia', + ], + [ + 'id' => 'me', + 'dial_code' => '382', + 'name' => 'Montenegro', + ], + [ + 'id' => 'ms', + 'dial_code' => '1664', + 'name' => 'Montserrat', + ], + [ + 'id' => 'ma', + 'dial_code' => '212', + 'name' => 'Morocco', + ], + [ + 'id' => 'mz', + 'dial_code' => '258', + 'name' => 'Mozambique', + ], + [ + 'id' => 'mm', + 'dial_code' => '95', + 'name' => 'Myanmar', + ], + [ + 'id' => 'na', + 'dial_code' => '264', + 'name' => 'Namibia', + ], + [ + 'id' => 'nr', + 'dial_code' => '674', + 'name' => 'Nauru', + ], + [ + 'id' => 'np', + 'dial_code' => '977', + 'name' => 'Nepal', + ], + [ + 'id' => 'nl', + 'dial_code' => '31', + 'name' => 'Netherlands', + ], + [ + 'id' => 'an', + 'dial_code' => '599', + 'name' => 'Netherlands Antilles', + ], + [ + 'id' => 'nc', + 'dial_code' => '687', + 'name' => 'New Caledonia', + ], + [ + 'id' => 'nz', + 'dial_code' => '64', + 'name' => 'New Zealand', + ], + [ + 'id' => 'ni', + 'dial_code' => '505', + 'name' => 'Nicaragua', + ], + [ + 'id' => 'ne', + 'dial_code' => '227', + 'name' => 'Niger', + ], + [ + 'id' => 'ng', + 'dial_code' => '234', + 'name' => 'Nigeria', + ], + [ + 'id' => 'nu', + 'dial_code' => '683', + 'name' => 'Niue', + ], + [ + 'id' => 'nf', + 'dial_code' => '672', + 'name' => 'Norfolk Island', + ], + [ + 'id' => 'mp', + 'dial_code' => '1670', + 'name' => 'Northern Mariana Islands', + ], + [ + 'id' => 'no', + 'dial_code' => '47', + 'name' => 'Norway', + ], + [ + 'id' => 'om', + 'dial_code' => '968', + 'name' => 'Oman', + ], + [ + 'id' => 'pk', + 'dial_code' => '92', + 'name' => 'Pakistan', + ], + [ + 'id' => 'pw', + 'dial_code' => '680', + 'name' => 'Palau', + ], + [ + 'id' => 'ps', + 'dial_code' => '970', + 'name' => 'Palestinian Territory, Occupied', + ], + [ + 'id' => 'pa', + 'dial_code' => '507', + 'name' => 'Panama', + ], + [ + 'id' => 'pg', + 'dial_code' => '675', + 'name' => 'Papua New Guinea', + ], + [ + 'id' => 'py', + 'dial_code' => '595', + 'name' => 'Paraguay', + ], + [ + 'id' => 'pe', + 'dial_code' => '51', + 'name' => 'Peru', + ], + [ + 'id' => 'ph', + 'dial_code' => '63', + 'name' => 'Philippines', + ], + [ + 'id' => 'pn', + 'dial_code' => '64', + 'name' => 'Pitcairn', + ], + [ + 'id' => 'pl', + 'dial_code' => '48', + 'name' => 'Poland', + ], + [ + 'id' => 'pt', + 'dial_code' => '351', + 'name' => 'Portugal', + ], + [ + 'id' => 'pr', + 'dial_code' => '1939', + 'name' => 'Puerto Rico', + ], + [ + 'id' => 'qa', + 'dial_code' => '974', + 'name' => 'Qatar', + ], + [ + 'id' => 'ro', + 'dial_code' => '40', + 'name' => 'Romania', + ], + [ + 'id' => 'ru', + 'dial_code' => '7', + 'name' => 'Russia', + ], + [ + 'id' => 'rw', + 'dial_code' => '250', + 'name' => 'Rwanda', + ], + [ + 'id' => 're', + 'dial_code' => '262', + 'name' => 'Reunion', + ], + [ + 'id' => 'bl', + 'dial_code' => '590', + 'name' => 'Saint Barthelemy', + ], + [ + 'id' => 'sh', + 'dial_code' => '290', + 'name' => 'Saint Helena, Ascension and Tristan Da Cunha', + ], + [ + 'id' => 'kn', + 'dial_code' => '1869', + 'name' => 'Saint Kitts and Nevis', + ], + [ + 'id' => 'lc', + 'dial_code' => '1758', + 'name' => 'Saint Lucia', + ], + [ + 'id' => 'mf', + 'dial_code' => '590', + 'name' => 'Saint Martin', + ], + [ + 'id' => 'pm', + 'dial_code' => '508', + 'name' => 'Saint Pierre and Miquelon', + ], + [ + 'id' => 'vc', + 'dial_code' => '1784', + 'name' => 'Saint Vincent and the Grenadines', + ], + [ + 'id' => 'ws', + 'dial_code' => '685', + 'name' => 'Samoa', + ], + [ + 'id' => 'sm', + 'dial_code' => '378', + 'name' => 'San Marino', + ], + [ + 'id' => 'st', + 'dial_code' => '239', + 'name' => 'Sao Tome and Principe', + ], + [ + 'id' => 'sa', + 'dial_code' => '966', + 'name' => 'Saudi Arabia', + ], + [ + 'id' => 'sn', + 'dial_code' => '221', + 'name' => 'Senegal', + ], + [ + 'id' => 'rs', + 'dial_code' => '381', + 'name' => 'Serbia', + ], + [ + 'id' => 'sc', + 'dial_code' => '248', + 'name' => 'Seychelles', + ], + [ + 'id' => 'sl', + 'dial_code' => '232', + 'name' => 'Sierra Leone', + ], + [ + 'id' => 'sg', + 'dial_code' => '65', + 'name' => 'Singapore', + ], + [ + 'id' => 'sk', + 'dial_code' => '421', + 'name' => 'Slovakia', + ], + [ + 'id' => 'si', + 'dial_code' => '386', + 'name' => 'Slovenia', + ], + [ + 'id' => 'sb', + 'dial_code' => '677', + 'name' => 'Solomon Islands', + ], + [ + 'id' => 'so', + 'dial_code' => '252', + 'name' => 'Somalia', + ], + [ + 'id' => 'za', + 'dial_code' => '27', + 'name' => 'South Africa', + ], + [ + 'id' => 'ss', + 'dial_code' => '211', + 'name' => 'South Sudan', + ], + [ + 'id' => 'gs', + 'dial_code' => '500', + 'name' => 'South Georgia and the South Sandwich Islands', + ], + [ + 'id' => 'es', + 'dial_code' => '34', + 'name' => 'Spain', + ], + [ + 'id' => 'lk', + 'dial_code' => '94', + 'name' => 'Sri Lanka', + ], + [ + 'id' => 'sd', + 'dial_code' => '249', + 'name' => 'Sudan', + ], + [ + 'id' => 'sr', + 'dial_code' => '597', + 'name' => 'Suriname', + ], + [ + 'id' => 'sj', + 'dial_code' => '47', + 'name' => 'Svalbard and Jan Mayen', + ], + [ + 'id' => 'sz', + 'dial_code' => '268', + 'name' => 'Swaziland', + ], + [ + 'id' => 'se', + 'dial_code' => '46', + 'name' => 'Sweden', + ], + [ + 'id' => 'ch', + 'dial_code' => '41', + 'name' => 'Switzerland', + ], + [ + 'id' => 'sy', + 'dial_code' => '963', + 'name' => 'Syrian Arab Republic', + ], + [ + 'id' => 'tw', + 'dial_code' => '886', + 'name' => 'Taiwan', + ], + [ + 'id' => 'tj', + 'dial_code' => '992', + 'name' => 'Tajikistan', + ], + [ + 'id' => 'tz', + 'dial_code' => '255', + 'name' => 'Tanzania, United Republic of Tanzania', + ], + [ + 'id' => 'th', + 'dial_code' => '66', + 'name' => 'Thailand', + ], + [ + 'id' => 'tl', + 'dial_code' => '670', + 'name' => 'Timor-Leste', + ], + [ + 'id' => 'tg', + 'dial_code' => '228', + 'name' => 'Togo', + ], + [ + 'id' => 'tk', + 'dial_code' => '690', + 'name' => 'Tokelau', + ], + [ + 'id' => 'to', + 'dial_code' => '676', + 'name' => 'Tonga', + ], + [ + 'id' => 'tt', + 'dial_code' => '1868', + 'name' => 'Trinidad and Tobago', + ], + [ + 'id' => 'tn', + 'dial_code' => '216', + 'name' => 'Tunisia', + ], + [ + 'id' => 'tr', + 'dial_code' => '90', + 'name' => 'Turkey', + ], + [ + 'id' => 'tm', + 'dial_code' => '993', + 'name' => 'Turkmenistan', + ], + [ + 'id' => 'tc', + 'dial_code' => '1649', + 'name' => 'Turks and Caicos Islands', + ], + [ + 'id' => 'tv', + 'dial_code' => '688', + 'name' => 'Tuvalu', + ], + [ + 'id' => 'ug', + 'dial_code' => '256', + 'name' => 'Uganda', + ], + [ + 'id' => 'ua', + 'dial_code' => '380', + 'name' => 'Ukraine', + ], + [ + 'id' => 'ae', + 'dial_code' => '971', + 'name' => 'United Arab Emirates', + ], + [ + 'id' => 'gb', + 'dial_code' => '44', + 'name' => 'United Kingdom', + ], + [ + 'id' => 'us', + 'dial_code' => '1', + 'name' => 'United States', + ], + [ + 'id' => 'uy', + 'dial_code' => '598', + 'name' => 'Uruguay', + ], + [ + 'id' => 'uz', + 'dial_code' => '998', + 'name' => 'Uzbekistan', + ], + [ + 'id' => 'vu', + 'dial_code' => '678', + 'name' => 'Vanuatu', + ], + [ + 'id' => 've', + 'dial_code' => '58', + 'name' => 'Venezuela, Bolivarian Republic of Venezuela', + ], + [ + 'id' => 'vn', + 'dial_code' => '84', + 'name' => 'Vietnam', + ], + [ + 'id' => 'vg', + 'dial_code' => '1284', + 'name' => 'Virgin Islands, British', + ], + [ + 'id' => 'vi', + 'dial_code' => '1340', + 'name' => 'Virgin Islands, U.S.', + ], + [ + 'id' => 'wf', + 'dial_code' => '681', + 'name' => 'Wallis and Futuna', + ], + [ + 'id' => 'ye', + 'dial_code' => '967', + 'name' => 'Yemen', + ], + [ + 'id' => 'zm', + 'dial_code' => '260', + 'name' => 'Zambia', + ], + [ + 'id' => 'zw', + 'dial_code' => '263', + 'name' => 'Zimbabwe', + ], +]; \ No newline at end of file diff --git a/src/Model.php b/src/Model.php new file mode 100644 index 0000000..fee34f4 --- /dev/null +++ b/src/Model.php @@ -0,0 +1,62 @@ +map); + + if ($map->count()) return $map; + + return collect($this->rawData->first())->mapWithKeys(function ($value, $columnName) { + return [$columnName => $columnName]; + }); + } + + public function getRows() + { + $this->rawData = collect($this->rawData ?: require __DIR__."/../resources/{$this->source}.php"); + + $map = $this->getMap(); + + return $this->rawData->map(function ($row) use ($map) { + $record = []; + + foreach ($map as $columnName => $sourceColumnName) { + $record[$columnName] = $row[$sourceColumnName]; + } + + return $record; + })->toArray(); + } + + public function getSchema() + { + $schema = collect($this->schema ?? []); + + return $this->getMap() + ->filter(function ($sourceColumnName, $columnName) use ($schema) { + return $schema->get($sourceColumnName, false); + }) + ->mapWithKeys(function ($sourceColumnName, $columnName) use ($schema) { + return [$columnName => $schema->get($sourceColumnName)]; + })->toArray(); + } +} diff --git a/src/Models/Country.php b/src/Models/Country.php new file mode 100644 index 0000000..805bc92 --- /dev/null +++ b/src/Models/Country.php @@ -0,0 +1,12 @@ +assertEquals(Foo::count(), 2); + $this->assertEquals(Foo::first()->foo, 'bar'); + $this->assertEquals(Foo::where('bob', 'law')->first()->foo, 'baz'); + } + + /** @test */ + function custom_column_map() + { + $this->assertEquals(Bar::first()->new_foo, 'bar'); + $this->assertEquals(Bar::where('new_bob', 'law')->first()->new_foo, 'baz'); + } + + /** @test */ + function custom_column_map_and_schema() + { + $this->assertEquals(Baz::first()->new_foo, '1.0'); + $this->assertEquals(Baz::first()->new_bob, '1'); + } +} + +class Foo extends Model +{ + protected $rawData = [ + ['foo' => 'bar', 'bob' => 'lob'], + ['foo' => 'baz', 'bob' => 'law'], + ]; +} + +class Bar extends Model +{ + protected $map = [ + 'new_foo' => 'foo', + 'new_bob' => 'bob', + ]; + + protected $rawData = [ + ['foo' => 'bar', 'bob' => 'lob'], + ['foo' => 'baz', 'bob' => 'law'], + ]; +} + +class Baz extends Model +{ + protected $map = [ + 'new_foo' => 'foo', + 'new_bob' => 'bob', + ]; + + protected $rawData = [ + ['foo' => '1.0', 'bob' => '1.0'], + ]; + + protected $schema = [ + 'bob' => 'integer', + ]; +} \ No newline at end of file