├── .yamllint.yaml ├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── composer.json ├── composer.lock └── src └── Helper.php /.yamllint.yaml: -------------------------------------------------------------------------------- 1 | extends: "default" 2 | 3 | ignore: | 4 | .build/ 5 | .notes/ 6 | vendor/ 7 | 8 | rules: 9 | braces: 10 | max-spaces-inside-empty: 0 11 | max-spaces-inside: 1 12 | min-spaces-inside-empty: 0 13 | min-spaces-inside: 1 14 | brackets: 15 | max-spaces-inside-empty: 0 16 | max-spaces-inside: 0 17 | min-spaces-inside-empty: 0 18 | min-spaces-inside: 0 19 | colons: 20 | max-spaces-after: 1 21 | max-spaces-before: 0 22 | commas: 23 | max-spaces-after: 1 24 | max-spaces-before: 0 25 | min-spaces-after: 1 26 | comments: 27 | ignore-shebangs: true 28 | min-spaces-from-content: 1 29 | require-starting-space: true 30 | comments-indentation: "enable" 31 | document-end: 32 | present: false 33 | document-start: 34 | present: false 35 | indentation: 36 | check-multi-line-strings: false 37 | indent-sequences: true 38 | spaces: 2 39 | empty-lines: 40 | max-end: 0 41 | max-start: 0 42 | max: 1 43 | empty-values: 44 | forbid-in-block-mappings: true 45 | forbid-in-flow-mappings: true 46 | hyphens: 47 | max-spaces-after: 2 48 | key-duplicates: "enable" 49 | key-ordering: "disable" 50 | line-length: "disable" 51 | new-line-at-end-of-file: "enable" 52 | new-lines: 53 | type: "unix" 54 | octal-values: 55 | forbid-implicit-octal: true 56 | quoted-strings: 57 | quote-type: "double" 58 | trailing-spaces: "enable" 59 | truthy: 60 | allowed-values: 61 | - "false" 62 | - "true" 63 | 64 | yaml-files: 65 | - "*.yaml" 66 | - "*.yml" 67 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 6 | 7 | ## Unreleased 8 | 9 | For a full diff see [`1.6.0...main`][1.6.0...main]. 10 | 11 | ### Removed 12 | 13 | - Removed all data providers ([#552]), by [@localheinz] 14 | 15 | If you use any of the data providers, run 16 | 17 | ```shell 18 | composer require --dev ergebnis/data-provider 19 | ``` 20 | 21 | and replace occurrences of `Ergebnis\Test\Util\DataProvider` with `Ergebnis\DataProvider`. 22 | 23 | - Removed all assertions ([#553]), by [@localheinz] 24 | 25 | If you use any of the assertions, stop. Most of them are useless, some of them could be replaced with static code analysis. I do not use them anymore and I would not recommend to use these kinds of assertions. 26 | 27 | - Removed all provide methods ([#554]), by [@localheinz] 28 | 29 | If you use any of the provide methods in an external data provider, run 30 | 31 | ```shell 32 | composer require --dev ergebnis/data-provider 33 | ``` 34 | 35 | and extend `Ergebnis\DataProvider\AbstractProvider`. 36 | 37 | If you use any of the provide methods in data provider declared as an instance method on a test case, extract your own `Helper` trait and move the functionality there. 38 | 39 | ## [`1.6.0`][1.6.0] 40 | 41 | For a full diff see [`1.5.0...1.6.0`][1.5.0...1.6.0]. 42 | 43 | ### Changed 44 | 45 | - Deprecated all data providers ([#526]), by [@localheinz] 46 | - Dropped support for PHP 7.2 ([#530]), by [@localheinz] 47 | - Dropped support for PHP 7.3 ([#540]), by [@localheinz] 48 | - Deprecated all assertions ([#548]), by [@localheinz] 49 | - Deprecated provide methods ([#549]), by [@localheinz] 50 | 51 | ## [`1.5.0`][1.5.0] 52 | 53 | For a full diff see [`1.4.0...1.5.0`][1.4.0...1.5.0]. 54 | 55 | ### Changed 56 | 57 | * Updated `fakerphp/faker` ([#434]), by [@dependabot] 58 | 59 | ### Fixed 60 | 61 | * Stopped using deprecated magic properties on `Faker\Generator` and started using magic functions instead ([#435]), by [@localheinz] 62 | 63 | ## [`1.4.0`][1.4.0] 64 | 65 | For a full diff see [`1.3.0...1.4.0`][1.3.1...1.4.0]. 66 | 67 | ### Added 68 | 69 | * Added `DataProvider\StringProvider::withWhitespace()` ([#374]), by [@localheinz] 70 | 71 | ## [`1.3.1`][1.3.1] 72 | 73 | For a full diff see [`1.3.0...1.3.1`][1.3.0...1.3.1]. 74 | 75 | ### Fixed 76 | 77 | * Started using `fakerphp/faker` instead of `fzaninotto/faker` ([#372]), by [@localheinz] 78 | 79 | ## [`1.3.0`][1.3.0] 80 | 81 | For a full diff see [`1.2.0...1.3.0`][1.2.0...1.3.0]. 82 | 83 | ### Added 84 | 85 | * Added `DataProvider\ObjectProvider` ([#343]), by [@localheinz] 86 | * Added `DataProvider\ResourceProvider` ([#344]), by [@localheinz] 87 | 88 | ## [`1.2.0`][1.2.0] 89 | 90 | For a full diff see [`1.1.0...1.2.0`][1.1.0...1.2.0]. 91 | 92 | ### Added 93 | 94 | * Added `DataProvider\BooleanProvider` ([#326]), by [@localheinz] 95 | * Added `DataProvider\NullProvider` ([#327]), by [@localheinz] 96 | * Added `DataProvider\StringProvider` ([#328]), by [@localheinz] 97 | * Added `DataProvider\IntProvider` ([#335]), by [@localheinz] 98 | * Added `DataProvider\FloatProvider` ([#341]), by [@localheinz] 99 | 100 | ### Changed 101 | 102 | * Renamed `DataProvider\BooleanProvider` to `DataProvider\BoolProvider` ([#334]), by [@localheinz] 103 | 104 | ## [`1.1.0`][1.1.0] 105 | 106 | For a full diff see [`1.0.1...1.1.0`][1.0.1...1.1.0]. 107 | 108 | ### Changed 109 | 110 | * Added support for PHP 8.0 ([#302]), by [@localheinz] 111 | 112 | ## [`1.0.1`][1.0.1] 113 | 114 | For a full diff see [`1.0.0...1.0.1`][1.0.0...1.0.1]. 115 | 116 | ### Changed 117 | 118 | * Dropped support for PHP 7.1 ([#295]), by [@localheinz] 119 | 120 | ## [`1.0.0`][1.0.0] 121 | 122 | For a full diff see [`0.9.1...1.0.0`][0.9.1...1.0.0]. 123 | 124 | ## [`0.9.1`][0.9.1] 125 | 126 | For a full diff see [`0.9.0...0.9.1`][0.9.0...0.9.1]. 127 | 128 | ### Fixed 129 | 130 | * Brought back support for PHP 7.1 ([#155]), by [@localheinz] 131 | 132 | ## [`0.9.0`][0.9.0] 133 | 134 | For a full diff see [`0.8.0...0.9.0`][0.8.0...0.9.0]. 135 | 136 | ### Changed 137 | 138 | * Renamed vendor namespace `Localheinz` to `Ergebnis` after move to [@ergebnis] ([#147]), by [@localheinz] 139 | 140 | Run 141 | 142 | ``` 143 | $ composer remove localheinz/test-util 144 | ``` 145 | 146 | and 147 | 148 | ``` 149 | $ composer require ergebnis/test-util 150 | ``` 151 | 152 | to update. 153 | 154 | Run 155 | 156 | ``` 157 | $ find . -type f -exec sed -i '.bak' 's/Localheinz\\Test\\Util/Ergebnis\\Test\\Util/g' {} \; 158 | ``` 159 | 160 | to replace occurrences of `Localheinz\Test\Util` with `Ergebnis\Test\Util`. 161 | 162 | Run 163 | 164 | ``` 165 | $ find -type f -name '*.bak' -delete 166 | ``` 167 | 168 | to delete backup files created in the previous step. 169 | 170 | ## [`0.8.0`][0.8.0] 171 | 172 | For a full diff see [`0.7.0...0.8.0`][0.7.0...0.8.0]. 173 | 174 | ### Changed 175 | 176 | * Dropped support for PHP 7.1 ([#118]), by [@localheinz] 177 | * Methods in `Helper` trait are now `static` ([#119]), by [@localheinz] 178 | * Dropped support for `phpunit/phpunit:^6.0.0` ([#120]), by [@localheinz] 179 | * Allowed installation with `phpunit/phpunit:^8.0.0` ([#122]), by [@localheinz] 180 | 181 | [0.8.0]: https://github.com/ergebnis/test-util/releases/tag/0.8.0 182 | [0.9.0]: https://github.com/ergebnis/test-util/releases/tag/0.9.0 183 | [0.9.1]: https://github.com/ergebnis/test-util/releases/tag/0.9.1 184 | [1.0.0]: https://github.com/ergebnis/test-util/releases/tag/1.0.0 185 | [1.0.1]: https://github.com/ergebnis/test-util/releases/tag/1.0.1 186 | [1.1.0]: https://github.com/ergebnis/test-util/releases/tag/1.1.0 187 | [1.2.0]: https://github.com/ergebnis/test-util/releases/tag/1.2.0 188 | [1.3.0]: https://github.com/ergebnis/test-util/releases/tag/1.3.0 189 | [1.3.1]: https://github.com/ergebnis/test-util/releases/tag/1.3.1 190 | [1.4.0]: https://github.com/ergebnis/test-util/releases/tag/1.4.0 191 | [1.5.0]: https://github.com/ergebnis/test-util/releases/tag/1.5.0 192 | [1.6.0]: https://github.com/ergebnis/test-util/releases/tag/1.6.0 193 | 194 | [0.7.0...0.8.0]: https://github.com/ergebnis/test-util/compare/0.7.0...0.8.0 195 | [0.8.0...0.9.0]: https://github.com/ergebnis/test-util/compare/0.8.0...0.9.0 196 | [0.9.0...0.9.1]: https://github.com/ergebnis/test-util/compare/0.9.0...0.9.1 197 | [0.9.1...1.0.0]: https://github.com/ergebnis/test-util/compare/0.9.1...1.0.0 198 | [1.0.0...1.0.1]: https://github.com/ergebnis/test-util/compare/1.0.0...1.0.1 199 | [1.0.1...1.1.0]: https://github.com/ergebnis/test-util/compare/1.0.1...1.1.0 200 | [1.1.0...1.2.0]: https://github.com/ergebnis/test-util/compare/1.1.0...1.2.0 201 | [1.2.0...1.3.0]: https://github.com/ergebnis/test-util/compare/1.2.0...1.3.0 202 | [1.3.0...1.3.1]: https://github.com/ergebnis/test-util/compare/1.3.0...1.3.1 203 | [1.3.1...1.4.0]: https://github.com/ergebnis/test-util/compare/1.3.1...1.4.0 204 | [1.4.0...1.5.0]: https://github.com/ergebnis/test-util/compare/1.4.0...1.5.0 205 | [1.5.0...1.6.0]: https://github.com/ergebnis/test-util/compare/1.5.0...1.6.0 206 | [1.6.0...main]: https://github.com/ergebnis/test-util/compare/1.6.0...main 207 | 208 | [#118]: https://github.com/ergebnis/test-util/pull/118 209 | [#119]: https://github.com/ergebnis/test-util/pull/119 210 | [#120]: https://github.com/ergebnis/test-util/pull/120 211 | [#122]: https://github.com/ergebnis/test-util/pull/122 212 | [#147]: https://github.com/ergebnis/test-util/pull/147 213 | [#155]: https://github.com/ergebnis/test-util/pull/155 214 | [#295]: https://github.com/ergebnis/test-util/pull/295 215 | [#302]: https://github.com/ergebnis/test-util/pull/302 216 | [#326]: https://github.com/ergebnis/test-util/pull/326 217 | [#327]: https://github.com/ergebnis/test-util/pull/327 218 | [#328]: https://github.com/ergebnis/test-util/pull/328 219 | [#334]: https://github.com/ergebnis/test-util/pull/334 220 | [#335]: https://github.com/ergebnis/test-util/pull/335 221 | [#341]: https://github.com/ergebnis/test-util/pull/341 222 | [#343]: https://github.com/ergebnis/test-util/pull/343 223 | [#344]: https://github.com/ergebnis/test-util/pull/344 224 | [#372]: https://github.com/ergebnis/test-util/pull/372 225 | [#374]: https://github.com/ergebnis/test-util/pull/374 226 | [#434]: https://github.com/ergebnis/test-util/pull/434 227 | [#435]: https://github.com/ergebnis/test-util/pull/435 228 | [#526]: https://github.com/ergebnis/test-util/pull/526 229 | [#530]: https://github.com/ergebnis/test-util/pull/530 230 | [#540]: https://github.com/ergebnis/test-util/pull/540 231 | [#548]: https://github.com/ergebnis/test-util/pull/548 232 | [#549]: https://github.com/ergebnis/test-util/pull/549 233 | [#552]: https://github.com/ergebnis/test-util/pull/552 234 | [#553]: https://github.com/ergebnis/test-util/pull/553 235 | 236 | [@dependabot]: https://github.com/dependabot 237 | [@ergebnis]: https://github.com/ergebnis 238 | [@localheinz]: https://github.com/localheinz 239 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | 3 | Copyright (c) 2017-2022 Andreas Möller 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 6 | documentation files (the _Software_), to deal in the Software without restriction, including without limitation the 7 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit 8 | persons to whom the Software is furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 11 | Software. 12 | 13 | THE SOFTWARE IS PROVIDED **AS IS**, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 14 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 15 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # test-util 2 | 3 | [![Integrate](https://github.com/ergebnis/test-util/workflows/Integrate/badge.svg)](https://github.com/ergebnis/test-util/actions) 4 | [![Prune](https://github.com/ergebnis/test-util/workflows/Prune/badge.svg)](https://github.com/ergebnis/test-util/actions) 5 | [![Release](https://github.com/ergebnis/test-util/workflows/Release/badge.svg)](https://github.com/ergebnis/test-util/actions) 6 | [![Renew](https://github.com/ergebnis/test-util/workflows/Renew/badge.svg)](https://github.com/ergebnis/test-util/actions) 7 | 8 | [![Code Coverage](https://codecov.io/gh/ergebnis/test-util/branch/main/graph/badge.svg)](https://codecov.io/gh/ergebnis/test-util) 9 | [![Type Coverage](https://shepherd.dev/github/ergebnis/test-util/coverage.svg)](https://shepherd.dev/github/ergebnis/test-util) 10 | 11 | [![Latest Stable Version](https://poser.pugx.org/ergebnis/test-util/v/stable)](https://packagist.org/packages/ergebnis/test-util) 12 | [![Total Downloads](https://poser.pugx.org/ergebnis/test-util/downloads)](https://packagist.org/packages/ergebnis/test-util) 13 | 14 | Provides a helper trait for tests. 15 | 16 | ## Installation 17 | 18 | Run 19 | 20 | ```sh 21 | $ composer require --dev ergebnis/test-util 22 | ``` 23 | 24 | ## Usage 25 | 26 | ### `Helper` 27 | 28 | Import the `Ergebnis\Test\Util\Helper` trait into your test class: 29 | 30 | ```php 31 | firstName; 70 | 71 | $player = new Player($name); 72 | 73 | $this->assertSame($name, $player->firstName()); 74 | } 75 | } 76 | ``` 77 | 78 | For reference, see [`fzaninotto/faker`](https://github.com/fzaninotto/Faker). 79 | 80 | ## Changelog 81 | 82 | Please have a look at [`CHANGELOG.md`](CHANGELOG.md). 83 | 84 | ## Contributing 85 | 86 | Please have a look at [`CONTRIBUTING.md`](.github/CONTRIBUTING.md). 87 | 88 | ## Code of Conduct 89 | 90 | Please have a look at [`CODE_OF_CONDUCT.md`](https://github.com/ergebnis/.github/blob/main/CODE_OF_CONDUCT.md). 91 | 92 | ## License 93 | 94 | This package is licensed using the MIT License. 95 | 96 | Please have a look at [`LICENSE.md`](LICENSE.md). 97 | 98 | ## Curious what I am building? 99 | 100 | :mailbox_with_mail: [Subscribe to my list](https://localheinz.com/projects/), and I will occasionally send you an email to let you know what I am working on. 101 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ergebnis/test-util", 3 | "description": "Provides a helper trait and generic data providers for tests.", 4 | "license": "MIT", 5 | "type": "library", 6 | "keywords": [ 7 | "assertion", 8 | "faker", 9 | "phpunit", 10 | "test" 11 | ], 12 | "authors": [ 13 | { 14 | "name": "Andreas Möller", 15 | "email": "am@localheinz.com" 16 | } 17 | ], 18 | "homepage": "https://github.com/ergebnis/test-util", 19 | "support": { 20 | "issues": "https://github.com/ergebnis/test-util/issues", 21 | "source": "https://github.com/ergebnis/test-util" 22 | }, 23 | "require": { 24 | "php": "^7.4 || ^8.0", 25 | "ergebnis/classy": "^1.3.0", 26 | "fakerphp/faker": "^1.17.0" 27 | }, 28 | "require-dev": { 29 | "ergebnis/composer-normalize": "^2.22.0", 30 | "ergebnis/license": "^1.2.0", 31 | "ergebnis/php-cs-fixer-config": "^3.4.0", 32 | "ergebnis/phpstan-rules": "~0.15.3", 33 | "infection/infection": "~0.25.5", 34 | "phpstan/extension-installer": "^1.1.0", 35 | "phpstan/phpstan": "~0.12.84", 36 | "phpstan/phpstan-deprecation-rules": "~0.12.6", 37 | "phpstan/phpstan-phpunit": "~0.12.22", 38 | "phpstan/phpstan-strict-rules": "~0.12.11", 39 | "phpunit/phpunit": "^9.5.11", 40 | "psalm/plugin-phpunit": "~0.16.1", 41 | "vimeo/psalm": "^4.17.0" 42 | }, 43 | "autoload": { 44 | "psr-4": { 45 | "Ergebnis\\Test\\Util\\": "src/" 46 | } 47 | }, 48 | "autoload-dev": { 49 | "psr-4": { 50 | "Ergebnis\\Test\\Util\\Test\\": "test/" 51 | } 52 | }, 53 | "config": { 54 | "allow-plugins": { 55 | "composer/package-versions-deprecated": true, 56 | "ergebnis/composer-normalize": true, 57 | "infection/extension-installer": true, 58 | "phpstan/extension-installer": true 59 | }, 60 | "platform": { 61 | "php": "7.4.26" 62 | }, 63 | "preferred-install": "dist", 64 | "sort-packages": true 65 | }, 66 | "extra": { 67 | "composer-normalize": { 68 | "indent-size": 2, 69 | "indent-style": "space" 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/Helper.php: -------------------------------------------------------------------------------- 1 | 32 | */ 33 | static $fakers = []; 34 | 35 | if (!\array_key_exists($locale, $fakers)) { 36 | $faker = Factory::create($locale); 37 | 38 | $faker->seed(9001); 39 | 40 | $fakers[$locale] = $faker; 41 | } 42 | 43 | return $fakers[$locale]; 44 | } 45 | } 46 | --------------------------------------------------------------------------------