sfYaml echoln() error in Zend Framework project PHPUnit tests - php

I'm starting a Zend Framework project and I decided to use Doctrine 1.2.3 instead of the Zend_Db classes. I configured my project and doctrine command line script works just fine, my index controller can query my database without problems, but Unit Tests with PHPUnit throws an error:
Fatal error: Cannot redeclare echoln() (previously declared in D:\Zend\Apache2\vhost\myproject\library\Doctrine\Parser\sfYaml\sfYaml.php:132) in D:\Zend\ZendServer\bin\PEAR\SymfonyComponents\YAML\sfYaml.php on line 135
I'm using Zend Server with PHP 5.3. PHPUnit requires the PEAR SymfonyComponents' YAML package. This happens everytime my unit test bootstrap tries to re-create and load the whole testing database, specially when loading the fixtures files. This is the full command and output:
D:\Zend\Apache2\vhost\myproject\tests>phpunit
build-all-reload - Successfully dropped database for connection named 'doctrine'
build-all-reload - Successfully created database for connection named 'doctrine'
build-all-reload - Created tables successfully
build-all-reload - Data was successfully loaded
PHPUnit 3.5.10 by Sebastian Bergmann.
Fatal error: Cannot redeclare echoln() (previously declared in D:\Zend\Apache2\vhost\myproject\library\Doctrine\Parser\sfYaml\sfYaml.php:132) in D:\Zend\ZendServer\bin\PEAR\SymfonyComponents\YAML\sfYaml.php on line 135
D:\Zend\Apache2\vhost\myproject\tests>
As result, my database is completely created and data fixtures are loaded successfully. But this error stops the Unit Testing process. I only have one test class for Doctrine models but this error happens even if I comment its testing code.
It is strange, because if I execute the doctrine script by hand, It runs without problems, and no error happens when the system runs via web. This just happens for Unit Testing.
How can I avoid this libraries collition, if both, Doctrine and PHPUnit include the same sfYaml class from PEAR and from inside Doctrine, without breaking the working system?

You can see in the error message that sfYaml.php is being loaded from two different locations. You must clean up your include path so it has only one copy of each library you need. Use var_dump(get_include_path()) in your bootstrap.php to diagnose the issue.

Related

Symfony 3.4 Where to Put Auto-Generating Proxy Class Config Mode?

Symfony is complaining about renaming proxy classes during my multiple instance command execution. Basically, I am running a Symfony command mutliple times at the same time, and it is throwing an error for generated proxy classes not being able to be renamed...
In ProxyGenerator.php line 293:
Warning: rename(/Users/jlroberts/Projects/Shred/Symfony/var/cache/dev/doctrine/orm/Proxies/__CG__AppBundleEntityNslocaleCountryNames.php.5ee27c106fc5f0.51071995,/Users/jlroberts/Projects/Shred/Symfony/var/cache/dev/doctrine/orm/Proxies/__CG__AppBundleEntityNslocaleCountryNames.php): No such file or directory
I found this issue on github
https://github.com/doctrine/common/issues/327
And I think it says to set the AutoGeneratedProxyClasses to AUTOGENERATE_FILE_NOT_EXISTS, which I found on
https://www.doctrine-project.org/projects/doctrine-orm/en/latest/reference/advanced-configuration.html
Which says I use this following line to set that mode
$mode = AUTOGENERATE_FILE_NOT_EXISTS;
$config->setAutoGenerateProxyClasses($mode);
but where do I put that line?

PHPUnit Doctrine error on Controllers CodeIgniter

Using CodeIgniter/CIUnit/PHPUnit/Doctrine combo and having issues running the controllers folder. The models folder works fine, but the controller folder seems to have this error.
$ phpunit controllers
PHPUnit 4.1.3 by Sebastian Bergmann.
Configuration read from
/home/web/web.com/codeigniter/tests/phpunit.xml
.
Fatal error: Cannot redeclare class Doctrine\Common\ClassLoader in
/home/web/web.com/codeigniter/application/libraries/Doctrine/Common/ClassLoader.php on line 35
Anyone know how to get it to by pass this error. I checked and the only place its being declared is in the ClassLoader.php. Don't see a second redeclaration anywhere. Any help is appreciated.
Simple change on Doctrine.php
From:
require APPPATH.'libraries/Doctrine/Common/ClassLoader.php';
To:
require_once APPPATH.'libraries/Doctrine/Common/ClassLoader.php';
Made all the difference.

PHPUnit CodeIgniter Generate Fixtures PHP Fatal error: Class 'PHPUnit_Framework_TestCase' not found

So have PHPUnit and CodeIgniter installed:
http://d.hatena.ne.jp/Kenji_s/20120117/1326763908
Couldn't download the PEAR as its been deprecated. So had to download the phpunit phar file:
http://phpunit.de/manual/4.0/en/installation.html#installation.phar
So was able to get some tests to run properly. Moved my phpunit.phar to /usr/local/bin and ran on the tests dir:
php /usr/local/bin/phpunit.phar
And all the tests ran correctly. But when i tried to run the php generate fixtures and php generate.php fixtures:
PHP Fatal error: Class 'PHPUnit_Framework_TestCase' not found in /www/test/application/third_party/CIUnit/libraries/CIUnitTestCase.php on line 15
Fatal error: Class 'PHPUnit_Framework_TestCase' not found in /www/test/application/third_party/CIUnit/libraries/CIUnitTestCase.php on line 15
Seems like its not finding the classes inside the phar file or at least they are not in the correct order? What is funny is that it runs the tests fine but not the generate fixtures.
Additionally i also installed using composer the phpunit so i have a /www/test/vendor/bin/phpunit installed as well.
Any help would be appreciated.
I had the same problem in my code, although I do not use the CodeIgniter. Trying to run tests would result in the error message:
Class 'PHPUnit_Framework_TestCase' not found
For what it's worth I had this fixed by adding a backslash to my test class declaration.
// Before
namespace IMAVendor\Super\Duper;
class MyClassTest extends PHPUnit_Framework_TestCase
// After
namespace IMAVendor\Super\Duper;
class MyClassTest extends \PHPUnit_Framework_TestCase
^
Added this backslash here
This seems to have something to do with namespaces and the autoloader that's built in phpunit. I have my own autoloader for the project code and it seems that it was trying to load the phpunit's classes from my code. I'm not really sure why it didn't try to load it from the 'base' when it wasn't able to find it in the projects namespace (This may very well be due to my own autoloader being faulty).
I know this is an old question, but I'll just leave this here in case it may help somebody somewhere.

CakePHP v1.3: Full Code Coverage Report

In CakePHP v2.x, you can generate a unit testing code coverage report from the command line using a test suite that fires all of your app's tests and the --coverage-html option. (Example: cake test app All --coverage-html=tmp/coverage/)
I've been searching for an equivalent for Cake v1.3, which uses SimpleTest. When testing via the browser, it's possible to view code coverage for each individual test case, but not for the whole App category.
Similarly, running tests from the command line via cake testsuite app all does not seem capable of taking any command-line options for generating coverage output. The v1.3 Book doesn't dive into any more detail on the subject.
So my question is: Is there a way to generate a "full" code coverage report for a Cake v1.3 application from the command line?
Additional Information for future searchers:
Per #mark-story's suggestion, I tried running cake testsuite app all cov, but that produces the following fatal error for me:
PHP Fatal error: Class 'CodeCoverageManager' not found in
cake/tests/lib/reporter/cake_base_reporter.php on line 131
This is with SimpleTest v1.0.1 in my app/vendors/simpletest/ folder. I tried upgrading to SimpleTest v1.1.0, but that resulted in a different fatal error:
PHP Fatal error: Call to undefined method CakeCliReporter::SimpleReporter() in
cake/tests/lib/reporter/cake_base_reporter.php on line 85
You might want to try addin 'cov' to the end of the cli runner arguments. The help() command indicates this will work. It has been a whilre, but I think this will output the % of code covered. There is no way to generate a detailed set of coverage reports like you can with phpunit.

Guzzle annotations not working with Doctrine2 annotation parser in Symfony2 project

I've got a Symfony2 project and am trying to integrate the GuzzleBundle to build a web service client. I'm using the #guzzle annotations for the client commands (which extend Guzzle\Service\Command\AbstractCommand).
It seems to work correctly in the dev environment but when I try to load pages using the prod environment I get a Doctrine AnnotationException:
PHP Fatal error: Uncaught exception 'Doctrine\Common\Annotations\AnnotationException' with message '[Semantical Error] The annotation "#guzzle" in class Admin\FindAnExpertBundle\Entity\SymplecticClient\Rest\Command\UserById was never imported. Did you maybe forget to add a "use" statement for this annotation?'
I also get an error about a missing Proxy class file:
PHP Warning: require(/home/httpd/sites/experts.admin/app/cache/prod/doctrine/orm/Proxies/AdminFindAnExpertBundleEntityRelationshipTypeProxy.php) [<a href='function.require'>function.require</a>]: failed to open stream: No such file or directory in /home/httpd/sites/experts.admin/vendor/doctrine/lib/Doctrine/ORM/Proxy/ProxyFactory.php
I assume this is because the fatal error is stopping all the proxy classes from being created.
Guzzle appears not to use the Doctrine annotation parser so I'm wondering if there's a way to make it ignore #guzzle annotations or register them somehow?
You have to import the annotation-Parser of Guzzle, which handles the "#guzzle" annotation, e.g.:
use Guzzle\Service\Inspector as guzzle;
But i don't know which class it is.
Maybe this gist file helps you.
I ended up moving the classes relating to the web service client out of the Entity folder, which stopped the Doctrine annotation parser from reading them. In retrospect, the classes shouldn't have been in that folder anyway.

Categories