Codeception / Codeception/c3

c3.php throwing PHP Warnings with Vagrant

未关闭
#32 7 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
PHP
星标
73
派生
46
PR 合并指标
30 天内没有已合并 PR

描述

# Description #

I seem to receiving an error when trying to generate code coverage for functional tests inside Vagrant. The tests run and the code coverage generates fine but some test fail (namely any check on the response being valid JSON) due to `PHP Warnings` being thrown by the c3.php file.

## Steps ##

When ssh'd into vagrant, I run this command:

```
./vendor/bin/codecept run functional --coverage-html=blah tests/functional/Company/Product/CategoriesCest.php
```

All 3 tests fail when trying to assert `$I->seeResponseIsJson();`. When taking a look at the failure report generate in `tests/_output/tests.Company.Product.CategoriesCest.orderCategoriesDesc.fail.html` I see the following error:

```
Warning: file_put_contents(/var/www/phpapps/api.testurl.test/tests/_output/c3tmp/codecoverage.serialized): failed to open stream: Permission denied in /var/www/phpapps/api.testurl.test/c3.php on line 321
```

At line 321, `c3.php` is trying to execute:

https://github.com/Codeception/c3/blob/f08f20b0b6191f0c58be022c6f20d5b1cdc1004c/c3.php#L320-L322

which it can't complete because the permissions for c3tmp directory are as follows:

```
drwxr-xr-x 1 vagrant vagrant 68 Aug 10 08:55 c3tmp/
```

I'm puzzled as to why codeception wouldn't have permissions to write `codecoverage.serialized` in `c3tmp/` when it has created the directory itself... Furthermore, applying full read-write permissions to the `c3tmp/` via:

```
chmod -R 777 tests/_output/c3tmp/
```

results in even more `PHP Warnings` being generated seemingly from the same type of issue i.e incorrect file permissions, read-write lock etc. I've detailed these issues below:

```
Warning: fopen(/var/www/phpapps/api.testurl.test/tests/_output/c3tmp/codecoverage.serialized): failed to open stream: Permission denied in /var/www/phpapps/api.testurl.test/c3.php on line 184

Warning: flock() expects parameter 1 to be resource, boolean given in /var/www/phpapps/api.testurl.test/c3.php on line 185

Notice: Undefined variable: phpCoverage in /var/www/phpapps/api.testurl.test/c3.php on line 194

Fatal error: Call to a member function merge() on a non-object in /var/www/phpapps/api.testurl.test/c3.php on line 318
```

# Additional Information #

- **Vagrant:** Vagrant 1.9.2

- **PHP:** PHP 5.5.9-1ubuntu4.20 (cli)

- functional.suite.dist.yml

```Yaml
class_name: FunctionalTester
error_level: -1
coverage:
enabled: true
modules:
enabled: [PhpBrowser, REST, Asserts, FunctionalHelper]
config:
PhpBrowser:
url: http://api.testurl.test/
REST:
url: http://api.testurl.test/

```

- codeception.yml

```Yaml
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
helpers: tests/_support
settings:
bootstrap: _bootstrap.php
colors: true
memory_limit: 1024M
coverage:
enabled: true
whitelist:
include:
- src/*
- public/*
exclude:
- src/Company/*/apidoc.json
- src/Company/*/apiDocVersioning/*
```

贡献指南

这个仓库没有索引到贡献指南

调研方向

在 Vagrant 中使用列出的 Codeception 命令重现故障,并检查 tests/_output/c3tmp。先从 c3.php 的第 184-194 行和第 318-321 行开始,然后将报告的文件和锁警告与目录权限进行比较。功能测试和 JSON 断言在没有这些警告或后续 fatal error 的情况下完成,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
php
领域
testing-qa
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。