我写了一个脚本,该脚本遍历每个目录,同时忽略了一些目录,并执行composer install
,phpunit
并且应该可以工作,在大多数情况下它确实如此 - 当我第二次运行它时......
问题是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 刷新允许它正常工作。这可能是问题所在吗?