Skip to content

Commit

Permalink
Add Psalm (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilario-pierbattista authored Dec 5, 2021
1 parent 7feac74 commit 59efb45
Show file tree
Hide file tree
Showing 55 changed files with 373 additions and 216 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
- name: Remove phpstan from dev dependecies for older php versions
- name: Remove dev dependecies for older php versions
if: ${{ matrix.php < 7.1 }}
run: composer remove --dev phpstan/phpstan --ignore-platform-reqs --no-update
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:
Expand All @@ -48,9 +50,11 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
- name: Remove phpstan from dev dependecies for older php versions
- name: Remove dev dependecies for older php versions
if: ${{ matrix.php < 7.1 }}
run: composer remove --dev phpstan/phpstan --ignore-platform-reqs --no-update
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
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ jobs:
- description: Code style
script: vendor/bin/php-cs-fixer fix --verbose --diff --dry-run
- description: PHPStan
script: vendor/bin/phpstan analyse -c phpstan.neon
script: vendor/bin/phpstan
- description: Psalm
script: vendor/bin/psalm.phar
name: ${{ matrix.description }}
runs-on: ubuntu-latest
steps:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ composer.lock
docs/_build
.phpunit.result.cache
docker-compose.override.yml
.psalm-cache/
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"sebastian/comparator": ">=1.2.4",
"friendsofphp/php-cs-fixer": "^2.0",
"icomefromthenet/reverse-regex": "v0.0.6.3",
"phpstan/phpstan": "^1.2"
"phpstan/phpstan": "^1.2",
"psalm/phar": "^4.13"
},
"suggest":
{
Expand Down Expand Up @@ -55,8 +56,9 @@
"composer update",
"vendor/bin/phpunit test"
],
"phpstan": [
"vendor/bin/phpstan analyse -c phpstan.neon"
"static": [
"vendor/bin/phpstan",
"vendor/bin/psalm.phar"
],
"phpstan-baseline": [
"vendor/bin/phpstan analyse -c phpstan.neon --generate-baseline"
Expand Down
5 changes: 3 additions & 2 deletions examples/AlwaysFailsTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
use Eris\Generator;

use Eris\Generators;
use Eris\TestTrait;

class AlwaysFailsTest extends \PHPUnit_Framework_TestCase
Expand All @@ -9,7 +10,7 @@ class AlwaysFailsTest extends \PHPUnit_Framework_TestCase
public function testFailsNoMatterWhatIsTheInput()
{
$this->forAll(
Generator\elements(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'])
Generators::elements(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'])
)
->then(function ($someChar) {
$this->fail("This test fails by design. '$someChar' was passed in");
Expand Down
9 changes: 5 additions & 4 deletions examples/AssociativeArrayTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
use Eris\Generator;

use Eris\Generators;

class AssociativeArrayTest extends PHPUnit_Framework_TestCase
{
Expand All @@ -8,9 +9,9 @@ class AssociativeArrayTest extends PHPUnit_Framework_TestCase
public function testAssociativeArraysGeneratedOnStandardKeys()
{
$this->forAll(
Generator\associative([
'letter' => Generator\elements("A", "B", "C"),
'cipher' => Generator\choose(0, 9),
Generators::associative([
'letter' => Generators::elements("A", "B", "C"),
'cipher' => Generators::choose(0, 9),
])
)
->then(function ($array) {
Expand Down
13 changes: 7 additions & 6 deletions examples/BindTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
use Eris\Generator;

use Eris\Generators;

class BindTest extends PHPUnit_Framework_TestCase
{
Expand All @@ -8,12 +9,12 @@ class BindTest extends PHPUnit_Framework_TestCase
public function testCreatingABrandNewGeneratorFromAGeneratedValueSingle()
{
$this->forAll(
Generator\bind(
Generator\vector(4, Generator\nat()),
Generators::bind(
Generators::vector(4, Generators::nat()),
function ($vector) {
return Generator\tuple(
Generator\elements($vector),
Generator\constant($vector)
return Generators::tuple(
Generators::elements($vector),
Generators::constant($vector)
);
}
)
Expand Down
5 changes: 3 additions & 2 deletions examples/BooleanTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
use Eris\Generator;

use Eris\Generators;
use Eris\TestTrait;

class BooleanTest extends PHPUnit_Framework_TestCase
Expand All @@ -9,7 +10,7 @@ class BooleanTest extends PHPUnit_Framework_TestCase
public function testBooleanValueIsTrueOrFalse()
{
$this->forAll(
Generator\bool()
Generators::bool()
)
->then(function ($boolValue) {
$this->assertTrue(
Expand Down
23 changes: 12 additions & 11 deletions examples/CharacterTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
use Eris\Generator;
use Eris\Antecedent;

use Eris\Antecedents;
use Eris\Generators;

class CharacterTest extends PHPUnit_Framework_TestCase
{
Expand All @@ -9,7 +10,7 @@ class CharacterTest extends PHPUnit_Framework_TestCase
public function testLengthOfAsciiCharactersInPhp()
{
$this->forAll(
Generator\char(['basic-latin'])
Generators::char(['basic-latin'])
)
->then(function ($char) {
$this->assertLenghtIs1($char);
Expand All @@ -19,9 +20,9 @@ public function testLengthOfAsciiCharactersInPhp()
public function testLengthOfPrintableAsciiCharacters()
{
$this->forAll(
Generator\char(['basic-latin'])
Generators::char(['basic-latin'])
)
->when(Antecedent\printableCharacter())
->when(Antecedents::printableCharacter())
->then(function ($char) {
$this->assertFalse(ord($char) < 32);
});
Expand All @@ -32,10 +33,10 @@ public function testMultiplePrintableCharacters()
$this
->minimumEvaluationRatio(0.1)
->forAll(
Generator\char(['basic-latin']),
Generator\char(['basic-latin'])
Generators::char(['basic-latin']),
Generators::char(['basic-latin'])
)
->when(Antecedent\printableCharacters())
->when(Antecedents::printableCharacters())
->then(function ($first, $second) {
$this->assertFalse(ord($first) < 32);
$this->assertFalse(ord($second) < 32);
Expand All @@ -49,10 +50,10 @@ public function testMultiplePrintableCharactersFromAnnotation()
{
$this
->forAll(
Generator\char(['basic-latin']),
Generator\char(['basic-latin'])
Generators::char(['basic-latin']),
Generators::char(['basic-latin'])
)
->when(Antecedent\printableCharacters())
->when(Antecedents::printableCharacters())
->then(function ($first, $second) {
$this->assertFalse(ord($first) < 32);
$this->assertFalse(ord($second) < 32);
Expand Down
7 changes: 4 additions & 3 deletions examples/ChooseTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
use Eris\Generator;

use Eris\Generators;
use Eris\TestTrait;

class ChooseTest extends PHPUnit_Framework_TestCase
Expand All @@ -9,8 +10,8 @@ class ChooseTest extends PHPUnit_Framework_TestCase
public function testSumOfTwoIntegersFromBoundedRangesIsCommutative()
{
$this->forAll(
Generator\choose(-1000, 430),
Generator\choose(230, -30000)
Generators::choose(-1000, 430),
Generators::choose(230, -30000)
)
->then(function ($first, $second) {
$x = $first + $second;
Expand Down
19 changes: 10 additions & 9 deletions examples/CollectTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php
use Eris\Generator;

use Eris\Generators;
use Eris\Listeners;
use Eris\TestTrait;
use Eris\Listener;

class CollectTest extends PHPUnit_Framework_TestCase
{
Expand All @@ -10,8 +11,8 @@ class CollectTest extends PHPUnit_Framework_TestCase
public function testGeneratedDataCollectionOnScalars()
{
$this
->forAll(Generator\neg())
->hook(Listener\collectFrequencies())
->forAll(Generators::neg())
->hook(Listeners::collectFrequencies())
->then(function ($x) {
$this->assertTrue($x < $x + 1);
});
Expand All @@ -21,10 +22,10 @@ public function testGeneratedDataCollectionOnMoreComplexDataStructures()
{
$this
->forAll(
Generator\vector(2, Generator\int()),
Generator\char()
Generators::vector(2, Generators::int()),
Generators::char()
)
->hook(Listener\collectFrequencies())
->hook(Listeners::collectFrequencies())
->then(function ($vector) {
$this->assertEquals(2, count($vector));
});
Expand All @@ -34,10 +35,10 @@ public function testGeneratedDataCollectionWithCustomMapper()
{
$this
->forAll(
Generator\seq(Generator\nat())
Generators::seq(Generators::nat())
)
->withMaxSize(10)
->hook(Listener\collectFrequencies(function ($array) {
->hook(Listeners::collectFrequencies(function ($array) {
return count($array);
}))
->then(function ($array) {
Expand Down
8 changes: 4 additions & 4 deletions examples/ConstantTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use Eris\Generator;
use Eris\Generators;

class ConstantTest extends \PHPUnit_Framework_TestCase
{
Expand All @@ -10,8 +10,8 @@ public function testUseConstantGeneratorExplicitly()
{
$this
->forAll(
Generator\nat(),
Generator\constant(2)
Generators::nat(),
Generators::constant(2)
)
->then(function ($number, $alwaysTwo) {
$this->assertTrue(($number * $alwaysTwo % 2) === 0);
Expand All @@ -22,7 +22,7 @@ public function testUseConstantGeneratorImplicitly()
{
$this
->forAll(
Generator\nat(),
Generators::nat(),
2
)
->then(function ($number, $alwaysTwo) {
Expand Down
13 changes: 7 additions & 6 deletions examples/DateTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
use Eris\Generator;

use Eris\Generators;

class DateTest extends PHPUnit_Framework_TestCase
{
Expand All @@ -8,7 +9,7 @@ class DateTest extends PHPUnit_Framework_TestCase
public function testYearOfADate()
{
$this->forAll(
Generator\date("2014-01-01T00:00:00", "2014-12-31T23:59:59")
Generators::date("2014-01-01T00:00:00", "2014-12-31T23:59:59")
)
->then(function (DateTime $date) {
$this->assertEquals(
Expand All @@ -21,7 +22,7 @@ public function testYearOfADate()
public function testDefaultValuesForTheInterval()
{
$this->forAll(
Generator\date()
Generators::date()
)
->then(function (DateTime $date) {
$this->assertGreaterThanOrEqual(
Expand All @@ -38,9 +39,9 @@ public function testDefaultValuesForTheInterval()
public function testFromDayOfYearFactoryMethodRespectsDistanceBetweenDays()
{
$this->forAll(
Generator\choose(2000, 2020),
Generator\choose(0, 364),
Generator\choose(0, 364)
Generators::choose(2000, 2020),
Generators::choose(0, 364),
Generators::choose(0, 364)
)
->then(function ($year, $dayOfYear, $anotherDayOfYear) {
$day = fromZeroBasedDayOfYear($year, $dayOfYear);
Expand Down
11 changes: 6 additions & 5 deletions examples/DifferentElementsTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
use Eris\Generator;

use Eris\Generators;
use Eris\TestTrait;

class Type
Expand Down Expand Up @@ -55,12 +56,12 @@ function ($candidate) use ($whatToRemove) {
};

$this
->forAll(Generator\bind(
->forAll(Generators::bind(
call_user_func_array('Eris\Generator\elements', $allTypes),
function ($first) use ($allTypes, $remove) {
return Generator\tuple(
Generator\constant($first),
Generator\elements($remove($allTypes, $first))
return Generators::tuple(
Generators::constant($first),
Generators::elements($remove($allTypes, $first))
);
}
))
Expand Down
5 changes: 3 additions & 2 deletions examples/DisableShrinkingTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
use Eris\Generator;

use Eris\Generators;
use Eris\TestTrait;

class DisableShrinkingTest extends \PHPUnit_Framework_TestCase
Expand All @@ -19,7 +20,7 @@ public function testThenIsNotCalledMultipleTime()
$this->calls = 0;
$this
->forAll(
Generator\nat()
Generators::nat()
)
->disableShrinking()
->then(function ($number) {
Expand Down
Loading

0 comments on commit 59efb45

Please sign in to comment.