Skip to content

Commit

Permalink
Merge pull request #166 from paragonie/fix-psalm
Browse files Browse the repository at this point in the history
Fix Psalm autoloading in Travis CI
  • Loading branch information
paragonie-security authored Oct 15, 2020
2 parents 41f3283 + 1d04681 commit 446fc9f
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 56 deletions.
23 changes: 13 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ matrix:
CHECK_MBSTRING=1
- dist: precise
php: "5.6"
env: USE_PSALM=1
env: USE_PSALM=0
CHECK_MBSTRING=1
- php: "7.0"
env: USE_PSALM=1
env: USE_PSALM=0
CHECK_MBSTRING=1
- php: "7.1"
env: USE_PSALM=1
CHECK_MBSTRING=1
env: USE_PSALM=0
CHECK_MBSTRING=0
- php: "7.2"
env: USE_PSALM=1
env: USE_PSALM=0
CHECK_MBSTRING=0
- php: "7.3"
env: USE_PSALM=1
Expand All @@ -36,7 +36,7 @@ matrix:
env: USE_PSALM=1
CHECK_MBSTRING=0
- php: "nightly"
env: USE_PSALM=1
env: USE_PSALM=0
CHECK_MBSTRING=0
- php: "hhvm"
env: USE_PSALM=1
Expand All @@ -45,15 +45,18 @@ matrix:
env: USE_PSALM=1
CHECK_MBSTRING=0
allow_failures:
- php: "nightly"
- php: "hhvm"
- php: "master"

install:
- composer self-update
- composer install
- if [[ $USE_PSALM -eq 1 ]]; then composer require --dev "vimeo/psalm:^0|^1|^2"; fi
- travis_retry composer install
- if [[ $USE_PSALM -eq 1 ]]; then composer require --dev "phpunit/phpunit:>=4"; fi
- if [[ $USE_PSALM -eq 1 ]]; then rm composer.lock; fi
- if [[ $USE_PSALM -eq 1 ]]; then rm -rf vendor; fi
- if [[ $USE_PSALM -eq 1 ]]; then composer require --dev "vimeo/psalm:^3"; fi

script:
- vendor/bin/phpunit
- php -dmbstring.func_overload=7 vendor/bin/phpunit
- if [[ $CHECK_MBSTRING -eq 1 ]]; then php -dmbstring.func_overload=7 vendor/bin/phpunit; fi
- if [[ $USE_PSALM -eq 1 ]]; then vendor/bin/psalm; fi
6 changes: 6 additions & 0 deletions other/phpunit-shim.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

class PHPUnit_Framework_TestCase extends \PHPUnit\Framework\TestCase
{

}
14 changes: 14 additions & 0 deletions phpunit-autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

require_once __DIR__ . '/psalm-autoload.php';

/**
* This is necessary for PHPUnit on PHP >= 5.3
*
* Class PHPUnit_Framework_TestCase
*/
if (PHP_VERSION_ID >= 50300) {
if (!class_exists('PHPUnit_Framework_TestCase')) {
require_once __DIR__ . '/other/phpunit-shim.php';
}
}
40 changes: 11 additions & 29 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,31 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="true"
backupStaticAttributes="false"
bootstrap="lib/random.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
failOnRisky="true"
failOnWarning="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
syntaxCheck="true"
>
<testsuites>
<testsuite name="Unit">
<directory>tests/unit</directory>
</testsuite>
</testsuites>
<testsuites>
<testsuite name="Random Compat Test Suite">
<directory suffix="Test.php">./tests/unit</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./lib</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="true" backupStaticAttributes="false" bootstrap="phpunit-autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" failOnRisky="true" failOnWarning="true" processIsolation="false" stopOnError="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./lib</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Random Compat Test Suite">
<directory suffix="Test.php">./tests/unit</directory>
</testsuite>
</testsuites>
</phpunit>
10 changes: 5 additions & 5 deletions psalm-autoload.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

require_once 'lib/byte_safe_strings.php';
require_once 'lib/cast_to_int.php';
require_once 'lib/error_polyfill.php';
require_once 'other/ide_stubs/libsodium.php';
require_once 'lib/random.php';
require_once __DIR__ . '/lib/byte_safe_strings.php';
require_once __DIR__ . '/lib/cast_to_int.php';
require_once __DIR__ . '/lib/error_polyfill.php';
require_once __DIR__ . '/other/ide_stubs/libsodium.php';
require_once __DIR__ . '/lib/random.php';

$int = random_int(0, 65536);
32 changes: 20 additions & 12 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
<?xml version="1.0"?>
<psalm
autoloader="psalm-autoload.php"
useDocblockTypes="true"
totallyTyped="true"
autoloader="psalm-autoload.php"
useDocblockTypes="true"
totallyTyped="true"
>
<projectFiles>
<directory name="lib" />
</projectFiles>
<issueHandlers>
<ReferenceConstraintViolation errorLevel="info" />
<!-- Type strictness surrounding /dev/urandom reads -->
<RedundantConditionGivenDocblockType errorLevel="info" />
<!-- We have to be explicit because PHP 5 lacks scalar types -->
<!-- We have to be explicit because PHP 5 lacks scalar types -->
<DocblockTypeContradiction errorLevel="info" />
<!-- We're strict about runtime checks -->
<DuplicateFunction errorLevel="info" />
<!-- We're a polyfill library! -->
<UnresolvableInclude errorLevel="info" />
<!-- Because we put the variants into their own subdirectory -->
<!-- Because we put the variants into their own subdirectory -->
<DuplicateClass errorLevel="info" />
<!-- Later versions of Psalm are only PHP 7 compatible, which
sees our redefinition of Error and TypeError as duplicate
class errors. -->
<!-- Later versions of Psalm are only PHP 7 compatible, which
sees our redefinition of Error and TypeError as duplicate
class errors. -->
<UndefinedDocblockClass errorLevel="info" />
<!-- COM is Windows only -->
<UndefinedConstant errorLevel="info" />
<!-- The Mcrypt constants aren't defined in PHP 7.2 -->
<!-- The Mcrypt constants aren't defined in PHP 7.2 -->
<MissingReturnType errorLevel="info" />
<!-- False positive with some versions of (Psalm, PHP) -->
<!-- False positive with some versions of (Psalm, PHP) -->
<InvalidReturnType errorLevel="info" />
<!-- The "last resort" function in lib/random.php -->
<!-- The "last resort" function in lib/random.php -->
<MixedInferredReturnType errorLevel="suppress" />
<!-- Only used in totallyTyped mode -->
<!-- Only used in totallyTyped mode -->
</issueHandlers>
</psalm>

0 comments on commit 446fc9f

Please sign in to comment.