【问题标题】:Travis CI is not case-sensitive by default?Travis CI 默认不区分大小写?
【发布时间】:2015-08-31 14:41:08
【问题描述】:

我有一个 php 项目,它具有 composer 依赖项,这些依赖项在我的单元测试的代码路径中进行了固有的测试。这是我的示例代码:

<?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;
}

我的测试只是测试方法,但当然会在我的源代码中执行FooBar::logTimer 行。问题是如果我将FooBar 类错误输入为fooBaR,我预计我的测试会失败。不幸的是,travis 构建正在通过......但我不清楚为什么。

.travis.yml文件:

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

对可能出现的问题有任何想法吗?

【问题讨论】:

    标签: filesystems phpunit composer-php travis-ci case-sensitive


    【解决方案1】:

    当涉及到类名时,PHP 不区分大小写。如果您的代码声明了一个名为 Foo 的类,并且执行了此定义,您还可以实例化任何其他 case 样式,例如 foofOO

    PHP 将保留触发自动加载的事件的大小写(即 PHP 第一次遇到类名时),如果该大小写样式与区分大小写的文件名不匹配,则使用该类将失败。

    我认为以正确的案例风格编写类是一个不应该用单元测试测试的问题。这是您自己的代码无法解决的问题 - 如果您使用功能强大的 IDE,它知道所有可以使用的类,它基本上不存在。

    另外:您的问题没有提供演示问题的代码。它包含的代码可能不会像您认为的那样做。

    【讨论】:

      猜你喜欢
      • 2021-02-27
      • 2010-10-06
      • 2019-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-01
      • 2013-03-06
      • 2020-02-18
      相关资源
      最近更新 更多