如何在GIT上通过断言实现phpunitest?
我有一个GITWrapper,它维护一个GIT目录。对于一些测试,我需要这些东西:如何在GIT上通过断言实现phpunitest?,php,git,unit-testing,phpunit,Php,Git,Unit Testing,Phpunit,我有一个GITWrapper,它维护一个GIT目录。对于一些测试,我需要这些东西: 带有GIT的目录 一次不包含文件的初始提交 一次提交包含两个新文件 一次提交,包含对文件的一些更改 我的GitWrapper现在浏览历史并做一些事情。所以我需要测试这些东西。例如: 前提条件/历史记录如上所述。 GitWrapper应该指出文件系统及其内容中的一些差异 这些都是我需要测试但不知道如何测试的东西。我想有一些简单或常见的解决方案,比如使用vfstream或其他助手,我还不知道。所以我想到了这些问题
- 带有GIT的目录
- 一次不包含文件的初始提交
- 一次提交包含两个新文件
- 一次提交,包含对文件的一些更改
- 您将如何在单元测试中实现此回购
- 存储库将放在哪里
- 如何为下一次测试回滚回购更改
- 如果测试回购的设置很短,我建议只编写一个执行所需操作的脚本。比如:
# file setup.sh : #!/bin/sh repo=$1 # create the repo : mkdir -p $1 cd $1 git init # first empty commit : git commit --allow-empty -m 'first commit' # second commit : a couple of new files echo "Foo" > bar.txt echo "Hello" > world.txt git add -A git commit -m 'second commit' # etc ...
exec('unittest/git/setup.sh', '/tmp/randomString'):
# file setup.sh :
#!/bin/sh
repo=$1
# create the repo :
mkdir -p $1
cd $1
git init
# first empty commit :
git commit --allow-empty -m 'first commit'
# second commit : a couple of new files
echo "Foo" > bar.txt
echo "Hello" > world.txt
git add -A
git commit -m 'second commit'
# etc ...
exec('unittest/git/setup.sh', '/tmp/randomString'):
拆掉它:
exec('rm', '-rf', '/tmp/randomString');
- 如果您想要的设置更大:使用您的设置创建一个git repo,在单元测试开始时只需将其克隆到
中的某个位置,然后将其删除/tmp
// setup exec('git', 'clone', 'path/or/url/to/initial/setup', '/tmp/randomString'); // teardown exec('rm', '-rf', '/tmp/randomString');