必须 运行 我的脚本两次?

Have to run my script twice?

我编写了一个遍历每个目录的脚本,同时忽略了一些目录,并执行了 composer installphpunit 并且应该可以工作,在大多数情况下它可以工作 - 当我 运行第二次...

问题是 phpunit 命令。脚本进入该命令并打印出:

...
+ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files
+ phpunit
PHPUnit 4.6.4 by Sebastian Bergmann and contributors.

Usage: phpunit [options] UnitTest [UnitTest.php]
       phpunit [options] <directory>
...

当我第二次 运行 时,我得到:

...
+ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files
+ phpunit
PHPUnit 4.6.4 by Sebastian Bergmann and contributors.

Configuration read from /vagrant/Freya/Form/phpunit.xml

...............................................................

Time: 647 ms, Memory: 15.25Mb

OK (63 tests, 63 assertions)
...

我不应该 运行 脚本两次。该脚本的目标是说:您有供应商目录吗?不,好吧做一个 composer install 和 运行 phpunit 如果我们遇到一个目录有一个 routes-test.sh 文件我们然后做一些其他的事情,但概念仍然是相同的一天结束。

因此,使用以下脚本:

#!/usr/bin/env bash

set -eux

function run_tests() {
  if [[ -f "composer.json" ]]; then
    if [[ -d "vendor" ]]; then
      composer update
      phpunit
      cd ../
    else
      composer install
      phpunit
      cd ../
    fi
  fi
}

function wordpress_routes() {
  cd ../../
  if [[ -d "trunk" ]]; then
    cd trunk
    if [[ -f "wp-tests-config.php" ]]; then
      continue
    else
      cd ../Freya/Routes/
      cp wp-tests-config.php ../../trunk/
    fi
  else
    svn co http://develop.svn.wordpress.org/trunk/
    cd Freya/Routes/
    cp wp-tests-config.php ../../trunk/
  fi
}

for f in *; do
  if [[ -d $f ]]; then
    if [[ $f != ".git" ]] && [[ $f != "bin" ]] && [[ $f != "docs" ]]; then
      cd "$f/"

      if [[ -f "routes-test" ]]; then
        wordpress_routes
        run_tests
      fi

      run_tests
    fi
  fi
done

为什么我要 运行 脚本两次才能让 phpunit 实际上 运行?

我以前看过类似的东西。我遇到了会话变量的问题,直到 第一次 运行 之后才初始化...然后 F5-refresh 允许它正常工作。这可能是问题所在吗?