Skip to content

Update CONTRIBUTING.md #373

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

Merged
1 commit merged into from
Sep 17, 2014
Merged

Update CONTRIBUTING.md #373

1 commit merged into from
Sep 17, 2014

Conversation

franzholz
Copy link

The PHPUnit tests run into error messages if PHPWord has not been installed by Composer.

The PHPUnit tests run into error messages if PHPWord has not been installed by Composer.
ghost pushed a commit that referenced this pull request Sep 17, 2014
@ghost ghost merged commit 68422ef into PHPOffice:develop Sep 17, 2014
@ghost
Copy link

ghost commented Sep 17, 2014

Sounds reasonable. Thanks for the PR.

@franzholz franzholz deleted the patch-3 branch September 17, 2014 17:06
@ghost
Copy link

ghost commented Sep 17, 2014

By the way, I'm stuck a bit. @franzholz, could you please clarify your sentence?

Do you want just explicitly indicate that someone must have PHPWord sources (at all) to run unit tests? Or you meant that PHPWord sources retrieved in any way except Composer won't allow to run unit tests?

@franzholz
Copy link
Author

It is the second. If you have PHPWord PHP code on your computer, and if you did formerly not use Composer to install it, then you cannot run the PHPUnit test. This has cost me several hours to figure this out. The PHPWord sources are not sufficient to run the tests.

@Progi1984 Progi1984 assigned ghost Sep 18, 2014
@Progi1984 Progi1984 added this to the 0.12.0 milestone Sep 18, 2014
@ghost
Copy link

ghost commented Oct 5, 2014

Hi, @franzholz.

I've just tried to run unit tests against PHPWord source code, downloaded from GitHub repo without Composer. You know, I succeeded.

Could you please describe how did you try (step by step)?

@franzholz
Copy link
Author

I have added the same in issue #372.

I have fetched the whole PHPWord from Git and put it under my local folder PHPWordDevelop.

[franz@localhost developer]$ ls -ld PHPWordDevelop/*
drwxrwxrwx 3 franz live   4096 sept. 16 18:41 PHPWordDevelop/build/
-rw-r--r-- 1 franz live  21440 oct.  11 11:45 PHPWordDevelop/CHANGELOG.md
-rw-r--r-- 1 franz live   1979 oct.  11 11:45 PHPWordDevelop/composer.json
-rw-r--r-- 1 franz live 131936 oct.  11 11:45 PHPWordDevelop/composer.lock
-rw-r--r-- 1 franz live   2088 oct.  11 11:45 PHPWordDevelop/CONTRIBUTING.md
-rw-r--r-- 1 franz live  35147 oct.  11 11:45 PHPWordDevelop/COPYING
-rw-r--r-- 1 franz live   7651 oct.  11 11:45 PHPWordDevelop/COPYING.LESSER
drwxrwxrwx 4 franz live   4096 oct.  11 11:45 PHPWordDevelop/docs/
-rw-r--r-- 1 franz live    688 oct.  11 11:45 PHPWordDevelop/LICENSE
-rw-r--r-- 1 franz live   1185 oct.  11 11:45 PHPWordDevelop/phpmd.xml.dist
-rw-r--r-- 1 franz live    970 oct.  11 11:45 PHPWordDevelop/phpunit.xml.dist
-rw-r--r-- 1 franz live    303 oct.  11 11:45 PHPWordDevelop/phpword.ini.dist
-rw-r--r-- 1 franz live   7589 oct.  11 11:45 PHPWordDevelop/README.md
drwxrwxrwx 5 franz live   4096 oct.  11 11:45 PHPWordDevelop/samples/
drwxrwxrwx 3 franz live   4096 sept.  9 11:17 PHPWordDevelop/src/
drwxrwxrwx 3 franz live   4096 oct.  11 11:45 PHPWordDevelop/tests/
-rw-r--r-- 1 franz live      6 oct.  11 11:45 PHPWordDevelop/VERSION

Then I start the unit tests. And they hang in an error message.

[franz@localhost developer]$  phpunit  PHPWordDevelop/tests/
PHPUnit 4.2.6 by Sebastian Bergmann.

EE
Fatal error: Class 'PhpOffice\PhpWord\Collection\Footnotes' not found in /var/www/html/developer/PHPWordDevelop/tests/PhpWord/Tests/Collection/CollectionTest.php on line 27

Call Stack:
    0.0003     236024   1. {main}() /home/franz/.composer/vendor/phpunit/phpunit/phpunit:0
    0.0042     558064   2. PHPUnit_TextUI_Command::main() /home/franz/.composer/vendor/phpunit/phpunit/phpunit:56
    0.0043     558688   3. PHPUnit_TextUI_Command->run() /home/franz/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:138
    0.5548   13570136   4. PHPUnit_TextUI_TestRunner->doRun() /home/franz/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:186
    0.5581   13891600   5. PHPUnit_Framework_TestSuite->run() /home/franz/.composer/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:423
    0.8006   15210472   6. PHPUnit_Framework_TestSuite->run() /home/franz/.composer/vendor/phpunit/phpunit/src/Framework/TestSuite.php:703
    0.8027   15213792   7. PHPUnit_Framework_TestCase->run() /home/franz/.composer/vendor/phpunit/phpunit/src/Framework/TestSuite.php:703
    0.8027   15215288   8. PHPUnit_Framework_TestResult->run() /home/franz/.composer/vendor/phpunit/phpunit/src/Framework/TestCase.php:771
    0.8035   15263456   9. PHPUnit_Framework_TestCase->runBare() /home/franz/.composer/vendor/phpunit/phpunit/src/Framework/TestResult.php:643
    0.8043   15308952  10. PHPUnit_Framework_TestCase->runTest() /home/franz/.composer/vendor/phpunit/phpunit/src/Framework/TestCase.php:835
    0.8043   15309824  11. ReflectionMethod->invokeArgs() /home/franz/.composer/vendor/phpunit/phpunit/src/Framework/TestCase.php:963
    0.8043   15310096  12. PhpOffice\PhpWord\Tests\Element\CollectionTest->testCollection() /home/franz/.composer/vendor/phpunit/phpunit/src/Framework/TestCase.php:963

I also tried to start the tests from inside of the folder PHPWordDevelop. And the tests still hang.

[franz@localhost PHPWordDevelop (develop)]$ phpunit tests 

Fatal error: Uncaught exception 'Exception' with message 'Unable to load dependencies' in /var/www/html/developer/PHPWordDevelop/tests/bootstrap.php on line 34

Exception: Unable to load dependencies in /var/www/html/developer/PHPWordDevelop/tests/bootstrap.php on line 34

Call Stack:
    0.0003     236016   1. {main}() /home/franz/.composer/vendor/phpunit/phpunit/phpunit:0
    0.0044     558080   2. PHPUnit_TextUI_Command::main() /home/franz/.composer/vendor/phpunit/phpunit/phpunit:56
    0.0044     558704   3. PHPUnit_TextUI_Command->run() /home/franz/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:138
    0.0044     561288   4. PHPUnit_TextUI_Command->handleArguments() /home/franz/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:148
    0.0752     937736   5. PHPUnit_TextUI_Command->handleBootstrap() /home/franz/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:650
    0.0754     946264   6. PHPUnit_Util_Fileloader::checkAndLoad() /home/franz/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:814
    0.0754     946448   7. PHPUnit_Util_Fileloader::load() /home/franz/.composer/vendor/phpunit/phpunit/src/Util/Fileloader.php:77
    0.0755     957576   8. include_once('/var/www/html/developer/PHPWordDevelop/tests/bootstrap.php') /home/franz/.composer/vendor/phpunit/phpunit/src/Util/Fileloader.php:93

So I think that it is necessary to fetch the PHP code using Composer.

@ghost
Copy link

ghost commented Oct 14, 2014

Great! This is the expected behavior, because PHPUnit really doesn't know where to get the classes. Please try calling PHPUnit with --bootstrap option and pass tests/bootstrap.php file in it. I suppose, the command will look like this:
phpunit --bootstrap PHPWordDevelop/tests/bootstrap.php PHPWordDevelop/tests/

Information about PHPUnit comman-line options can be found here.

@franzholz
Copy link
Author

So I must start the tests from outside of the folder PHPWordDevelop.

[franz@localhost developer]$ phpunit --bootstrap PHPWordDevelop/tests/bootstrap.php PHPWordDevelop/tests/

Fatal error: Uncaught exception 'Exception' with message 'Unable to load dependencies' in /var/www/html/developer/PHPWordDevelop/tests/bootstrap.php on line 34

Exception: Unable to load dependencies in /var/www/html/developer/PHPWordDevelop/tests/bootstrap.php on line 34

Call Stack:
    0.0002     236384   1. {main}() /home/franz/.composer/vendor/phpunit/phpunit/phpunit:0
    0.0041     558400   2. PHPUnit_TextUI_Command::main() /home/franz/.composer/vendor/phpunit/phpunit/phpunit:56
    0.0041     559024   3. PHPUnit_TextUI_Command->run() /home/franz/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:138
    0.0041     561608   4. PHPUnit_TextUI_Command->handleArguments() /home/franz/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:148
    0.0048     598568   5. PHPUnit_TextUI_Command->handleBootstrap() /home/franz/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:598
    0.0050     607232   6. PHPUnit_Util_Fileloader::checkAndLoad() /home/franz/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:814
    0.0050     607416   7. PHPUnit_Util_Fileloader::load() /home/franz/.composer/vendor/phpunit/phpunit/src/Util/Fileloader.php:77
    0.0052     618544   8. include_once('/var/www/html/developer/PHPWordDevelop/tests/bootstrap.php') /home/franz/.composer/vendor/phpunit/phpunit/src/Util/Fileloader.php:93

@ghost
Copy link

ghost commented Oct 15, 2014

Do you have PHPWordDevelop/vendor/autoload.php file?

@franzholz
Copy link
Author

I do not have a vendor folder inside of PHPWordDevelop. The vendor folder is on the same level as PHPWordDevelop. The base directory is /var/www/html/developer. The base directory contains the folders PHPWordDevelop and vendor. The vendor folder contains an autoload. However this has been generated by Composer. Everything inside of the vendor folder has been installed by Composer.

@gabrielbull
Copy link
Member

Can you run these commands inside PHPWordDevelop:

cd PHPWordDevelop
curl -sS https://getcomposer.org/installer | php
php composer.phar install --dev
php vendor/bin/phpunit --bootstrap=tests/bootstrap.php

should run the tests fine

@franzholz
Copy link
Author

So I did install all this bunch of software packages inside of PHPWordDevelop. This has the big drawback that I need reinstall them only for PHPWord.

[franz@localhost PHPWordDevelop (develop)]$ php bin/phpunit --bootstrap= tests/bootstrap.php
Could not open input file: bin/phpunit

So I try to use phpunit directly:

[franz@localhost PHPWordDevelop (develop)]$ phpunit  --bootstrap= tests/bootstrap.php

Warning: require(/home/franz/.composer/vendor/phpunit/phpunit/tests/../vendor/autoload.php): failed to open stream: No such file or directory in /home/franz/.composer/vendor/phpunit/phpunit/tests/bootstrap.php on line 2

Call Stack:
    0.0002     236192   1. {main}() /home/franz/.composer/vendor/phpunit/phpunit/phpunit:0
    0.0097     558192   2. PHPUnit_TextUI_Command::main() /home/franz/.composer/vendor/phpunit/phpunit/phpunit:56
    0.0098     558824   3. PHPUnit_TextUI_Command->run() /home/franz/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:138
    0.0098     561408   4. PHPUnit_TextUI_Command->handleArguments() /home/franz/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:148
    0.0179     598056   5. PHPUnit_TextUI_Command->handleBootstrap() /home/franz/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:598
    0.0192     606720   6. PHPUnit_Util_Fileloader::checkAndLoad() /home/franz/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:814
    0.0531     606912   7. PHPUnit_Util_Fileloader::load() /home/franz/.composer/vendor/phpunit/phpunit/src/Util/Fileloader.php:77
    0.0582     610808   8. include_once('/home/franz/.composer/vendor/phpunit/phpunit/tests/bootstrap.php') /home/franz/.composer/vendor/phpunit/phpunit/src/Util/Fileloader.php:93


Fatal error: require(): Failed opening required '/home/franz/.composer/vendor/phpunit/phpunit/tests/../vendor/autoload.php' (include_path='/home/franz/.composer/vendor/phpunit/php-text-template:/home/franz/.composer/vendor/phpunit/php-timer:/home/franz/.composer/vendor/phpunit/php-file-iterator:/home/franz/.composer/vendor/phpunit/php-code-coverage:/home/franz/.composer/vendor/phpunit/phpunit:/home/franz/.composer/vendor/symfony/yaml:.:/usr/lib64/php/:/usr/share/pear/:/usr/share/php/') in /home/franz/.composer/vendor/phpunit/phpunit/tests/bootstrap.php on line 2

Call Stack:
    0.0002     236192   1. {main}() /home/franz/.composer/vendor/phpunit/phpunit/phpunit:0
    0.0097     558192   2. PHPUnit_TextUI_Command::main() /home/franz/.composer/vendor/phpunit/phpunit/phpunit:56
    0.0098     558824   3. PHPUnit_TextUI_Command->run() /home/franz/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:138
    0.0098     561408   4. PHPUnit_TextUI_Command->handleArguments() /home/franz/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:148
    0.0179     598056   5. PHPUnit_TextUI_Command->handleBootstrap() /home/franz/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:598
    0.0192     606720   6. PHPUnit_Util_Fileloader::checkAndLoad() /home/franz/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:814
    0.0531     606912   7. PHPUnit_Util_Fileloader::load() /home/franz/.composer/vendor/phpunit/phpunit/src/Util/Fileloader.php:77
    0.0582     610808   8. include_once('/home/franz/.composer/vendor/phpunit/phpunit/tests/bootstrap.php') /home/franz/.composer/vendor/phpunit/phpunit/src/Util/Fileloader.php:93

So I read the files inside of my second vendor folder:

[franz@localhost vendor (develop)]$ ls -x /var/www/html/developer/PHPWordDevelop/vendor
autoload.php  bin/          cilex/      composer/  doctrine/       dompdf/          erusev/         jms/
knplabs/      monolog/      mpdf/       nikic/     pdepend/        phenx/           phpcollection/  phpdocumentor/
phploc/       phpmd/        phpoption/  phpunit/   pimple/         psr/             sebastian/      squizlabs/
symfony/      tecnick.com/  theseer/    twig/      zendframework/  zetacomponents/

@gabrielbull
Copy link
Member

You need to use the version of PHPUnit provided by PHPWord, make sure you are inside the PHPWord directory when executing the following command (sorry I made a typo in my previous comment and that is why it did not work):

php vendor/bin/phpunit --bootstrap=tests/bootstrap.php

This has the big drawback that I need reinstall them only for PHPWord.

You only need to install dev dependencies when developing the PHPWord library, no need to include them if you just want to include PHPWord inside of a project. If you are planning on contributing you should indeed clone PHPWord independently, install all required development dependencies, and run tests cases as intended.

@franzholz
Copy link
Author

[franz@localhost PHPWordDevelop (develop)]$ pwd
/var/www/html/developer/PHPWordDevelop

[franz@localhost PHPWordDevelop (develop)]$ php vendor/bin/phpunit --bootstrap=tests/bootstrap.php

This now runs the tests.

PHPUnit 3.7.37 by Sebastian Bergmann.

Configuration read from /var/www/html/developer/PHPWordDevelop/phpunit.xml.dist

...............................................................  63 / 415 ( 15%)
............................................................... 126 / 415 ( 30%)
............................................................... 189 / 415 ( 45%)
............................................................... 252 / 415 ( 60%)
............................................................... 315 / 415 ( 75%)
............................................................... 378 / 415 ( 91%)
.....................................

Time: 2.19 minutes, Memory: 44.50Mb

OK (415 tests, 1283 assertions)

Generating code coverage report in Clover XML format ... done

Generating code coverage report in HTML format ...

Maybe you should add this to the documentation. I would still prefer to have only one vendor folder which is on the same level as the PHPWordDevelop folder. Then I can easily install third party packages as dompdf.

@gabrielbull
Copy link
Member

This is the intended behaviour for both the dompdf and phpword libraries. You should install them separately and work on them separately. Then, when you are done working on them, you should include them in your main project. You should not work on these two libraries from inside the vendor directory.

ghost pushed a commit that referenced this pull request Oct 16, 2014
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants