Search code examples
phpcomposer-phpphpunitfilesystemstravis-ci

Travis CI is not case-sensitive by default?


I have a php project that has composer dependencies which are inherently tested in the code path of my unit tests. Here's my sample code:

<?php
// where FooBar is a composer package but I'm purposely typing it incorrectly here
use \fooBaR
public function appendNameToWords(array $words, $name)
{
    $start = microtime(true);
    $newWords = array_map(function($word){
      return $word . $name;
    }, $words);
    // logs the diff between start and end time
    FooBar::logTimer($start);
    return $newWords;
}

My test is simply testing the method but of course executes the line FooBar::logTimer in my source code. The problem is I'm expecting my test to fail if I mistype the class FooBar to be fooBaR. Unfortunately, the travis build is passing...but i'm unclear why.

.travis.yml file:

 language: php
 php:
 - 5.6
 install:        script/install
 script:
 - script/test

Any ideas on what could be wrong?


Solution

  • PHP is not case sensitive when it comes to class names. If your code declares a class named Foo, and this definition is executed, you can also instantiate any other case style, like foo or fOO.

    PHP will preserve the case of the occurrence that triggers the autoload (i.e. the first time PHP encounters a class name), and if that case style does not match a case sensitive file name, using the class will fail.

    I consider writing the class in the correct case style a problem that should not be tested with a unit test. It's a problem that cannot be solved in your own code - and it is basically not existing if you use a powerful IDE that knows all classes that can be used.

    Additionally: Your question does not provide code that demonstrates the problem. And it contains code that probably does not do what you think it does.