From 5ddb6dbaabefb26299682b317c2c4327811c463f Mon Sep 17 00:00:00 2001 From: Ilario Pierbattista <987038+ilario-pierbattista@users.noreply.github.com> Date: Fri, 17 Dec 2021 21:46:27 +0100 Subject: [PATCH] Drop support for old php and phpunit versions (#148) --- .docker/Dockerfile | 3 +- .github/workflows/ci.yml | 19 ++-- ChangeLog.md | 3 + Makefile | 7 ++ README.md | 2 +- composer.json | 4 +- docker-compose.yml | 13 ++- examples/AlwaysFailsTest.php | 2 +- examples/AssociativeArrayTest.php | 8 +- examples/BindTest.php | 2 +- examples/BooleanTest.php | 2 +- examples/CharacterTest.php | 2 +- examples/ChooseTest.php | 2 +- examples/CollectTest.php | 2 +- examples/ConstantTest.php | 2 +- examples/DateTest.php | 2 +- examples/DifferentElementsTest.php | 2 +- examples/DisableShrinkingTest.php | 2 +- examples/ElementsTest.php | 2 +- examples/ErrorTest.php | 2 +- examples/FloatTest.php | 2 +- examples/FrequencyTest.php | 2 +- examples/GeneratorSamplesTest.php | 4 +- examples/IntegerTest.php | 2 +- examples/LimitToTest.php | 4 +- examples/LogFileTest.php | 8 +- examples/MapTest.php | 2 +- examples/MinimumEvaluationsTest.php | 2 +- examples/NamesTest.php | 6 +- examples/OneOfTest.php | 2 +- examples/RandConfigurationTest.php | 4 +- examples/ReadmeTest.php | 2 +- examples/RegexTest.php | 2 +- examples/SequenceTest.php | 4 +- examples/SetTest.php | 4 +- examples/ShrinkingTest.php | 4 +- examples/ShrinkingTimeLimitTest.php | 2 +- examples/SizeTest.php | 2 +- examples/SortTest.php | 2 +- examples/StringTest.php | 2 +- examples/SubsetTest.php | 5 +- examples/SuchThatTest.php | 4 +- examples/SumTest.php | 2 +- examples/TupleTest.php | 2 +- examples/VectorTest.php | 2 +- examples/WhenTest.php | 2 +- phpstan-baseline.neon | 21 ++--- phpstan.neon | 4 +- phpunit.xml | 4 +- psalm-baseline.xml | 28 +----- .../IndependentConstraintsAntecedent.php | 7 +- src/Generator/AssociativeArrayGenerator.php | 2 +- src/Generator/GeneratedValueOptions.php | 4 +- src/Generator/GeneratedValueSingle.php | 4 +- src/Generator/SuchThatGenerator.php | 12 +-- src/Generators.php | 4 +- src/Quantifier/Evaluation.php | 4 - src/Quantifier/ForAll.php | 3 - src/Quantifier/Size.php | 2 +- test/ExampleEnd2EndTest.php | 36 ++++---- .../AssociativeArrayGeneratorTest.php | 23 ++--- test/Generator/BindGeneratorTest.php | 43 +++++---- test/Generator/BooleanGeneratorTest.php | 11 +-- test/Generator/CharacterGeneratorTest.php | 12 +-- test/Generator/ChooseGeneratorTest.php | 24 +++-- test/Generator/ConstantGeneratorTest.php | 8 +- test/Generator/DateGeneratorTest.php | 6 +- test/Generator/ElementsGeneratorTest.php | 4 +- test/Generator/FloatGeneratorTest.php | 13 +-- test/Generator/FrequencyGeneratorTest.php | 28 +++--- test/Generator/GeneratedValueOptionsTest.php | 4 +- test/Generator/GeneratedValueTest.php | 18 ++-- test/Generator/IntegerGeneratorTest.php | 6 +- test/Generator/MapGeneratorTest.php | 4 +- test/Generator/NamesGeneratorTest.php | 14 +-- test/Generator/OneOfGeneratorTest.php | 14 ++- test/Generator/RegexGeneratorTest.php | 6 +- test/Generator/SequenceGeneratorTest.php | 4 +- test/Generator/SetGeneratorTest.php | 4 +- test/Generator/StringGeneratorTest.php | 4 +- test/Generator/SubsetGeneratorTest.php | 6 +- test/Generator/SuchThatGeneratorTest.php | 32 +++---- test/Generator/TupleGeneratorTest.php | 36 ++++---- test/Generator/VectorGeneratorTest.php | 4 +- test/Listener/LogTest.php | 12 +-- test/Listener/MinimumEvaluationsTest.php | 17 ++-- test/PHPUnitCommandTest.php | 2 +- test/PHPUnitDeprecationHelper.php | 90 +++++++++++++++++++ test/Quantifier/SizeTest.php | 4 +- .../TimeBasedTerminationConditionTest.php | 4 +- test/Random/MersenneTwisterTest.php | 6 +- test/Random/RandomRangeTest.php | 2 +- test/SampleTest.php | 2 +- test/Shrinker/FixedTimeLimitTest.php | 2 +- test/Shrinker/MultipleTest.php | 14 ++- test/bootstrap.php | 10 --- 96 files changed, 412 insertions(+), 378 deletions(-) create mode 100644 Makefile create mode 100644 test/PHPUnitDeprecationHelper.php delete mode 100644 test/bootstrap.php diff --git a/.docker/Dockerfile b/.docker/Dockerfile index d78c64b6..cbd5d441 100644 --- a/.docker/Dockerfile +++ b/.docker/Dockerfile @@ -1,4 +1,5 @@ -FROM php:7.4-cli-alpine3.14 +ARG BASE_IMAGE=php:7.4-cli-alpine3.14 +FROM ${BASE_IMAGE} RUN php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer RUN apk add --no-cache python3 \ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 31c2bd54..8718cd26 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,10 +8,12 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: [5.5, 5.6, 7.0, 7.1, 7.2, 7.3, 7.4] + php: [7.1, 7.4, 8.0] dependencies: - "lowest" - "highest" + include: + - { php: 8.1, dependencies: "highest" } steps: - name: Checkout uses: actions/checkout@v2 @@ -19,11 +21,6 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} - - name: Remove dev dependecies for older php versions - if: ${{ matrix.php < 7.1 }} - run: | - composer remove --dev phpstan/phpstan --ignore-platform-reqs --no-update - composer remove --dev psalm/phar --ignore-platform-reqs --no-update - name: Install dependencies uses: ramsey/composer-install@v1 with: @@ -37,12 +34,11 @@ jobs: strategy: matrix: include: + - { phpunit: 9, php: 8.1 } - { phpunit: 9, php: 8.0 } - { phpunit: 8, php: 7.4 } - { phpunit: 7, php: 7.3 } - - { phpunit: 6, php: 7.2 } - - { phpunit: 5, php: 7.1 } - - { phpunit: 4, php: 5.6 } + - { phpunit: 6, php: 7.1 } steps: - name: Checkout uses: actions/checkout@v2 @@ -50,11 +46,6 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} - - name: Remove dev dependecies for older php versions - if: ${{ matrix.php < 7.1 }} - run: | - composer remove --dev phpstan/phpstan --ignore-platform-reqs --no-update - composer remove --dev psalm/phar --ignore-platform-reqs --no-update - name: Install dependencies uses: ramsey/composer-install@v1 - name: Download phpunit phar diff --git a/ChangeLog.md b/ChangeLog.md index c1c04c66..0770036e 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -5,8 +5,11 @@ The project follows [semantic versioning](http://semver.org/). `BC` stands for a ## Unreleased ### Added * `Eris\Generators` contains all the generator constructors as static methods. +* Support for PHP 8.1 ### Changed * The generator constructors implemented as simple function now call the static methods of `Eris\Generators`. They will be deprecated. +### Removed +* Support for PHP < 7.1 ## 0.12.1 ### Changed diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..8fb7445b --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +.PHONY: run-php-7.4 +run-php-7.4: + docker-compose run php-7.4 sh + +.PHONY: run-php-8.1 +run-php-8.1: + docker-compose run php-8.1 sh diff --git a/README.md b/README.md index f8af6048..4f05605d 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ This test tries to verify that natural numbers from 0 to 1000 are all smaller th =5.5" + "php": ">=7.1" }, "require-dev": { - "phpunit/phpunit": ">=4.1 <8", + "phpunit/phpunit": ">=7", "sebastian/comparator": ">=1.2.4", "friendsofphp/php-cs-fixer": "^2.0", "icomefromthenet/reverse-regex": "v0.0.6.3", diff --git a/docker-compose.yml b/docker-compose.yml index 9c4e6fac..ddd08b51 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,9 +5,20 @@ version: "3.8" # Add a docker-compose.override.yml if you need to change one of the following (it won't be tracked) services: - php: + php-7.4: build: context: .docker + args: + BASE_IMAGE: php:7.4-cli-alpine3.14 + volumes: + - .:/usr/src/eris + user: 1000:1000 + working_dir: /usr/src/eris + php-8.1: + build: + context: .docker + args: + BASE_IMAGE: php:8.1-cli-alpine3.14 volumes: - .:/usr/src/eris user: 1000:1000 diff --git a/examples/AlwaysFailsTest.php b/examples/AlwaysFailsTest.php index a178bf5b..36892020 100644 --- a/examples/AlwaysFailsTest.php +++ b/examples/AlwaysFailsTest.php @@ -3,7 +3,7 @@ use Eris\Generators; use Eris\TestTrait; -class AlwaysFailsTest extends \PHPUnit_Framework_TestCase +class AlwaysFailsTest extends \PHPUnit\Framework\TestCase { use TestTrait; diff --git a/examples/AssociativeArrayTest.php b/examples/AssociativeArrayTest.php index db04d338..0772c40f 100644 --- a/examples/AssociativeArrayTest.php +++ b/examples/AssociativeArrayTest.php @@ -2,7 +2,7 @@ use Eris\Generators; -class AssociativeArrayTest extends PHPUnit_Framework_TestCase +class AssociativeArrayTest extends \PHPUnit\Framework\TestCase { use Eris\TestTrait; @@ -15,11 +15,11 @@ public function testAssociativeArraysGeneratedOnStandardKeys() ]) ) ->then(function ($array) { - $this->assertEquals(2, count($array)); + $this->assertCount(2, $array); $letter = $array['letter']; - $this->assertInternalType('string', $letter); + \Eris\PHPUnitDeprecationHelper::assertIsString($letter); $cipher = $array['cipher']; - $this->assertInternalType('integer', $cipher); + \Eris\PHPUnitDeprecationHelper::assertIsInt($cipher); }); } } diff --git a/examples/BindTest.php b/examples/BindTest.php index c690cb07..4c8c15bb 100644 --- a/examples/BindTest.php +++ b/examples/BindTest.php @@ -2,7 +2,7 @@ use Eris\Generators; -class BindTest extends PHPUnit_Framework_TestCase +class BindTest extends \PHPUnit\Framework\TestCase { use Eris\TestTrait; diff --git a/examples/BooleanTest.php b/examples/BooleanTest.php index b13e288c..aa9714ac 100644 --- a/examples/BooleanTest.php +++ b/examples/BooleanTest.php @@ -3,7 +3,7 @@ use Eris\Generators; use Eris\TestTrait; -class BooleanTest extends PHPUnit_Framework_TestCase +class BooleanTest extends \PHPUnit\Framework\TestCase { use TestTrait; diff --git a/examples/CharacterTest.php b/examples/CharacterTest.php index 0890aabf..d2bf7302 100644 --- a/examples/CharacterTest.php +++ b/examples/CharacterTest.php @@ -3,7 +3,7 @@ use Eris\Antecedents; use Eris\Generators; -class CharacterTest extends PHPUnit_Framework_TestCase +class CharacterTest extends \PHPUnit\Framework\TestCase { use Eris\TestTrait; diff --git a/examples/ChooseTest.php b/examples/ChooseTest.php index 734e15be..eae7a176 100644 --- a/examples/ChooseTest.php +++ b/examples/ChooseTest.php @@ -3,7 +3,7 @@ use Eris\Generators; use Eris\TestTrait; -class ChooseTest extends PHPUnit_Framework_TestCase +class ChooseTest extends \PHPUnit\Framework\TestCase { use TestTrait; diff --git a/examples/CollectTest.php b/examples/CollectTest.php index aabce91e..3cbc7f95 100644 --- a/examples/CollectTest.php +++ b/examples/CollectTest.php @@ -4,7 +4,7 @@ use Eris\Listeners; use Eris\TestTrait; -class CollectTest extends PHPUnit_Framework_TestCase +class CollectTest extends \PHPUnit\Framework\TestCase { use TestTrait; diff --git a/examples/ConstantTest.php b/examples/ConstantTest.php index 855c6695..8f98f5ed 100644 --- a/examples/ConstantTest.php +++ b/examples/ConstantTest.php @@ -2,7 +2,7 @@ use Eris\Generators; -class ConstantTest extends \PHPUnit_Framework_TestCase +class ConstantTest extends \PHPUnit\Framework\TestCase { use Eris\TestTrait; diff --git a/examples/DateTest.php b/examples/DateTest.php index 66f9d627..ed13777f 100644 --- a/examples/DateTest.php +++ b/examples/DateTest.php @@ -2,7 +2,7 @@ use Eris\Generators; -class DateTest extends PHPUnit_Framework_TestCase +class DateTest extends \PHPUnit\Framework\TestCase { use Eris\TestTrait; diff --git a/examples/DifferentElementsTest.php b/examples/DifferentElementsTest.php index 2174e1f1..7065c70c 100644 --- a/examples/DifferentElementsTest.php +++ b/examples/DifferentElementsTest.php @@ -32,7 +32,7 @@ public static function C() } } -class DifferentElementsTest extends \PHPUnit_Framework_TestCase +class DifferentElementsTest extends \PHPUnit\Framework\TestCase { use TestTrait; diff --git a/examples/DisableShrinkingTest.php b/examples/DisableShrinkingTest.php index aa69ec35..3581f3f1 100644 --- a/examples/DisableShrinkingTest.php +++ b/examples/DisableShrinkingTest.php @@ -3,7 +3,7 @@ use Eris\Generators; use Eris\TestTrait; -class DisableShrinkingTest extends \PHPUnit_Framework_TestCase +class DisableShrinkingTest extends \PHPUnit\Framework\TestCase { use TestTrait; diff --git a/examples/ElementsTest.php b/examples/ElementsTest.php index 5b28402b..b85feac5 100644 --- a/examples/ElementsTest.php +++ b/examples/ElementsTest.php @@ -2,7 +2,7 @@ use Eris\Generators; -class ElementsTest extends \PHPUnit_Framework_TestCase +class ElementsTest extends \PHPUnit\Framework\TestCase { use Eris\TestTrait; diff --git a/examples/ErrorTest.php b/examples/ErrorTest.php index be00b1e6..38098e8d 100644 --- a/examples/ErrorTest.php +++ b/examples/ErrorTest.php @@ -2,7 +2,7 @@ use Eris\Generators; -class ErrorTest extends \PHPUnit_Framework_TestCase +class ErrorTest extends \PHPUnit\Framework\TestCase { use Eris\TestTrait; diff --git a/examples/FloatTest.php b/examples/FloatTest.php index 92d54280..ee601484 100644 --- a/examples/FloatTest.php +++ b/examples/FloatTest.php @@ -2,7 +2,7 @@ use Eris\Generators; -class FloatTest extends \PHPUnit_Framework_TestCase +class FloatTest extends \PHPUnit\Framework\TestCase { use Eris\TestTrait; diff --git a/examples/FrequencyTest.php b/examples/FrequencyTest.php index a895d463..a0e70289 100644 --- a/examples/FrequencyTest.php +++ b/examples/FrequencyTest.php @@ -2,7 +2,7 @@ use Eris\Generators; -class FrequencyTest extends \PHPUnit_Framework_TestCase +class FrequencyTest extends \PHPUnit\Framework\TestCase { use Eris\TestTrait; diff --git a/examples/GeneratorSamplesTest.php b/examples/GeneratorSamplesTest.php index 0fc97af0..3d397ebd 100644 --- a/examples/GeneratorSamplesTest.php +++ b/examples/GeneratorSamplesTest.php @@ -3,7 +3,7 @@ use Eris\Generators; use Eris\TestTrait; -class GeneratorSamplesTest extends PHPUnit_Framework_TestCase +class GeneratorSamplesTest extends \PHPUnit\Framework\TestCase { use TestTrait; @@ -36,7 +36,7 @@ private function generateSample($description, $generator) echo PHP_EOL; echo $description . " with size 10"; $sample = $this->sample($generator); - $this->assertInternalType('array', $sample->collected()); + \Eris\PHPUnitDeprecationHelper::assertIsArray($sample->collected()); $this->prettyPrint($sample->collected()); } diff --git a/examples/IntegerTest.php b/examples/IntegerTest.php index f2184704..2915dac2 100644 --- a/examples/IntegerTest.php +++ b/examples/IntegerTest.php @@ -3,7 +3,7 @@ use Eris\Generators; use Eris\TestTrait; -class IntegerTest extends PHPUnit_Framework_TestCase +class IntegerTest extends \PHPUnit\Framework\TestCase { use TestTrait; diff --git a/examples/LimitToTest.php b/examples/LimitToTest.php index cfa3a27f..c57130ef 100644 --- a/examples/LimitToTest.php +++ b/examples/LimitToTest.php @@ -3,7 +3,7 @@ use Eris\Generators; use Eris\TestTrait; -class LimitToTest extends PHPUnit_Framework_TestCase +class LimitToTest extends \PHPUnit\Framework\TestCase { use TestTrait; @@ -16,7 +16,7 @@ public function testNumberOfIterationsCanBeConfigured() Generators::int() ) ->then(function ($value) { - $this->assertInternalType('integer', $value); + \Eris\PHPUnitDeprecationHelper::assertIsInt($value); }); } diff --git a/examples/LogFileTest.php b/examples/LogFileTest.php index 98d79303..05a46568 100644 --- a/examples/LogFileTest.php +++ b/examples/LogFileTest.php @@ -4,11 +4,11 @@ use Eris\Listeners; use Eris\TestTrait; -class LogFileTest extends PHPUnit_Framework_TestCase +class LogFileTest extends \PHPUnit\Framework\TestCase { use TestTrait; - public function testWritingIterationsOnALogFile() + public function testWritingIterationsOnALogFile(): void { $this ->forAll( @@ -16,11 +16,11 @@ public function testWritingIterationsOnALogFile() ) ->hook(Listeners::log(sys_get_temp_dir().'/eris-log-file-test.log')) ->then(function ($number) { - $this->assertInternalType('integer', $number); + \Eris\PHPUnitDeprecationHelper::assertIsInt($number); }); } - public function testLogOfFailuresAndShrinking() + public function testLogOfFailuresAndShrinking(): void { $this ->forAll( diff --git a/examples/MapTest.php b/examples/MapTest.php index eab1f1a5..8dcd6266 100644 --- a/examples/MapTest.php +++ b/examples/MapTest.php @@ -2,7 +2,7 @@ use Eris\Generators; -class MapTest extends PHPUnit_Framework_TestCase +class MapTest extends \PHPUnit\Framework\TestCase { use Eris\TestTrait; diff --git a/examples/MinimumEvaluationsTest.php b/examples/MinimumEvaluationsTest.php index 69aca00f..da7421ac 100644 --- a/examples/MinimumEvaluationsTest.php +++ b/examples/MinimumEvaluationsTest.php @@ -2,7 +2,7 @@ use Eris\Generators; -class MinimumEvaluationsTest extends PHPUnit_Framework_TestCase +class MinimumEvaluationsTest extends \PHPUnit\Framework\TestCase { use Eris\TestTrait; diff --git a/examples/NamesTest.php b/examples/NamesTest.php index 70614c50..6222270a 100644 --- a/examples/NamesTest.php +++ b/examples/NamesTest.php @@ -3,7 +3,7 @@ use Eris\Generator; use Eris\Generators; -class NamesTest extends PHPUnit_Framework_TestCase +class NamesTest extends \PHPUnit\Framework\TestCase { use Eris\TestTrait; @@ -12,7 +12,7 @@ public function testGeneratingNames() $this->forAll( Generators::names() )->then(function ($name) { - $this->assertInternalType('string', $name); + \Eris\PHPUnitDeprecationHelper::assertIsString($name); var_dump($name); }); } @@ -21,7 +21,7 @@ public function testSamplingShrinkingOfNames() { $generator = Generator\NamesGenerator::defaultDataSet(); $sample = $this->sampleShrink($generator); - $this->assertInternalType('array', $sample->collected()); + \Eris\PHPUnitDeprecationHelper::assertIsArray($sample->collected()); var_dump($sample->collected()); } } diff --git a/examples/OneOfTest.php b/examples/OneOfTest.php index c1729ac6..96e22e51 100644 --- a/examples/OneOfTest.php +++ b/examples/OneOfTest.php @@ -2,7 +2,7 @@ use Eris\Generators; -class OneOfTest extends \PHPUnit_Framework_TestCase +class OneOfTest extends \PHPUnit\Framework\TestCase { use Eris\TestTrait; diff --git a/examples/RandConfigurationTest.php b/examples/RandConfigurationTest.php index e74c5bdc..c13afa9c 100644 --- a/examples/RandConfigurationTest.php +++ b/examples/RandConfigurationTest.php @@ -4,7 +4,7 @@ use Eris\Random; use Eris\TestTrait; -class RandConfigurationTest extends PHPUnit_Framework_TestCase +class RandConfigurationTest extends \PHPUnit\Framework\TestCase { use TestTrait; @@ -72,7 +72,7 @@ public function testUsingThePurePhpMtRandFunction() private function isInteger() { return function ($number) { - $this->assertInternalType('integer', $number); + \Eris\PHPUnitDeprecationHelper::assertIsInt($number); }; } } diff --git a/examples/ReadmeTest.php b/examples/ReadmeTest.php index 53b3e70b..0b0c2d49 100644 --- a/examples/ReadmeTest.php +++ b/examples/ReadmeTest.php @@ -2,7 +2,7 @@ use Eris\Generators; -class ReadmeTest extends \PHPUnit_Framework_TestCase +class ReadmeTest extends \PHPUnit\Framework\TestCase { use Eris\TestTrait; diff --git a/examples/RegexTest.php b/examples/RegexTest.php index 82c45d54..68a44cc9 100644 --- a/examples/RegexTest.php +++ b/examples/RegexTest.php @@ -2,7 +2,7 @@ use Eris\Generators; -class RegexTest extends \PHPUnit_Framework_TestCase +class RegexTest extends \PHPUnit\Framework\TestCase { use Eris\TestTrait; diff --git a/examples/SequenceTest.php b/examples/SequenceTest.php index ce84258c..e162d43f 100644 --- a/examples/SequenceTest.php +++ b/examples/SequenceTest.php @@ -2,7 +2,7 @@ use Eris\Generators; -class SequenceTest extends PHPUnit_Framework_TestCase +class SequenceTest extends \PHPUnit\Framework\TestCase { use Eris\TestTrait; @@ -13,7 +13,7 @@ public function testArrayReversePreserveLength() Generators::seq(Generators::nat()) ) ->then(function ($array) { - $this->assertEquals(count($array), count(array_reverse($array))); + self::assertCount(count($array), array_reverse($array)); }); } diff --git a/examples/SetTest.php b/examples/SetTest.php index fa2d0222..3b03de9e 100644 --- a/examples/SetTest.php +++ b/examples/SetTest.php @@ -3,7 +3,7 @@ use Eris\Generators; use Eris\TestTrait; -class SetTest extends PHPUnit_Framework_TestCase +class SetTest extends \PHPUnit\Framework\TestCase { use TestTrait; @@ -13,7 +13,7 @@ public function testSetsOfAnotherGeneratorsDomain() Generators::set(Generators::nat()) ) ->then(function ($set) { - $this->assertInternalType('array', $set); + \Eris\PHPUnitDeprecationHelper::assertIsArray($set); foreach ($set as $element) { $this->assertGreaterThanOrEqual(0, $element); } diff --git a/examples/ShrinkingTest.php b/examples/ShrinkingTest.php index 1f6e36e8..fdb81386 100644 --- a/examples/ShrinkingTest.php +++ b/examples/ShrinkingTest.php @@ -3,7 +3,7 @@ use Eris\Generators; use Eris\TestTrait; -class ShrinkingTest extends \PHPUnit_Framework_TestCase +class ShrinkingTest extends \PHPUnit\Framework\TestCase { use TestTrait; @@ -14,7 +14,7 @@ public function testShrinkingAString() ) ->then(function ($string) { var_dump($string); - $this->assertNotContains('B', $string); + \Eris\PHPUnitDeprecationHelper::assertStringNotContainsString('B', $string); }); } diff --git a/examples/ShrinkingTimeLimitTest.php b/examples/ShrinkingTimeLimitTest.php index 2c9a47ba..a46b6e78 100644 --- a/examples/ShrinkingTimeLimitTest.php +++ b/examples/ShrinkingTimeLimitTest.php @@ -12,7 +12,7 @@ function very_slow_concatenation($first, $second) return $first . $second; } -class ShrinkingTimeLimitTest extends PHPUnit_Framework_TestCase +class ShrinkingTimeLimitTest extends \PHPUnit\Framework\TestCase { use Eris\TestTrait; diff --git a/examples/SizeTest.php b/examples/SizeTest.php index 9a79c721..c1e6e62c 100644 --- a/examples/SizeTest.php +++ b/examples/SizeTest.php @@ -3,7 +3,7 @@ use Eris\Generators; use Eris\TestTrait; -class SizeTest extends PHPUnit_Framework_TestCase +class SizeTest extends \PHPUnit\Framework\TestCase { use TestTrait; diff --git a/examples/SortTest.php b/examples/SortTest.php index f3bd2d62..9e87099a 100644 --- a/examples/SortTest.php +++ b/examples/SortTest.php @@ -2,7 +2,7 @@ use Eris\Generators; -class SortTest extends PHPUnit_Framework_TestCase +class SortTest extends \PHPUnit\Framework\TestCase { use Eris\TestTrait; diff --git a/examples/StringTest.php b/examples/StringTest.php index 27cab426..8398fac8 100644 --- a/examples/StringTest.php +++ b/examples/StringTest.php @@ -11,7 +11,7 @@ function string_concatenation($first, $second) return $first . $second; } -class StringTest extends PHPUnit_Framework_TestCase +class StringTest extends \PHPUnit\Framework\TestCase { use Eris\TestTrait; diff --git a/examples/SubsetTest.php b/examples/SubsetTest.php index 4111747b..c6c6ac16 100644 --- a/examples/SubsetTest.php +++ b/examples/SubsetTest.php @@ -2,8 +2,9 @@ use Eris\Generators; use Eris\TestTrait; +use PHPUnit\Framework\TestCase; -class SubsetTest extends PHPUnit_Framework_TestCase +class SubsetTest extends TestCase { use TestTrait; @@ -15,7 +16,7 @@ public function testSubsetsOfASet() ]) ) ->then(function ($set) { - $this->assertInternalType('array', $set); + \Eris\PHPUnitDeprecationHelper::assertIsArray($set); foreach ($set as $element) { $this->assertTrue($this->isEven($element), "Element $element is not even, where did it come from?"); } diff --git a/examples/SuchThatTest.php b/examples/SuchThatTest.php index 9817a1cd..5df6aa3c 100644 --- a/examples/SuchThatTest.php +++ b/examples/SuchThatTest.php @@ -3,7 +3,7 @@ use Eris\Generators; use Eris\Listeners; -class SuchThatTest extends \PHPUnit_Framework_TestCase +class SuchThatTest extends \PHPUnit\Framework\TestCase { use Eris\TestTrait; @@ -48,7 +48,7 @@ public function testSuchThatAcceptsPHPUnitConstraints() Generators::vector( 5, Generators::suchThat( - $this->isType('integer'), + $this->isType('int'), Generators::oneOf( Generators::choose(0, 1000), Generators::string() diff --git a/examples/SumTest.php b/examples/SumTest.php index d321490a..5e2d02be 100644 --- a/examples/SumTest.php +++ b/examples/SumTest.php @@ -10,7 +10,7 @@ function my_sum($first, $second) return $first + $second; } -class SumTest extends PHPUnit_Framework_TestCase +class SumTest extends \PHPUnit\Framework\TestCase { use Eris\TestTrait; diff --git a/examples/TupleTest.php b/examples/TupleTest.php index 3822ddc7..5221bbc6 100644 --- a/examples/TupleTest.php +++ b/examples/TupleTest.php @@ -2,7 +2,7 @@ use Eris\Generators; -class TupleTest extends PHPUnit_Framework_TestCase +class TupleTest extends \PHPUnit\Framework\TestCase { use Eris\TestTrait; diff --git a/examples/VectorTest.php b/examples/VectorTest.php index 61dcd472..78112c6e 100644 --- a/examples/VectorTest.php +++ b/examples/VectorTest.php @@ -2,7 +2,7 @@ use Eris\Generators; -class VectorTest extends PHPUnit_Framework_TestCase +class VectorTest extends \PHPUnit\Framework\TestCase { use Eris\TestTrait; diff --git a/examples/WhenTest.php b/examples/WhenTest.php index 8ae68bc1..56e431c5 100644 --- a/examples/WhenTest.php +++ b/examples/WhenTest.php @@ -2,7 +2,7 @@ use Eris\Generators; -class WhenTest extends \PHPUnit_Framework_TestCase +class WhenTest extends \PHPUnit\Framework\TestCase { use Eris\TestTrait; diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 6ff8fbab..09bd1446 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,22 +1,17 @@ parameters: ignoreErrors: - - message: "#^Caught class PHPUnit_Framework_ExpectationFailedException not found\\.$#" + message: "#^Anonymous function has an unused use \\$i\\.$#" count: 1 - path: src/Antecedent/IndependentConstraintsAntecedent.php + path: examples/SuchThatTest.php - - message: "#^Caught class PHPUnit_Framework_ExpectationFailedException not found\\.$#" - count: 1 - path: src/Generator/SuchThatGenerator.php + message: "#^Static method Eris\\\\Generators\\:\\:nat\\(\\) invoked with 1 parameter, 0 required\\.$#" + count: 6 + path: examples/SumTest.php - - message: "#^Class PHPUnit_Framework_Constraint not found\\.$#" - count: 1 - path: src/Generator/SuchThatGenerator.php - - - - message: "#^Class PHPUnit_Framework_Constraint not found\\.$#" - count: 1 - path: src/Quantifier/ForAll.php + message: "#^Static method Eris\\\\Generators\\:\\:nat\\(\\) invoked with 1 parameter, 0 required\\.$#" + count: 2 + path: examples/VectorTest.php diff --git a/phpstan.neon b/phpstan.neon index ea368ad2..b7397dfd 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -2,9 +2,7 @@ includes: - phpstan-baseline.neon parameters: - level: 0 - bootstrapFiles: - - test/bootstrap.php + level: 1 paths: - src - test diff --git a/phpunit.xml b/phpunit.xml index cad10985..c7a8fd4b 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,9 +1,8 @@ @@ -14,6 +13,7 @@ ./test/ExampleEnd2EndTest.php + ./test/PHPUnitDeprecationHelper.php diff --git a/psalm-baseline.xml b/psalm-baseline.xml index ae34e755..629a4068 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,28 +1,2 @@ - - - - PHPUnit_Framework_ExpectationFailedException - - - - - PHPUnit_Framework_Constraint - - - callable|PHPUnit_Framework_Constraint|Constraint - callable|PHPUnit_Framework_Constraint|Constraint - - - - - callable|PHPUnit_Framework_Constraint|Constraint - callable|PHPUnit_Framework_Constraint|Constraint - - - - - PHPUnit_Framework_Constraint - - - + diff --git a/src/Antecedent/IndependentConstraintsAntecedent.php b/src/Antecedent/IndependentConstraintsAntecedent.php index f458ce3f..c98369ca 100644 --- a/src/Antecedent/IndependentConstraintsAntecedent.php +++ b/src/Antecedent/IndependentConstraintsAntecedent.php @@ -1,9 +1,8 @@ constraints); $i++) { + for ($i = 0, $iMax = count($this->constraints); $i < $iMax; $i++) { // TODO: use Evaluation object? try { $this->constraints[$i]->evaluate($values[$i]); - } catch (PHPUnit_Framework_ExpectationFailedException $e) { - return false; } catch (ExpectationFailedException $e) { return false; } diff --git a/src/Generator/AssociativeArrayGenerator.php b/src/Generator/AssociativeArrayGenerator.php index c84195f1..1f60cf3b 100644 --- a/src/Generator/AssociativeArrayGenerator.php +++ b/src/Generator/AssociativeArrayGenerator.php @@ -43,7 +43,7 @@ private function mapToAssociativeArray(GeneratedValue $tuple) function ($value) { $associativeArray = []; $keys = array_keys($this->generators); - for ($i = 0; $i < count($value); $i++) { + for ($i = 0, $iMax = count($value); $i < $iMax; $i++) { $key = $keys[$i]; $associativeArray[$key] = $value[$i]; } diff --git a/src/Generator/GeneratedValueOptions.php b/src/Generator/GeneratedValueOptions.php index 8f2fd8f5..a30a0577 100644 --- a/src/Generator/GeneratedValueOptions.php +++ b/src/Generator/GeneratedValueOptions.php @@ -116,12 +116,12 @@ public function generatorName() return $this->last()->generatorName(); } - public function getIterator() + public function getIterator(): \Traversable { return new ArrayIterator($this->generatedValues); } - public function count() + public function count(): int { return count($this->generatedValues); } diff --git a/src/Generator/GeneratedValueSingle.php b/src/Generator/GeneratedValueSingle.php index 3a73a307..3f2820f1 100644 --- a/src/Generator/GeneratedValueSingle.php +++ b/src/Generator/GeneratedValueSingle.php @@ -127,14 +127,14 @@ function ($value) { ); } - public function getIterator() + public function getIterator(): \Traversable { return new ArrayIterator([ $this ]); } - public function count() + public function count(): int { return 1; } diff --git a/src/Generator/SuchThatGenerator.php b/src/Generator/SuchThatGenerator.php index d3737831..325d9f42 100644 --- a/src/Generator/SuchThatGenerator.php +++ b/src/Generator/SuchThatGenerator.php @@ -5,14 +5,12 @@ use Eris\Generators; use Eris\Random\RandomRange; use LogicException; -use PHPUnit_Framework_Constraint; use PHPUnit\Framework\Constraint\Constraint; -use PHPUnit_Framework_ExpectationFailedException; use PHPUnit\Framework\ExpectationFailedException; use Traversable; /** - * @param callable|PHPUnit_Framework_Constraint|Constraint $filter + * @param callable|Constraint $filter * @return SuchThatGenerator */ function filter($filter, Generator $generator, $maximumAttempts = 100) @@ -21,7 +19,7 @@ function filter($filter, Generator $generator, $maximumAttempts = 100) } /** - * @param callable|PHPUnit_Framework_Constraint|Constraint $filter + * @param callable|Constraint $filter * @return SuchThatGenerator */ function suchThat($filter, Generator $generator, $maximumAttempts = 100) @@ -36,7 +34,7 @@ class SuchThatGenerator implements Generator private $maximumAttempts; /** - * @param callable|PHPUnit_Framework_Constraint|Constraint + * @param callable|Constraint */ public function __construct($filter, $generator, $maximumAttempts = 100) { @@ -89,12 +87,10 @@ private function filterForPredicate(Traversable $options) private function predicate(GeneratedValueSingle $value) { - if ($this->filter instanceof PHPUnit_Framework_Constraint || $this->filter instanceof Constraint) { + if ($this->filter instanceof Constraint) { try { $this->filter->evaluate($value->unbox()); return true; - } catch (PHPUnit_Framework_ExpectationFailedException $e) { - return false; } catch (ExpectationFailedException $e) { return false; } diff --git a/src/Generators.php b/src/Generators.php index 3a81f7aa..f9ceeb4a 100644 --- a/src/Generators.php +++ b/src/Generators.php @@ -243,7 +243,7 @@ public static function subset($input) } /** - * @param callable|PHPUnit_Framework_Constraint|Constraint $filter + * @param callable|Constraint $filter * @return SuchThatGenerator */ public static function filter($filter, Generator $generator, $maximumAttempts = 100) @@ -252,7 +252,7 @@ public static function filter($filter, Generator $generator, $maximumAttempts = } /** - * @param callable|PHPUnit_Framework_Constraint|Constraint $filter + * @param callable|Constraint $filter * @return SuchThatGenerator */ public static function suchThat($filter, Generator $generator, $maximumAttempts = 100) diff --git a/src/Quantifier/Evaluation.php b/src/Quantifier/Evaluation.php index 5c46dab8..e7100679 100644 --- a/src/Quantifier/Evaluation.php +++ b/src/Quantifier/Evaluation.php @@ -2,7 +2,6 @@ namespace Eris\Quantifier; use Eris\Generator\GeneratedValueSingle; -use PHPUnit_Framework_AssertionFailedError; use PHPUnit\Framework\AssertionFailedError; /** @@ -54,9 +53,6 @@ public function execute() $this->assertion, $this->values->unbox() ); - } catch (PHPUnit_Framework_AssertionFailedError $e) { - call_user_func($this->onFailure, $this->values, $e); - return; } catch (AssertionFailedError $e) { call_user_func($this->onFailure, $this->values, $e); return; diff --git a/src/Quantifier/ForAll.php b/src/Quantifier/ForAll.php index 618f114c..4b2ddce8 100644 --- a/src/Quantifier/ForAll.php +++ b/src/Quantifier/ForAll.php @@ -7,7 +7,6 @@ use Eris\Generator\GeneratedValueSingle; use Eris\Generator\SkipValueException; use BadMethodCallException; -use PHPUnit_Framework_Constraint; use PHPUnit\Framework\Constraint\Constraint; use Exception; use RuntimeException; @@ -99,8 +98,6 @@ public function when(/* see docblock */) $arguments = func_get_args(); if ($arguments[0] instanceof Antecedent) { $antecedent = $arguments[0]; - } elseif ($arguments[0] instanceof PHPUnit_Framework_Constraint) { - $antecedent = Antecedent\IndependentConstraintsAntecedent::fromAll($arguments); } elseif ($arguments[0] instanceof Constraint) { $antecedent = Antecedent\IndependentConstraintsAntecedent::fromAll($arguments); } elseif ($arguments && count($arguments) == 1) { diff --git a/src/Quantifier/Size.php b/src/Quantifier/Size.php index 023ee8aa..89224b47 100644 --- a/src/Quantifier/Size.php +++ b/src/Quantifier/Size.php @@ -81,7 +81,7 @@ public function limit($maximumNumber) return new self($uniformSample); } - public function count() + public function count(): int { return count($this->list); } diff --git a/test/ExampleEnd2EndTest.php b/test/ExampleEnd2EndTest.php index 01987511..74e16192 100644 --- a/test/ExampleEnd2EndTest.php +++ b/test/ExampleEnd2EndTest.php @@ -3,7 +3,7 @@ use SimpleXMLElement; -class ExampleEnd2EndTest extends \PHPUnit_Framework_TestCase +class ExampleEnd2EndTest extends \PHPUnit\Framework\TestCase { private $testFile; private $testsByName; @@ -63,7 +63,7 @@ public function testStringShrinkingTests() $this->runExample('StringTest.php'); $this->assertTestsAreFailing(1); $errorMessage = (string) $this->theTest('testLengthPreservation')->failure; - $this->assertRegExp( + PHPUnitDeprecationHelper::assertMatchesRegularExpression( "/Concatenating '' to '.{6}' gives '.{6}ERROR'/", $errorMessage, "It seems there is a problem with shrinking: we were expecting a minimal error message but instead the one for StringTest::testLengthPreservation() didn't match" @@ -74,11 +74,11 @@ public function testShrinkingAndAntecedentsTests() { $this->runExample('ShrinkingTest.php'); $this->assertTestsAreFailing(2); - $this->assertRegExp( + PHPUnitDeprecationHelper::assertMatchesRegularExpression( "/Failed asserting that .* does not contain \"B\"/", (string) $this->theTest('testShrinkingAString')->failure ); - $this->assertRegExp( + PHPUnitDeprecationHelper::assertMatchesRegularExpression( "/The number 11 is not multiple of 29/", (string) $this->theTest('testShrinkingRespectsAntecedents')->failure, "It seems there is a problem with shrinking: we were expecting an error message containing '11' since it's the lowest value in the domain that satisfies the antecedents." @@ -90,7 +90,7 @@ public function testShrinkingTimeLimitTest() $this->runExample('ShrinkingTimeLimitTest.php'); $this->assertTestsAreFailing(2); $executionTime = (float) $this->theTest('testLengthPreservation')->attributes()['time']; - $this->assertRegexp( + PHPUnitDeprecationHelper::assertMatchesRegularExpression( '/Eris has reached the time limit for shrinking/', (string) $this->theTest('testLengthPreservation')->error, var_export($this->theTest('testLengthPreservation'), true) @@ -103,7 +103,7 @@ public function testDisableShrinkingTest() { $this->runExample('DisableShrinkingTest.php'); $this->assertTestsAreFailing(1); - $this->assertRegExp( + PHPUnitDeprecationHelper::assertMatchesRegularExpression( '/Total calls: 1\n/', (string) $this->theTest('testThenIsNotCalledMultipleTime')->failure ); @@ -132,7 +132,7 @@ public function testGenericErrorTest() $this->runExample('ErrorTest.php'); $this->assertTestsAreFailing(1); $errorMessage = (string) $this->theTest('testGenericExceptionsDoNotShrinkButStillShowTheInput')->error; - $this->assertRegExp( + PHPUnitDeprecationHelper::assertMatchesRegularExpression( "/Original input:/", $errorMessage ); @@ -160,7 +160,7 @@ public function testFrequencyTests() { $this->runExample('FrequencyTest.php'); $this->assertTestsAreFailing(1); - $this->assertRegExp( + PHPUnitDeprecationHelper::assertMatchesRegularExpression( '/Failed asserting that (1|100|200) matches expected 0./', (string) $this->theTest('testAlwaysFails')->failure ); @@ -170,15 +170,15 @@ public function testSuchThatTest() { $this->runExample('SuchThatTest.php'); $this->assertTestsAreFailing(3); - $this->assertRegexp( + PHPUnitDeprecationHelper::assertMatchesRegularExpression( '/number was asserted to be more than 100, but it\'s 43/', (string) $this->theTest('testSuchThatShrinkingRespectsTheCondition')->failure ); - $this->assertRegexp( + PHPUnitDeprecationHelper::assertMatchesRegularExpression( '/number was asserted to be more than 42, but it\'s 0/', (string) $this->theTest('testSuchThatAcceptsPHPUnitConstraints')->failure ); - $this->assertRegexp( + PHPUnitDeprecationHelper::assertMatchesRegularExpression( '/number was asserted to be more than 100, but it\'s 0/', (string) $this->theTest('testSuchThatShrinkingRespectsTheConditionButTriesToSkipOverTheNotAllowedSet')->failure ); @@ -188,11 +188,11 @@ public function testWhenTests() { $this->runExample('WhenTest.php'); $this->assertTestsAreFailing(2); - $this->assertRegExp( + PHPUnitDeprecationHelper::assertMatchesRegularExpression( "/should be less or equal to 100, but/", (string) $this->theTest('testWhenFailingWillNaturallyHaveALowEvaluationRatioSoWeDontWantThatErrorToObscureTheTrueOne')->failure ); - $this->assertRegExp( + PHPUnitDeprecationHelper::assertMatchesRegularExpression( "/Evaluation ratio .* is under the threshold/", (string) $this->theTest('testWhenWhichSkipsTooManyValues')->error ); @@ -202,11 +202,11 @@ public function testMapTest() { $this->runExample('MapTest.php'); $this->assertTestsAreFailing(2); - $this->assertRegExp( + PHPUnitDeprecationHelper::assertMatchesRegularExpression( "/number is not less than 100/", (string) $this->theTest('testShrinkingJustMappedValues')->failure ); - $this->assertRegExp( + PHPUnitDeprecationHelper::assertMatchesRegularExpression( "/triple sum array/", (string) $this->theTest('testShrinkingMappedValuesInsideOtherGenerators')->failure ); @@ -216,7 +216,7 @@ public function testLogFileTest() { $this->runExample('LogFileTest.php'); $this->assertTestsAreFailing(1); - $this->assertRegexp( + PHPUnitDeprecationHelper::assertMatchesRegularExpression( "/asserting that 43 is equal to 42 or is less than 42/", (string) $this->theTest('testLogOfFailuresAndShrinking')->failure ); @@ -243,7 +243,7 @@ public function testSizeCustomization() { $this->runExample('SizeTest.php'); $this->assertTestsAreFailing(1); - $this->assertRegexp( + PHPUnitDeprecationHelper::assertMatchesRegularExpression( "/Failed asserting that 100000 is less than 100000/", (string) $this->theTest('testMaxSizeCanBeIncreased')->failure ); @@ -253,7 +253,7 @@ public function testMinimumEvaluations() { $this->runExample('MinimumEvaluationsTest.php'); $this->assertTestsAreFailing(1); - $this->assertRegexp( + PHPUnitDeprecationHelper::assertMatchesRegularExpression( "/Evaluation ratio 0\..* is under the threshold 0\.5/", (string) $this->theTest('testFailsBecauseOfTheLowEvaluationRatio')->error ); diff --git a/test/Generator/AssociativeArrayGeneratorTest.php b/test/Generator/AssociativeArrayGeneratorTest.php index f98a5c64..ac41e4e7 100644 --- a/test/Generator/AssociativeArrayGeneratorTest.php +++ b/test/Generator/AssociativeArrayGeneratorTest.php @@ -3,8 +3,9 @@ use Eris\Random\RandomRange; use Eris\Random\RandSource; +use PHPUnit\Framework\TestCase; -class AssociativeArrayGeneratorTest extends \PHPUnit_Framework_TestCase +class AssociativeArrayGeneratorTest extends TestCase { /** * @var ElementsGenerator @@ -27,7 +28,7 @@ class AssociativeArrayGeneratorTest extends \PHPUnit_Framework_TestCase */ private $rand; - protected function setUp() + protected function setUp(): void { $this->letterGenerator = ElementsGenerator::fromArray(['A', 'B', 'C']); $this->cipherGenerator = ElementsGenerator::fromArray([0, 1, 2]); @@ -36,7 +37,7 @@ protected function setUp() $this->rand = new RandomRange(new RandSource()); } - public function testConstructWithAnAssociativeArrayOfGenerators() + public function testConstructWithAnAssociativeArrayOfGenerators(): void { $generator = new AssociativeArrayGenerator([ 'letter' => $this->letterGenerator, @@ -46,18 +47,18 @@ public function testConstructWithAnAssociativeArrayOfGenerators() $generated = $generator($this->size, $this->rand); $array = $generated->unbox(); - $this->assertEquals(2, count($array)); + $this->assertCount(2, $array); $letter = $array['letter']; - $this->assertInternalType('string', $letter); + \Eris\PHPUnitDeprecationHelper::assertIsString($letter); $this->assertEquals(1, strlen($letter)); $cipher = $array['cipher']; - $this->assertInternalType('integer', $cipher); + \Eris\PHPUnitDeprecationHelper::assertIsInt($cipher); $this->assertGreaterThanOrEqual(0, $cipher); $this->assertLessThanOrEqual(9, $cipher); - $this->assertSame(2, count($generated->unbox())); + $this->assertCount(2, $generated->unbox()); } - public function testShrinksTheGeneratorsButKeepsAllTheKeysPresent() + public function testShrinksTheGeneratorsButKeepsAllTheKeysPresent(): void { $generator = new AssociativeArrayGenerator([ 'former' => $this->smallIntegerGenerator, @@ -70,13 +71,13 @@ public function testShrinksTheGeneratorsButKeepsAllTheKeysPresent() $value = GeneratedValueOptions::mostPessimisticChoice($value); $value = $generator->shrink($value); $array = $value->unbox(); - $this->assertEquals(2, count($array)); + $this->assertCount(2, $array); $this->assertEquals( ['former', 'latter'], array_keys($array) ); - $this->assertInternalType('integer', $array['former']); - $this->assertInternalType('integer', $array['latter']); + \Eris\PHPUnitDeprecationHelper::assertIsInt($array['former']); + \Eris\PHPUnitDeprecationHelper::assertIsInt($array['latter']); } } } diff --git a/test/Generator/BindGeneratorTest.php b/test/Generator/BindGeneratorTest.php index f269bdd2..6a9d27c2 100644 --- a/test/Generator/BindGeneratorTest.php +++ b/test/Generator/BindGeneratorTest.php @@ -1,10 +1,11 @@ size = 10; $this->rand = new RandomRange(new RandSource()); } - - public function testGeneratesAGeneratedValueObject() + + public function testGeneratesAGeneratedValueObject(): void { $generator = new BindGenerator( - // TODO: order of parameters should be consistent with map, or not? + // TODO: order of parameters should be consistent with map, or not? ConstantGenerator::box(4), function ($n) { - return new ChooseGenerator($n, $n+10); + return new ChooseGenerator($n, $n + 10); } ); - $this->assertInternalType( - 'integer', + PHPUnitDeprecationHelper::assertIsInt( $generator->__invoke($this->size, $this->rand)->unbox() ); } - public function testShrinksTheOuterGenerator() + public function testShrinksTheOuterGenerator(): void { $generator = new BindGenerator( new ChooseGenerator(0, 5), @@ -46,8 +46,7 @@ function ($n) { ); $value = $generator->__invoke($this->size, $this->rand); for ($i = 0; $i < 20; $i++) { - $this->assertInternalType( - 'integer', + PHPUnitDeprecationHelper::assertIsInt( $value->unbox() ); $value = $generator->shrink($value); @@ -55,7 +54,7 @@ function ($n) { $this->assertLessThanOrEqual(5, $value->unbox()); } - public function testAssociativeProperty() + public function testAssociativeProperty(): void { $firstGenerator = new BindGenerator( new BindGenerator( @@ -85,27 +84,25 @@ function ($m) { } } - public function testShrinkBindGeneratorWithCompositeValue() + public function testShrinkBindGeneratorWithCompositeValue(): void { - $bindGenerator = new BindGenerator( + $bindGenerator = new BindGenerator( new ChooseGenerator(0, 5), function ($n) { return new TupleGenerator([$n]); } ); - $generatedValue = $bindGenerator->__invoke($this->size, $this->rand); - $firstShrunkValue = $bindGenerator->shrink($generatedValue); + $generatedValue = $bindGenerator->__invoke($this->size, $this->rand); + $firstShrunkValue = $bindGenerator->shrink($generatedValue); $secondShrunkValue = $bindGenerator->shrink($firstShrunkValue); - $this->assertInstanceOf('\Eris\Generator\GeneratedValue', $secondShrunkValue); + $this->assertInstanceOf(GeneratedValue::class, $secondShrunkValue); } - private function assertIsAnArrayOfX0OrX1Elements(array $value) + private function assertIsAnArrayOfX0OrX1Elements(array $value): void { - $this->assertTrue( - in_array( - count($value) % 10, - [0, 1] - ), + $this->assertContains( + count($value) % 10, + [0, 1], "The array has " . count($value) . " elements" ); } diff --git a/test/Generator/BooleanGeneratorTest.php b/test/Generator/BooleanGeneratorTest.php index 59a1893d..3cc89c57 100644 --- a/test/Generator/BooleanGeneratorTest.php +++ b/test/Generator/BooleanGeneratorTest.php @@ -1,31 +1,32 @@ rand = new RandomRange(new RandSource()); } - public function testRandomlyPicksTrueOrFalse() + public function testRandomlyPicksTrueOrFalse(): void { $generator = new BooleanGenerator(); for ($i = 0; $i < 10; $i++) { $generatedValue = $generator($_size = 0, $this->rand); - $this->assertInternalType('bool', $generatedValue->unbox()); + PHPUnitDeprecationHelper::assertIsBool($generatedValue->unbox()); } } - public function testShrinksToFalse() + public function testShrinksToFalse(): void { $generator = new BooleanGenerator(); for ($i = 0; $i < 10; $i++) { diff --git a/test/Generator/CharacterGeneratorTest.php b/test/Generator/CharacterGeneratorTest.php index e6d0a958..d84cbea2 100644 --- a/test/Generator/CharacterGeneratorTest.php +++ b/test/Generator/CharacterGeneratorTest.php @@ -4,7 +4,7 @@ use Eris\Random\RandomRange; use Eris\Random\RandSource; -class CharacterGeneratorTest extends \PHPUnit_Framework_TestCase +class CharacterGeneratorTest extends \PHPUnit\Framework\TestCase { /** * @var int @@ -15,13 +15,13 @@ class CharacterGeneratorTest extends \PHPUnit_Framework_TestCase */ private $rand; - protected function setUp() + protected function setUp(): void { $this->size = 0; $this->rand = new RandomRange(new RandSource()); } - public function testBasicAsciiCharacterGenerators() + public function testBasicAsciiCharacterGenerators(): void { $generator = CharacterGenerator::ascii(); for ($i = 0; $i < 100; $i++) { @@ -33,7 +33,7 @@ public function testBasicAsciiCharacterGenerators() } } - public function testPrintableAsciiCharacterGenerators() + public function testPrintableAsciiCharacterGenerators(): void { $generator = CharacterGenerator::printableAscii(); for ($i = 0; $i < 100; $i++) { @@ -45,13 +45,13 @@ public function testPrintableAsciiCharacterGenerators() } } - public function testCharacterGeneratorsShrinkByConventionToTheLowestCodePoint() + public function testCharacterGeneratorsShrinkByConventionToTheLowestCodePoint(): void { $generator = CharacterGenerator::ascii(); $this->assertEquals('@', $generator->shrink(GeneratedValueSingle::fromJustValue('A', 'character'))->unbox()); } - public function testTheLowestCodePointCannotBeShrunk() + public function testTheLowestCodePointCannotBeShrunk(): void { $generator = new CharacterGenerator(65, 90); $lowest = GeneratedValueSingle::fromJustValue('A', 'character'); diff --git a/test/Generator/ChooseGeneratorTest.php b/test/Generator/ChooseGeneratorTest.php index 55d9fb3e..d9c110fd 100644 --- a/test/Generator/ChooseGeneratorTest.php +++ b/test/Generator/ChooseGeneratorTest.php @@ -4,7 +4,7 @@ use Eris\Random\RandomRange; use Eris\Random\RandSource; -class ChooseGeneratorTest extends \PHPUnit_Framework_TestCase +class ChooseGeneratorTest extends \PHPUnit\Framework\TestCase { /** * @var int @@ -15,24 +15,24 @@ class ChooseGeneratorTest extends \PHPUnit_Framework_TestCase */ private $rand; - protected function setUp() + protected function setUp(): void { $this->size = 0; // ignored by this kind of generator $this->rand = new RandomRange(new RandSource()); } - public function testPicksRandomlyAnIntegerAmongBoundaries() + public function testPicksRandomlyAnIntegerAmongBoundaries(): void { $generator = new ChooseGenerator(-10, 10); for ($i = 0; $i < 100; $i++) { $value = $generator($this->size, $this->rand)->unbox(); - $this->assertInternalType('integer', $value); + \Eris\PHPUnitDeprecationHelper::assertIsInt($value); $this->assertGreaterThanOrEqual(-10, $value); $this->assertLessThanOrEqual(10, $value); } } - public function testShrinksLinearlyTowardsTheSmallerAbsoluteValue() + public function testShrinksLinearlyTowardsTheSmallerAbsoluteValue(): void { /* Not a good shrinking policy, it should start to shrink from 0 and move * towards the smaller absolute value. @@ -55,7 +55,7 @@ public function testShrinksLinearlyTowardsTheSmallerAbsoluteValue() $this->assertSame($target, $value->unbox()); } - public function testUniformity() + public function testUniformity(): void { $generator = new ChooseGenerator(-10, 10000); $values = []; @@ -71,29 +71,27 @@ public function testUniformity() ); } - public function testShrinkingStopsToZero() + public function testShrinkingStopsToZero(): void { $generator = new ChooseGenerator($lowerLimit = 0, $upperLimit = 0); $lastValue = $generator($this->size, $this->rand); $this->assertSame(0, $generator->shrink($lastValue)->unbox()); } - /** - * @expectedException InvalidArgumentException - */ - public function testExceptionWhenDomainBoundariesAreNotIntegers() + public function testExceptionWhenDomainBoundariesAreNotIntegers(): void { + $this->expectException(\InvalidArgumentException::class); $generator = new ChooseGenerator("zero", "twenty"); } - public function testCanGenerateSingleInteger() + public function testCanGenerateSingleInteger(): void { $generator = new ChooseGenerator(42, 42); $this->assertSame(42, $generator($this->size, $this->rand)->unbox()); $this->assertSame(42, $generator->shrink($generator($this->size, $this->rand))->unbox()); } - public function testTheOrderOfBoundariesDoesNotMatter() + public function testTheOrderOfBoundariesDoesNotMatter(): void { $this->assertEquals( new ChooseGenerator(100, -100), diff --git a/test/Generator/ConstantGeneratorTest.php b/test/Generator/ConstantGeneratorTest.php index 40f1376a..dd9b4548 100644 --- a/test/Generator/ConstantGeneratorTest.php +++ b/test/Generator/ConstantGeneratorTest.php @@ -4,7 +4,7 @@ use Eris\Random\RandomRange; use Eris\Random\RandSource; -class ConstantGeneratorTest extends \PHPUnit_Framework_TestCase +class ConstantGeneratorTest extends \PHPUnit\Framework\TestCase { /** * @var int @@ -15,13 +15,13 @@ class ConstantGeneratorTest extends \PHPUnit_Framework_TestCase */ private $rand; - protected function setUp() + protected function setUp(): void { $this->size = 0; $this->rand = new RandomRange(new RandSource()); } - public function testPicksAlwaysTheValue() + public function testPicksAlwaysTheValue(): void { $generator = new ConstantGenerator(true); for ($i = 0; $i < 50; $i++) { @@ -29,7 +29,7 @@ public function testPicksAlwaysTheValue() } } - public function testShrinkAlwaysToTheValue() + public function testShrinkAlwaysToTheValue(): void { $generator = new ConstantGenerator(true); $element = $generator($this->size, $this->rand); diff --git a/test/Generator/DateGeneratorTest.php b/test/Generator/DateGeneratorTest.php index 4620439a..123e3a73 100644 --- a/test/Generator/DateGeneratorTest.php +++ b/test/Generator/DateGeneratorTest.php @@ -1,11 +1,11 @@ size = 10; $this->rand = new RandomRange(new RandSource()); diff --git a/test/Generator/ElementsGeneratorTest.php b/test/Generator/ElementsGeneratorTest.php index 3289ed20..60b9f0e5 100644 --- a/test/Generator/ElementsGeneratorTest.php +++ b/test/Generator/ElementsGeneratorTest.php @@ -4,7 +4,7 @@ use Eris\Random\RandomRange; use Eris\Random\RandSource; -class ElementsGeneratorTest extends \PHPUnit_Framework_TestCase +class ElementsGeneratorTest extends \PHPUnit\Framework\TestCase { /** * @var int @@ -15,7 +15,7 @@ class ElementsGeneratorTest extends \PHPUnit_Framework_TestCase */ private $rand; - protected function setUp() + protected function setUp(): void { $this->size = 10; $this->rand = new RandomRange(new RandSource()); diff --git a/test/Generator/FloatGeneratorTest.php b/test/Generator/FloatGeneratorTest.php index deedf0dc..d7d75efc 100644 --- a/test/Generator/FloatGeneratorTest.php +++ b/test/Generator/FloatGeneratorTest.php @@ -1,10 +1,11 @@ size = 300; $this->rand = new RandomRange(new RandSource()); } - public function testPicksUniformelyPositiveAndNegativeFloatNumbers() + public function testPicksUniformelyPositiveAndNegativeFloatNumbers(): void { $generator = new FloatGenerator(); $sum = 0; $trials = 500; for ($i = 0; $i < $trials; $i++) { $value = $generator($this->size, $this->rand); - $this->assertInternalType('float', $value->unbox()); + PHPUnitDeprecationHelper::assertIsFloat($value->unbox()); $sum += $value->unbox(); } $mean = $sum / $trials; @@ -36,14 +37,14 @@ public function testPicksUniformelyPositiveAndNegativeFloatNumbers() $this->assertLessThan(10, abs($mean)); } - public function testShrinksLinearly() + public function testShrinksLinearly(): void { $generator = new FloatGenerator(); $this->assertSame(3.5, $generator->shrink(GeneratedValueSingle::fromJustValue(4.5))->unbox()); $this->assertSame(-2.5, $generator->shrink(GeneratedValueSingle::fromJustValue(-3.5))->unbox()); } - public function testWhenBothSignsArePossibleCannotShrinkBelowZero() + public function testWhenBothSignsArePossibleCannotShrinkBelowZero(): void { $generator = new FloatGenerator(); $this->assertSame(0.0, $generator->shrink(GeneratedValueSingle::fromJustValue(0.0))->unbox()); diff --git a/test/Generator/FrequencyGeneratorTest.php b/test/Generator/FrequencyGeneratorTest.php index 62b360e0..980a0101 100644 --- a/test/Generator/FrequencyGeneratorTest.php +++ b/test/Generator/FrequencyGeneratorTest.php @@ -4,7 +4,7 @@ use Eris\Random\RandomRange; use Eris\Random\RandSource; -class FrequencyGeneratorTest extends \PHPUnit_Framework_TestCase +class FrequencyGeneratorTest extends \PHPUnit\Framework\TestCase { /** * @var int @@ -15,13 +15,13 @@ class FrequencyGeneratorTest extends \PHPUnit_Framework_TestCase */ private $rand; - protected function setUp() + protected function setUp(): void { $this->size = 10; $this->rand = new RandomRange(new RandSource()); } - public function testEqualProbability() + public function testEqualProbability(): void { $generator = new FrequencyGenerator([ [1, 42], @@ -36,7 +36,7 @@ public function testEqualProbability() ); } - public function testMoreFrequentGeneratorIsChosenMoreOften() + public function testMoreFrequentGeneratorIsChosenMoreOften(): void { $generator = new FrequencyGenerator([ [10, 42], @@ -50,7 +50,7 @@ public function testMoreFrequentGeneratorIsChosenMoreOften() ); } - public function testZeroFrequencyMeansItWillNotBeChosen() + public function testZeroFrequencyMeansItWillNotBeChosen(): void { $generator = new FrequencyGenerator([ [0, 42], @@ -62,26 +62,22 @@ public function testZeroFrequencyMeansItWillNotBeChosen() $this->assertEquals(1000, $countOf[21]); } - /** - * @expectedException InvalidArgumentException - */ - public function testConstructWithNoArguments() + public function testConstructWithNoArguments(): void { + $this->expectException(\InvalidArgumentException::class); new FrequencyGenerator([]); } - /** - * @expectedException InvalidArgumentException - */ - public function testFrequenciesMustBeNaturals() + public function testFrequenciesMustBeNaturals(): void { + $this->expectException(\InvalidArgumentException::class); new FrequencyGenerator([ [10, 42], [false, 21], ]); } - public function testShrinking() + public function testShrinking(): void { $generator = new FrequencyGenerator([ [10, 42], @@ -101,7 +97,7 @@ public function testShrinking() } } - public function testShrinkIntersectingDomainsOnlyShrinkInTheDomainThatOriginallyProducedTheValue() + public function testShrinkIntersectingDomainsOnlyShrinkInTheDomainThatOriginallyProducedTheValue(): void { $generator = new FrequencyGenerator([ [5, new ChooseGenerator(1, 100)], @@ -119,7 +115,7 @@ public function testShrinkIntersectingDomainsOnlyShrinkInTheDomainThatOriginally $this->assertEquals([1 => true, 10 => true], $shrinkedTable); } - private function distribute($generator) + private function distribute($generator): array { $countOf = []; for ($i = 0; $i < 1000; $i++) { diff --git a/test/Generator/GeneratedValueOptionsTest.php b/test/Generator/GeneratedValueOptionsTest.php index b32f5c2b..90c6f1a4 100644 --- a/test/Generator/GeneratedValueOptionsTest.php +++ b/test/Generator/GeneratedValueOptionsTest.php @@ -2,7 +2,7 @@ namespace Eris\Generator; // TODO: complete *unit* test coverage -class GeneratedValueOptionsTest extends \PHPUnit_Framework_TestCase +class GeneratedValueOptionsTest extends \PHPUnit\Framework\TestCase { public function testMapsOverAllTheOptions() { @@ -66,7 +66,7 @@ public function testCartesianProductWithOtherValues() }); $this->assertEquals(6, count($product)); foreach ($product as $value) { - $this->assertRegexp('/^[ab][123]$/', $value->unbox()); + \Eris\PHPUnitDeprecationHelper::assertMatchesRegularExpression('/^[ab][123]$/', $value->unbox()); } } } diff --git a/test/Generator/GeneratedValueTest.php b/test/Generator/GeneratedValueTest.php index 7640e64c..05fafdfe 100644 --- a/test/Generator/GeneratedValueTest.php +++ b/test/Generator/GeneratedValueTest.php @@ -1,9 +1,9 @@ assertInternalType('string', $generatedValue->__toString()); - $this->assertRegExp('/value.*422/', $generatedValue->__toString()); - $this->assertRegExp('/211/', $generatedValue->__toString()); - $this->assertRegExp('/generator.*map/', $generatedValue->__toString()); + \Eris\PHPUnitDeprecationHelper::assertIsString($generatedValue->__toString()); + \Eris\PHPUnitDeprecationHelper::assertMatchesRegularExpression('/value.*422/', $generatedValue->__toString()); + \Eris\PHPUnitDeprecationHelper::assertMatchesRegularExpression('/211/', $generatedValue->__toString()); + \Eris\PHPUnitDeprecationHelper::assertMatchesRegularExpression('/generator.*map/', $generatedValue->__toString()); } - public function testCanBeIteratedUponAsASingleOption() + public function testCanBeIteratedUponAsASingleOption(): void { $generatedValue = GeneratedValueSingle::fromValueAndInput( 422, diff --git a/test/Generator/IntegerGeneratorTest.php b/test/Generator/IntegerGeneratorTest.php index b6f03d5b..78e86601 100644 --- a/test/Generator/IntegerGeneratorTest.php +++ b/test/Generator/IntegerGeneratorTest.php @@ -4,7 +4,7 @@ use Eris\Random\RandomRange; use Eris\Random\RandSource; -class IntegerGeneratorTest extends \PHPUnit_Framework_TestCase +class IntegerGeneratorTest extends \PHPUnit\Framework\TestCase { /** * @var int @@ -15,7 +15,7 @@ class IntegerGeneratorTest extends \PHPUnit_Framework_TestCase */ private $rand; - protected function setUp() + protected function setUp(): void { $this->size = 10; $this->rand = new RandomRange(new RandSource()); @@ -25,7 +25,7 @@ public function testPicksRandomlyAnInteger() { $generator = new IntegerGenerator(); for ($i = 0; $i < 100; $i++) { - $this->assertInternalType('integer', $generator($this->size, $this->rand)->unbox()); + \Eris\PHPUnitDeprecationHelper::assertIsInt($generator($this->size, $this->rand)->unbox()); } } diff --git a/test/Generator/MapGeneratorTest.php b/test/Generator/MapGeneratorTest.php index 5fbf851d..14134acd 100644 --- a/test/Generator/MapGeneratorTest.php +++ b/test/Generator/MapGeneratorTest.php @@ -4,7 +4,7 @@ use Eris\Random\RandomRange; use Eris\Random\RandSource; -class MapGeneratorTest extends \PHPUnit_Framework_TestCase +class MapGeneratorTest extends \PHPUnit\Framework\TestCase { /** * @var int @@ -15,7 +15,7 @@ class MapGeneratorTest extends \PHPUnit_Framework_TestCase */ private $rand; - protected function setUp() + protected function setUp(): void { $this->size = 10; $this->rand = new RandomRange(new RandSource()); diff --git a/test/Generator/NamesGeneratorTest.php b/test/Generator/NamesGeneratorTest.php index 7655fd9d..121eab46 100644 --- a/test/Generator/NamesGeneratorTest.php +++ b/test/Generator/NamesGeneratorTest.php @@ -4,19 +4,19 @@ use Eris\Random\RandomRange; use Eris\Random\RandSource; -class NamesGeneratorTest extends \PHPUnit_Framework_TestCase +class NamesGeneratorTest extends \PHPUnit\Framework\TestCase { /** * @var RandomRange */ private $rand; - public function setUp() + public function setUp(): void { $this->rand = new RandomRange(new RandSource()); } - public function testItRespectsTheGenerationSize() + public function testItRespectsTheGenerationSize(): void { $generator = NamesGenerator::defaultDataSet(); for ($i = 5; $i < 50; $i++) { @@ -28,16 +28,16 @@ public function testItRespectsTheGenerationSize() } } - public function testGeneratesANameFromAFixedDataset() + public function testGeneratesANameFromAFixedDataset(): void { $generator = NamesGenerator::defaultDataSet(); for ($i = 0; $i < 50; $i++) { $value = $generator($_size = 10, $this->rand); - $this->assertInternalType('string', $value->unbox()); + \Eris\PHPUnitDeprecationHelper::assertIsString($value->unbox()); } } - public static function namesToShrink() + public static function namesToShrink(): array { return [ ["Malene", "Maxence"], @@ -57,7 +57,7 @@ public static function namesToShrink() /** * @dataProvider namesToShrink */ - public function testShrinksToTheNameWithTheImmediatelyLowerLengthWhichHasTheMinimumDistance($shrunk, $original) + public function testShrinksToTheNameWithTheImmediatelyLowerLengthWhichHasTheMinimumDistance($shrunk, $original): void { $generator = NamesGenerator::defaultDataSet(); $this->assertEquals( diff --git a/test/Generator/OneOfGeneratorTest.php b/test/Generator/OneOfGeneratorTest.php index 041f6bdd..dfcbfd0a 100644 --- a/test/Generator/OneOfGeneratorTest.php +++ b/test/Generator/OneOfGeneratorTest.php @@ -4,7 +4,7 @@ use Eris\Random\RandomRange; use Eris\Random\RandSource; -class OneOfGeneratorTest extends \PHPUnit_Framework_TestCase +class OneOfGeneratorTest extends \PHPUnit\Framework\TestCase { /** * @var ChooseGenerator @@ -19,14 +19,14 @@ class OneOfGeneratorTest extends \PHPUnit_Framework_TestCase */ private $rand; - protected function setUp() + protected function setUp(): void { $this->singleElementGenerator = new ChooseGenerator(0, 100); $this->size = 10; $this->rand = new RandomRange(new RandSource()); } - public function testConstructWithAnArrayOfGenerators() + public function testConstructWithAnArrayOfGenerators(): void { $generator = new OneOfGenerator([ $this->singleElementGenerator, @@ -34,21 +34,19 @@ public function testConstructWithAnArrayOfGenerators() ]); $element = $generator($this->size, $this->rand); - $this->assertInternalType('integer', $element->unbox()); + \Eris\PHPUnitDeprecationHelper::assertIsInt($element->unbox()); } - public function testConstructWithNonGenerators() + public function testConstructWithNonGenerators(): void { $generator = new OneOfGenerator([42, 42]); $element = $generator($this->size, $this->rand)->unbox(); $this->assertEquals(42, $element); } - /** - * @expectedException InvalidArgumentException - */ public function testConstructWithNoArguments() { + $this->expectException(\InvalidArgumentException::class); $generator = new OneOfGenerator([]); $element = $generator($this->size, $this->rand); } diff --git a/test/Generator/RegexGeneratorTest.php b/test/Generator/RegexGeneratorTest.php index 89ee51e7..29957f97 100644 --- a/test/Generator/RegexGeneratorTest.php +++ b/test/Generator/RegexGeneratorTest.php @@ -4,7 +4,7 @@ use Eris\Random\RandomRange; use Eris\Random\RandSource; -class RegexGeneratorTest extends \PHPUnit_Framework_TestCase +class RegexGeneratorTest extends \PHPUnit\Framework\TestCase { /** * @var int @@ -27,7 +27,7 @@ public static function supportedRegexes() ]; } - protected function setUp() + protected function setUp(): void { $this->size = 10; $this->rand = new RandomRange(new RandSource()); @@ -41,7 +41,7 @@ public function testGeneratesOnlyValuesThatMatchTheRegex($expression) $generator = new RegexGenerator($expression); for ($i = 0; $i < 100; $i++) { $value = $generator($this->size, $this->rand)->unbox(); - $this->assertRegexp("/{$expression}/", $value); + \Eris\PHPUnitDeprecationHelper::assertMatchesRegularExpression("/{$expression}/", $value); } } diff --git a/test/Generator/SequenceGeneratorTest.php b/test/Generator/SequenceGeneratorTest.php index 83dc888c..5bf7870c 100644 --- a/test/Generator/SequenceGeneratorTest.php +++ b/test/Generator/SequenceGeneratorTest.php @@ -4,7 +4,7 @@ use Eris\Random\RandomRange; use Eris\Random\RandSource; -class SequenceGeneratorTest extends \PHPUnit_Framework_TestCase +class SequenceGeneratorTest extends \PHPUnit\Framework\TestCase { /** * @var int @@ -19,7 +19,7 @@ class SequenceGeneratorTest extends \PHPUnit_Framework_TestCase */ private $rand; - protected function setUp() + protected function setUp(): void { $this->size = 100; $this->singleElementGenerator = new ChooseGenerator(10, 100); diff --git a/test/Generator/SetGeneratorTest.php b/test/Generator/SetGeneratorTest.php index 8dfff830..6239f36c 100644 --- a/test/Generator/SetGeneratorTest.php +++ b/test/Generator/SetGeneratorTest.php @@ -4,7 +4,7 @@ use Eris\Random\RandomRange; use Eris\Random\RandSource; -class SetGeneratorTest extends \PHPUnit_Framework_TestCase +class SetGeneratorTest extends \PHPUnit\Framework\TestCase { /** * @var int @@ -19,7 +19,7 @@ class SetGeneratorTest extends \PHPUnit_Framework_TestCase */ private $rand; - protected function setUp() + protected function setUp(): void { $this->size = 100; $this->singleElementGenerator = new ChooseGenerator(10, 100); diff --git a/test/Generator/StringGeneratorTest.php b/test/Generator/StringGeneratorTest.php index ef6f1405..c8fc6529 100644 --- a/test/Generator/StringGeneratorTest.php +++ b/test/Generator/StringGeneratorTest.php @@ -4,14 +4,14 @@ use Eris\Random\RandomRange; use Eris\Random\RandSource; -class StringGeneratorTest extends \PHPUnit_Framework_TestCase +class StringGeneratorTest extends \PHPUnit\Framework\TestCase { /** * @var RandomRange */ private $rand; - public function setUp() + public function setUp(): void { $this->rand = new RandomRange(new RandSource()); } diff --git a/test/Generator/SubsetGeneratorTest.php b/test/Generator/SubsetGeneratorTest.php index 9b4da026..e8f3911c 100644 --- a/test/Generator/SubsetGeneratorTest.php +++ b/test/Generator/SubsetGeneratorTest.php @@ -1,11 +1,11 @@ universe = ['a', 'b', 'c', 'd', 'e']; $this->generator = new SubsetGenerator($this->universe); diff --git a/test/Generator/SuchThatGeneratorTest.php b/test/Generator/SuchThatGeneratorTest.php index 688eee01..ef21cdf1 100644 --- a/test/Generator/SuchThatGeneratorTest.php +++ b/test/Generator/SuchThatGeneratorTest.php @@ -4,7 +4,7 @@ use Eris\Random\RandomRange; use Eris\Random\RandSource; -class SuchThatGeneratorTest extends \PHPUnit_Framework_TestCase +class SuchThatGeneratorTest extends \PHPUnit\Framework\TestCase { /** * @var int @@ -15,13 +15,13 @@ class SuchThatGeneratorTest extends \PHPUnit_Framework_TestCase */ private $rand; - protected function setUp() + protected function setUp(): void { $this->size = 10; $this->rand = new RandomRange(new RandSource()); } - public function testGeneratesAGeneratedValueObject() + public function testGeneratesAGeneratedValueObject(): void { $generator = new SuchThatGenerator( function ($n) { @@ -35,7 +35,7 @@ function ($n) { ); } - public function testAcceptsPHPUnitConstraints() + public function testAcceptsPHPUnitConstraints(): void { $generator = new SuchThatGenerator( $this->callback(function ($n) { @@ -49,7 +49,7 @@ public function testAcceptsPHPUnitConstraints() ); } - public function testShrinksTheOriginalInput() + public function testShrinksTheOriginalInput(): void { $generator = new SuchThatGenerator( function ($n) { @@ -60,18 +60,17 @@ function ($n) { $element = $generator->__invoke($this->size, $this->rand); for ($i = 0; $i < 100; $i++) { $element = $generator->shrink($element)->last(); - $this->assertTrue( - $element->unbox() % 2 === 0, + $this->assertSame( + $element->unbox() % 2, + 0, "Element should still be filtered while shrinking: " . var_export($element, true) ); } } - /** - * @expectedException Eris\Generator\SkipValueException - */ - public function testGivesUpGenerationIfTheFilterIsNotSatisfiedTooManyTimes() + public function testGivesUpGenerationIfTheFilterIsNotSatisfiedTooManyTimes(): void { + $this->expectException(\Eris\Generator\SkipValueException::class); $generator = new SuchThatGenerator( function ($n) { return $n % 2 == 0; @@ -81,7 +80,7 @@ function ($n) { $generator->__invoke($this->size, $this->rand); } - public function testGivesUpShrinkingIfTheFilterIsNotSatisfiedTooManyTimes() + public function testGivesUpShrinkingIfTheFilterIsNotSatisfiedTooManyTimes(): void { $generator = new SuchThatGenerator( function ($n) { @@ -96,7 +95,7 @@ function ($n) { ); } - public function testShrinksMultipleOptionsButFiltersTheOnesThatSatisfyTheCondition() + public function testShrinksMultipleOptionsButFiltersTheOnesThatSatisfyTheCondition(): void { $generator = new SuchThatGenerator( function ($n) { @@ -107,14 +106,15 @@ function ($n) { $element = GeneratedValueSingle::fromJustValue(100); $options = $generator->shrink($element); foreach ($options as $option) { - $this->assertTrue( - $option->unbox() % 2 === 0, + $this->assertSame( + $option->unbox() % 2, + 0, "Option should still be filtered while shrinking: " . var_export($option, true) ); } } - public function testThanksToMultipleShrinkingItCanBeLikelyToFindShrunkValuesWithRespectToOnlyFollowingThePessimistRoute() + public function testThanksToMultipleShrinkingItCanBeLikelyToFindShrunkValuesWithRespectToOnlyFollowingThePessimistRoute(): void { $generator = new SuchThatGenerator( function ($n) { diff --git a/test/Generator/TupleGeneratorTest.php b/test/Generator/TupleGeneratorTest.php index 746c4853..5b2b6beb 100644 --- a/test/Generator/TupleGeneratorTest.php +++ b/test/Generator/TupleGeneratorTest.php @@ -4,7 +4,7 @@ use Eris\Random\RandomRange; use Eris\Random\RandSource; -class TupleGeneratorTest extends \PHPUnit_Framework_TestCase +class TupleGeneratorTest extends \PHPUnit\Framework\TestCase { /** * @var ChooseGenerator @@ -19,21 +19,21 @@ class TupleGeneratorTest extends \PHPUnit_Framework_TestCase */ private $rand; - protected function setUp() + protected function setUp(): void { $this->generatorForSingleElement = new ChooseGenerator(0, 100); $this->size = 10; $this->rand = new RandomRange(new RandSource()); } - private function assertInSingleElementGenerator($value) + private function assertInSingleElementGenerator($value): void { - $this->assertInternalType('integer', $value); + \Eris\PHPUnitDeprecationHelper::assertIsInt($value); $this->assertGreaterThanOrEqual(0, $value); $this->assertLessThanOrEqual(100, $value); } - public function testConstructWithAnArrayOfGenerators() + public function testConstructWithAnArrayOfGenerators(): void { $generator = new TupleGenerator([ $this->generatorForSingleElement, @@ -42,13 +42,13 @@ public function testConstructWithAnArrayOfGenerators() $generated = $generator($this->size, $this->rand); - $this->assertSame(2, count($generated->unbox())); + $this->assertCount(2, $generated->unbox()); foreach ($generated->unbox() as $element) { $this->assertInSingleElementGenerator($element); } } - public function testConstructWithNonGenerators() + public function testConstructWithNonGenerators(): void { $aNonGenerator = 42; $generator = new TupleGenerator([$aNonGenerator]); @@ -60,14 +60,14 @@ public function testConstructWithNonGenerators() } } - public function testConstructWithNoArguments() + public function testConstructWithNoArguments(): void { $generator = new TupleGenerator([]); $this->assertSame([], $generator($this->size, $this->rand)->unbox()); } - public function testShrink() + public function testShrink(): void { $generator = new TupleGenerator([ $this->generatorForSingleElement, @@ -93,7 +93,7 @@ public function testShrink() ); } - public function testDoesNotShrinkSomethingAlreadyShrunkToTheMax() + public function testDoesNotShrinkSomethingAlreadyShrunkToTheMax(): void { $constants = [42, 42]; $generator = new TupleGenerator($constants); @@ -103,7 +103,7 @@ public function testDoesNotShrinkSomethingAlreadyShrunkToTheMax() $this->assertSame($constants, $elementsAfterShrink->unbox()); } - public function testShrinkingMultipleOptionsOfOneGenerator() + public function testShrinkingMultipleOptionsOfOneGenerator(): void { $generator = new TupleGenerator([ new IntegerGenerator() @@ -118,15 +118,15 @@ public function testShrinkingMultipleOptionsOfOneGenerator() foreach ($shrunk as $option) { $this->assertEquals('tuple', $option->generatorName()); $optionValue = $option->unbox(); - $this->assertInternalType('array', $optionValue); - $this->assertEquals(1, count($optionValue)); + \Eris\PHPUnitDeprecationHelper::assertIsArray($optionValue); + $this->assertCount(1, $optionValue); } } /** * @depends testShrinkingMultipleOptionsOfOneGenerator */ - public function testShrinkingMultipleOptionsOfMoreThanOneSingleShrinkingGenerator() + public function testShrinkingMultipleOptionsOfMoreThanOneSingleShrinkingGenerator(): void { $generator = new TupleGenerator([ new StringGenerator(), @@ -146,7 +146,7 @@ public function testShrinkingMultipleOptionsOfMoreThanOneSingleShrinkingGenerato foreach ($shrunk as $option) { $this->assertEquals('tuple', $option->generatorName()); $optionValue = $option->unbox(); - $this->assertInternalType('array', $optionValue); + \Eris\PHPUnitDeprecationHelper::assertIsArray($optionValue); $this->assertEquals(2, count($optionValue)); $elementsBeingShrunk = (strlen($optionValue[0]) < 5 ? 1 : 0) @@ -158,7 +158,7 @@ public function testShrinkingMultipleOptionsOfMoreThanOneSingleShrinkingGenerato /** * @depends testShrinkingMultipleOptionsOfOneGenerator */ - public function testShrinkingMultipleOptionsOfMoreThanOneMultipleShrinkingGenerator() + public function testShrinkingMultipleOptionsOfMoreThanOneMultipleShrinkingGenerator(): void { $generator = new TupleGenerator([ new IntegerGenerator(), @@ -177,8 +177,8 @@ public function testShrinkingMultipleOptionsOfMoreThanOneMultipleShrinkingGenera foreach ($shrunk as $option) { $this->assertEquals('tuple', $option->generatorName()); $optionValue = $option->unbox(); - $this->assertInternalType('array', $optionValue); - $this->assertEquals(2, count($optionValue)); + \Eris\PHPUnitDeprecationHelper::assertIsArray($optionValue); + $this->assertCount(2, $optionValue); $this->assertNotEquals([100, 200], $optionValue); $elementsBeingShrunk = ($optionValue[0] < 100 ? 1 : 0) diff --git a/test/Generator/VectorGeneratorTest.php b/test/Generator/VectorGeneratorTest.php index d7e1a50e..b7c7738b 100644 --- a/test/Generator/VectorGeneratorTest.php +++ b/test/Generator/VectorGeneratorTest.php @@ -4,7 +4,7 @@ use Eris\Random\RandomRange; use Eris\Random\RandSource; -class VectorGeneratorTest extends \PHPUnit_Framework_TestCase +class VectorGeneratorTest extends \PHPUnit\Framework\TestCase { /** * @var int @@ -31,7 +31,7 @@ class VectorGeneratorTest extends \PHPUnit_Framework_TestCase */ private $rand; - protected function setUp() + protected function setUp(): void { $this->vectorSize = rand(5, 10); $this->size = 10; diff --git a/test/Listener/LogTest.php b/test/Listener/LogTest.php index ade4000e..4218093e 100644 --- a/test/Listener/LogTest.php +++ b/test/Listener/LogTest.php @@ -1,7 +1,9 @@ originalTimezone = date_default_timezone_get(); $this->file = sys_get_temp_dir().'/eris-log-unit-test.log'; @@ -28,7 +30,7 @@ protected function setUp() date_default_timezone_set('UTC'); } - public function tearDown() + public function tearDown(): void { $this->log->endPropertyVerification(null, null); date_default_timezone_set($this->originalTimezone); @@ -45,7 +47,7 @@ public function testWritesALineForEachIterationShowingItsIndex() public function testWritesALineForTheFirstFailureOfATest() { - $this->log->failure([23], new \PHPUnit_Framework_AssertionFailedError("Failed asserting that...")); + $this->log->failure([23], new AssertionFailedError("Failed asserting that...")); $this->assertEquals( "[2011-03-13T07:06:40+00:00][1234] failure: [23]. Failed asserting that..." . PHP_EOL, file_get_contents($this->file) @@ -54,7 +56,7 @@ public function testWritesALineForTheFirstFailureOfATest() public function testWritesALineForEachShrinkingAttempt() { - $this->log->shrinking([22], new \PHPUnit_Framework_AssertionFailedError("Failed asserting that...")); + $this->log->shrinking([22], new AssertionFailedError("Failed asserting that...")); $this->assertEquals( "[2011-03-13T07:06:40+00:00][1234] shrinking: [22]" . PHP_EOL, file_get_contents($this->file) diff --git a/test/Listener/MinimumEvaluationsTest.php b/test/Listener/MinimumEvaluationsTest.php index 1c099207..d1192518 100644 --- a/test/Listener/MinimumEvaluationsTest.php +++ b/test/Listener/MinimumEvaluationsTest.php @@ -1,36 +1,33 @@ listener = MinimumEvaluations::ratio(0.5); } - public function testAllowsExecutionsWithHigherThanMinimumRatioToBeGreen() + public function testAllowsExecutionsWithHigherThanMinimumRatioToBeGreen(): void { $this->assertNull($this->listener->endPropertyVerification(99, 100)); } - /** - * @expectedException OutOfBoundsException - * @expectedExceptionMessage Evaluation ratio 0.2 is under the threshold 0.5 - */ - public function testWarnsOfDangerouslyLowEvaluationRatiosAsVeryFewTestsAreBeingPerformed() + public function testWarnsOfDangerouslyLowEvaluationRatiosAsVeryFewTestsAreBeingPerformed(): void { + $this->expectExceptionMessage("Evaluation ratio 0.2 is under the threshold 0.5"); + $this->expectException(\OutOfBoundsException::class); $this->listener->endPropertyVerification(20, 100); } - public function testIfTheTestIsAlreadyFailingDoesNotCreateNoiseWithItsOwnCheck() + public function testIfTheTestIsAlreadyFailingDoesNotCreateNoiseWithItsOwnCheck(): void { $this->assertNull( $this->listener->endPropertyVerification(10, 100, new LogicException("One of the cross beams has gone out askew on the treadle")) diff --git a/test/PHPUnitCommandTest.php b/test/PHPUnitCommandTest.php index 289d98bf..9400db99 100644 --- a/test/PHPUnitCommandTest.php +++ b/test/PHPUnitCommandTest.php @@ -1,7 +1,7 @@ assertInternalType('integer', $size->at(42000)); + \Eris\PHPUnitDeprecationHelper::assertIsInt($size->at(42000)); } public function testAllowsLinearGrowth() diff --git a/test/Quantifier/TimeBasedTerminationConditionTest.php b/test/Quantifier/TimeBasedTerminationConditionTest.php index 02eaba5c..9fbf80dd 100644 --- a/test/Quantifier/TimeBasedTerminationConditionTest.php +++ b/test/Quantifier/TimeBasedTerminationConditionTest.php @@ -3,7 +3,7 @@ use DateInterval; -class TimeBasedTerminationConditionTest extends \PHPUnit_Framework_TestCase +class TimeBasedTerminationConditionTest extends \PHPUnit\Framework\TestCase { /** * @var \Closure @@ -18,7 +18,7 @@ class TimeBasedTerminationConditionTest extends \PHPUnit_Framework_TestCase */ private $condition; - protected function setUp() + protected function setUp(): void { $this->time = function () { return $this->currentTime; diff --git a/test/Random/MersenneTwisterTest.php b/test/Random/MersenneTwisterTest.php index 0d1780eb..58740edd 100644 --- a/test/Random/MersenneTwisterTest.php +++ b/test/Random/MersenneTwisterTest.php @@ -1,9 +1,9 @@ markTestSkipped('MersenneTwister class does not support HHVM'); @@ -11,7 +11,7 @@ public function setUp() $this->enableAssertions(); } - public function tearDown() + public function tearDown(): void { $this->disableAssertions(); } diff --git a/test/Random/RandomRangeTest.php b/test/Random/RandomRangeTest.php index 8e113b49..321ad45e 100644 --- a/test/Random/RandomRangeTest.php +++ b/test/Random/RandomRangeTest.php @@ -1,7 +1,7 @@ shrinker = new Multiple( [ @@ -65,8 +63,6 @@ public function testMultipleBranchesConvergeFasterThanLinearShrinking($startingP ); } catch (AssertionFailedError $e) { $this->verifyAssertionFailure($e, $startingPoint); - } catch (PHPUnit_Framework_AssertionFailedError $e) { - $this->verifyAssertionFailure($e, $startingPoint); } } diff --git a/test/bootstrap.php b/test/bootstrap.php deleted file mode 100644 index 3bd9763d..00000000 --- a/test/bootstrap.php +++ /dev/null @@ -1,10 +0,0 @@ -