I have narrowed my problem down to a single unit-test which involves a pretty clean dbal query. The query involves a nestedsets and the failure occurs when I go from 3 to 4 levels of hierarchical categories. Very little changes in terms of execution time.. And the functionality I'm work with has no problem at 10 level. However, in PhpUnit when I run the test with 4 or more levels -- I get a fatal error.
*To summarize, a query that may take a split second more than usual OR a tab bit more resources is getting me a php fatal error in PHPUnit *
And the Error Looks like this:
Fatal error: Call to undefined method Monolog\Formatter\LineFormatter::stopEvent() in /var/www/my-app/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Debug/Stopwatch.php on line 92
Someone here had a phpUnit fatal error problem on line 92 as well. Could it be related??
I've listed some quirky ways (below) to bypass my problem but I'd still like to know why such a basic test seems to be causing this problem.
Run PhpUnit with processIsolation set to "true".
Don't access the static::createClient(); in the setUpBeforeClass() method
I've had a respected member of #symfony (Stof) suggest that it looks like I'm improperly DI'ing #logger into a service.. but I've confirmed this doesn't seem to be the by taking the logger service out of any of my services.
Maybe this issue has something to do with a timeout? (The error mentions stopevent and stopwatch). Or maybe this error has something to do with accessing $client = static::createClient(); in setUpBeforeClass().. and then accessing is again in preceding tests.. Regardless.. it's confusing me and as far as I can tell, everything else in my Symfony2 (2.1.1) installation is working perfectly fine.
* LINE 92 of Stopwatch.php .. github source file here *
/**
* Stops an event.
* #param string $name The event name
* #return StopwatchEvent A StopwatchEvent instance
*/
public function stop($name)
{ return end($this->activeSections)->stopEvent($name);}
OK. So you grab the last item from the $this->activeSections array and they try to run the stopEvent() method on it. It would seem in this case that the LineFormatter class does not have that method available to it.
I am not familiar with Monolog, but in a brief glance at their latest GitHUb repo, I can see that neither the LineFormatter or NormalizerFormatter class which it inherits from have such a method.
It seems like Monolog is not playing nice with Symfony. And that without modifying Monolog and/or the Symfony Stopwatch class, you will not be able to use Stopwatch to profile your Monolog-related code.
Related
I'm having an issue with php unit on hhvm where getmock() failing on phpunit 4.8.27 for a class with the following message
Fatal error: Call to undefined method PHPUnit_Framework_MockObject_InvocationMocker::getTableColumns() in /joomla-cms/libraries/joomla/table/table.php on line 241
Test Code failing is located at https://github.com/photodude/joomla-cms/blob/patch-1/tests/unit/suites/libraries/cms/installer/JInstallerAdapterTest.php#L111
for the test code this "fails/errors" the test with no Fatal error
$mockTableExtension = $this->getMock('JTableExtension', array('find', 'load'), array($this->getMockDatabase()));
but if I use the stored value
$mockDatabase = $this->getMockDatabase();
and type cast the mockDatabase object to array I get the Fatal error listed above.
$mockTableExtension = $this->getMock('JTableExtension', array('find', 'load'), (array) $mockDatabase);
Travis test with the mockDatabase object and object type cast to array var_dumped https://travis-ci.org/photodude/joomla-cms/jobs/172201634#L1427-L2178
Everything passes and works just fine in php, the issue is specific to testing on hhvm
Am I doing something wrong in the mock setup? or is there something else going on?
note: I recently tested this portion of the test suit on php unit 5.6 and got the same issue. So I'm not sure what we've don't wrong in the setup of these tests.
I found there is some issue with array($this->getMockDatabase()) in one of the tests on hhvm. Replacing array($this->getMockDatabase()) with array(self::$driver) all of the issues were resolved.
I also replaced the direct use of getMock with the getMockBuilder (for compatibility with phpunit 5.6)
Every time I attempt to use one of the basic PHPUnit Selenium assertions, the tests errors out and displays this message:
Exception: You cannot call a command with multiple method arguments.
On http://phpunit.de/manual/3.7/en/selenium.html, it shows the usage to be:
void assertElementValueEquals(string $locator, string $text)
Be when I call it with
$this->assertElementValueEquals( 'id=date_1_formatted', '2013-01-01' );
the test produces the above error every time even though this same format seems to be working for others such as in the question Using PHPUnit with Selenium, how can I test that an element contains exactly something?
assertElementValueEquals is not implemented in Selenium2TestCase. On your link it mentioned for SeleniumTestCase (Selenium RC version).
Moreover, you used correct structure with $this->byXPath like here https://github.com/sebastianbergmann/phpunit-selenium/blob/master/Tests/Selenium2TestCaseTest.php
Also you can use $this->byId():
$element = $this->byId('date_1_formatted');
$this->assertEquals('2013-01-01', $element->value());
P. S.: If you are familiar with Selenium IDE, you can try this command line tool.
Walked into this one too, in my case it was my own custom method, so I thought it was a line off.
Turns out I was using a different "buffer" class between the test class and the phpunit than I thought. But because it uses __call() a Lot, it gave ↑ that error instead of "undefined method".
I am creating a Symfony2 application, all works well, but when i try to execute my behat tests or clear the cache, i got this error:
Error: Call to undefined method
Symfony\Bundle\FrameworkBundle\Templating\Loader\TemplateLocator::isFresh() in
[...]/vendor/symfony/assetic-
bundle/Symfony/Bundle/AsseticBundle/Factory/Resource/FileResource.php line 49
TemplateLocator does not even implements LoaderInterface, as required in FileResource construct.
Anyone has a clue ?
I figured out where the problem came from, but without understanding it.
It appeared that somewhere in my application I called
$this->container->get('twig')->render("Bundle:View:action.html.twig")
I changed to
$this->container->get('templating')->render("Bundle:View:action.html.twig")
twig service is a Twig_Environment instance, and template is a DelegatingEngine instance, both allowing to render a template.
And all works great again.
If someone could explain me what happened, I'll appreciate :)
I am creating my own custom module in Magento and during testing on a Litespeed server (PHP v5.2.14) I am getting a Fatal Error: Call to a member function batch() on a non-object in ../../../BatchController.php on line 25 that was not appearing during testing on another linux server and a wamp server (PHP v5.2.11).
This one has stumped me. I am guessing it has something to do with the server configuration rather than the code itself. But i am just guessing. I was hoping someone here could tell me.
The only real major difference I could see, aside from the php versions and environment, is that the server that the error is on is using the Suhosin Patch. But would that be something that could cause this?
The line in question is Mage::getModel('mymodule/mymodel')->batch(); which is enclosed in an IF statement. batch() is a public function located in my model file.
If you need more code let me know.
Thanks!
If you get a "non-object" error when calling a model, there's a problem with Magento's attempt to get your model class, and it is returning null. The reasons for this are not always apparent. If this worked identically on a normal LAMP stack, then the problem is most likely not in your code.
My first guess would be that the file does not have the proper permissions. Otherwise, it may have to do with resolving the classname. You could test this temporarily by calling the plugin directly like this:
$obj = new Mynamespace_Mymodule_Model_Mymodel();
$obj->batch();
If this works, then the file is readable, and you will want to go spelunking in the resolution of that classname. If it doesn't work, you have a problem with either autoloading or the declaration of your class.
Hope that helps!
Thanks,
Joe
Break it down.
You've tried to call
Mage::getModel('mymodule/mymodel')->batch();
and PHP told you it tried to call the method batch on a non-object. That means
Mage::getModel('mymodule/mymodel')
isn't returning a Model object the way it's supposed to.
First thing to do is clear out your Magento cache on the server you're having problems with. If your Module's config hasn't been loaded into the global config tree Magento will try to instantiate a Mage_Core_Model_Mymodel, and fail.
Second step is to make sure your module's app/etc/module file is in place.
Third step is to add some debugging (assuming a 1.4 branch) to the method that instantiates your objects and determine why Magento can't create your object
File: app/code/core/Mage/Core/Model/Config.php
...
public function getModelInstance($modelClass='', $constructArguments=array())
{
$className = $this->getModelClassName($modelClass);
if (class_exists($className)) {
Varien_Profiler::start('CORE::create_object_of::'.$className);
$obj = new $className($constructArguments);
Varien_Profiler::stop('CORE::create_object_of::'.$className);
return $obj;
} else {
#throw Mage::exception('Mage_Core', Mage::helper('core')->__('Model class does not exist: %s.', $modelClass));
return false;
}
}
...
I am trying to make a service call to a php function from flex, through Zend AMF. Most of the functions get called fine, but for one particular function, it throws the following exception:
InvocationTargetException:There was an
error while invoking the operation.
Check your operation inputs or server
code and try invoking the operation
again.
Reason: Fatal error: Call to a member
function getInvokeArguments() on a
non-object in
D:\wamp\www\ZendFramework\library\Zend\Amf\Server.php
on line 328
I am not able to debug through this - has anyone faced any issue like this before, or have any ideas how this can be debugged?
At a quick glance through ZFW's source, this appears to be a bug on their framework.
// There is no check if $this->_table[$qualifiedName] is an object, implements an interface, extends a class, only if it's set (the key exists).
$info = $this->_table[$qualifiedName];
$argv = $info->getInvokeArguments(); // Here's when you get the error.
Source: http://framework.zend.com/code/filedetails.php?repname=Zend+Framework&path=/trunk/library/Zend/Amf/Server.php
I looked in their bug tracker and haven't found anything related to this, perhaps you should open a new issue?
Additionally, you can debug the problem by grabbing the message that Flex is sending to the PHP client and making a test case out of it.
We finally realized that this was a problem in the flex project setup - don't know exactly what it was, but once we deleted and created the project again, things started working fine!