Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

c3.php throwing PHP Warnings with Vagrant #32

Open
austintino opened this issue Aug 10, 2017 · 7 comments
Open

c3.php throwing PHP Warnings with Vagrant #32

austintino opened this issue Aug 10, 2017 · 7 comments

Comments

@austintino
Copy link

austintino commented Aug 10, 2017

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:

c3/c3.php

Lines 320 to 322 in f08f20b

if ($file === null) {
file_put_contents($current_report, serialize($existingCodeCoverage), LOCK_EX);
} else {

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

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
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/*
@austintino
Copy link
Author

@olemartinorg Any idea what might be causing this? Issue caused in the code of your last commit.

Thanks in advance!

@olemartinorg
Copy link
Contributor

Huh.. I think this must be a problem with the file system mirror inside the Vagrant VM. I've had strange problems like this with the VirtualBox shared folder drivers before. Can you check a few things for me?

  1. Connect to the VM as the root user and try to touch a file in the same directory. Do you still get a permission denied error? Root should have access to everything, so that's a sure sign there's something going on with the shared folder.
  2. What are the permission settings on the folder on the host machine? What are you running on your host, is it win/mac/linux?
  3. On the VM, try 'stat someFileThatDontExist' and then create it on your host machine (not on the VM!). After that, run 'ls -l' in the folder to see what the permissions on that (now existing) file is. There's a bug in some older version of the VirtualBox drivers that ends up marking the file with a lot of question marks on the permissions fields, and you can't read it on the VM until after a reboot.

@olemartinorg
Copy link
Contributor

Did you find a solution, @austintino?

@austintino
Copy link
Author

Hi @olemartinorg,

Apologies for the slight delay in replying. You can find the answers to your questions below.
As stated above, the c3tmp directory is created by running the functional tests but then fails to be be able to write files to it which is very peculiar. How the information below helps.

1. Connect to the VM as the root user and try to touch a file in the same directory.

vagrant@ubuntu: ssh root@locahost
root@ubuntu:~# whoami
root
root@ubuntu:~# touch /var/www/phpapps/api.testurl.test/tests/_output/c3tmp/testfile.txt
root@ubuntu:~# ls -l /var/www/phpapps/api.testurl.test/tests/_output/c3tmp/
total 0
-rw-r--r-- 1 vagrant vagrant 0 Aug 23 11:37 testfile.txt

No issues creating a file in this directory. I had tried this before and found the same results.

2.a What are the permission settings on the folder on the host machine?

MyName:api.testurl.test thisismyname$ ls -l /Users/thisismyname/Sites/api.testurl.test/tests/_output/
total 1512
-rw-r--r--  1 thisismyname  staff    1631 23 Aug 11:30 GroupTokenCest.validGroupToken.fail.html
drwxr-xr-x  9 thisismyname  staff     306 23 Aug 11:33 blah
drwxr-xr-x  3 thisismyname  staff     102 23 Aug 11:37 c3tmp
-rw-r--r--  1 thisismyname  staff  766071 23 Aug 11:31 coverage.serialized

2.b What are you running on your host, is it win/mac/linux?

The host machine is

iMac, Late 2009
macOS Sierra Version 10.12.6

The VM is

VirtualBox
Version 5.1.18 r114002

Vagrant 1.9.2
Ubuntu 14.04.5 LTS (GNU/Linux 4.4.0-31-generic x86_64)

3. On the VM, try 'stat someFileThatDontExist' and then create it on your host machine (not on the VM!). After that, run 'ls -l' in the folder to see what the permissions on that (now existing) file is.

On the VM:

vagrant@ubuntu:~$ whoami
vagrant
vagrant@ubuntu:~$ stat /var/www/phpapps/api.testurl.test/tests/_output/c3tmp/doesntexist.txt
stat: cannot stat ‘/var/www/phpapps/api.testurl.test/tests/_output/c3tmp/doesntexist.txt’: No such file or directory

On the host:

MyName:~ thisismyname$ stat /Users/thisismyname/Sites/api.testurl.test/tests/_output/c3tmp/doesntexist.txt
stat: /Users/thisismyname/Sites/api.testurl.test/tests/_output/c3tmp/doesntexist.txt: stat: No such file or directory
MyName:~ thisismyname$ touch /Users/thisismyname/Sites/api.testurl.test/tests/_output/c3tmp/doesntexist.txt
MyName:~ thisismyname$ ls -l /Users/thisismyname/Sites/api.testurl.test/tests/_output/c3tmp/doesntexist.txt
-rw-r--r--  1 thisismyname  staff  0 23 Aug 11:55 /Users/thisismyname/Sites/api.testurl.test/tests/_output/c3tmp/doesntexist.txt

@austintino
Copy link
Author

Any update @olemartinorg ?

@olemartinorg
Copy link
Contributor

Oh, sorry about this - I forgot all about it and went on vacation...

Anyway, thanks for all the debugging! I have some more questions, that didn't quite clear things up for me.

  1. Which user is running all of this on the vagrant VM? I'm assuming the vagrant user? Can you log in as that user and touch a file in the c3tmp folder, or do you get the same error? What if you try to touch that specific file?
  2. On the third question I posted earlier, the last "ls -l" on the vagrant VM, not the host (sorry I didn't make that clear). What do you see then?

@nicholascus
Copy link

nicholascus commented Mar 20, 2018

Hi @austintino ,
you can sudo as your webserver/php process user and try to create, edit and save file /var/www/phpapps/api.testurl.test/tests/_output/c3tmp/codecoverage.serialized
`
su www-data -s /bin/bash

vi /var/www/phpapps/api.testurl.test/tests/_output/c3tmp/codecoverage.serialized

i new text

[ESC]:qw

ls -al /var/www/phpapps/api.testurl.test/tests/_output/c3tmp/
`
then you will know where to continue with your issue investigation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants