Skip to content

Commit

Permalink
Allow tests to run without using the mbstring extension
Browse files Browse the repository at this point in the history
This really is a workaround for this issue:
travis-ci/travis-ci#4701

There is currently no way to disable PHP extensions on Travis CI, so we have to conditionally use them in the code itself.
  • Loading branch information
BenMorel committed Feb 27, 2018
1 parent 8dcc9d1 commit 07bd26a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ php:
- hhvm
- nightly

env:
- USE_PHP_EXTENSIONS=FALSE
- USE_PHP_EXTENSIONS=TRUE

matrix:
allow_failures:
- php: hhvm
Expand Down
14 changes: 14 additions & 0 deletions phpunit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

require __DIR__ . '/vendor/autoload.php';

echo 'Using PHP extensions: ';

if (getenv('USE_PHP_EXTENSIONS') === 'FALSE') {
define('NO_PHP_EXTENSIONS', true);
echo 'NO';
} else {
echo 'YES';
}

echo PHP_EOL;
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true" bootstrap="vendor/autoload.php">
<phpunit colors="true" bootstrap="phpunit.php">
<testsuites>
<testsuite>
<directory>tests</directory>
Expand Down
2 changes: 1 addition & 1 deletion src/Validator/StringValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected function validate(string $value) : void
*/
private function getLength(string $string) : ?int
{
if (extension_loaded('mbstring')) {
if (extension_loaded('mbstring') && ! defined('NO_PHP_EXTENSIONS')) { // constant used for tests
if (! mb_check_encoding($string, 'UTF-8')) {
return null;
}
Expand Down

0 comments on commit 07bd26a

Please sign in to comment.