July 7th, 2010
Having some issues with a mock in PHPUnit - the method on the mocked object was being called and the code run (bootstrap method on Zend_Application_Bootstrap_BootstrapAbstract). After some head scratching, I realized it was a final method, so PHPUnit can’t override it, and thus, the code is executed. I extended Zend_Application_Bootstrap_BootstrapAbstract and overwrote the code that was cuasing problems (::bootstrap is final, but it calls ::_bootstrap, which you can override).
I ‘ve been meaning to play around with Mockery, but until then, I’ve come up with some ways to deal with Mocks in PHPUnit (I personally don’t think the implementation is too bad, but I’m not a die hard tester…). One of the issues I commonly run into is needing to return mocked objects from a mocked method. This is easy if the method is only called once, but what about if the same method is called a couple of times, and you need to return different mocks (e.g. ::bootstrap($name) will return different objects based on the $name parameter)?
I’ve used a closure with a callbackValue to get around this:
<?php
$mapper = $this->getMock(‘Bolton_MapperInterface’);
$relatedMapper = $this->getMock(‘Bolton_MapperInterface’);
$callback = function($property) use($mapper, $relatedMapper) {
if ($property == ‘model’) {
return $mapper;
} else if ($property == ‘childModel’) {
return $relatedMapper;
}
throw new Exception(sprintf(‘Mapper factory mock passed an unexpected parameter (%s)’,$property));
};
$this->_mapperFactory->expects($this->any())->method(‘factory’)->will($this->returnCallback($callback));
?>
What about needing to return a different value based on the number of times the method has been called? I’ll use a callback function, but then have a static variable in the callback function that keeps track of how many times it has been called. In the test setUp() method, I will reset the static variable, so the function can be used across a number of different tests.
Posted in Zend Framework | No Comments »
May 5th, 2010
Google added a new way to verify your site in their Webmaster Tools: through a DNS TXT entry. It took me a couple of tries to figure out how to properly enter it through Slicehost’s DNS GUI:
- Type: TXT
- Name: Enter the
FQD name domain that you put in Google Webmaster Tools I.e. for this site, I would use www.robertbolton.com or robertbolton.com, depending on what I entered into Webmaster Tools.
- Data: Enter the value provided by Google (i.e. google-site-verification: waRANDbRgWxXfEBMKhl8c1v8fL1kcVvRtPFU-OmN9I1)
To see if it worked, you can use the command line “host -t txt robertbolton.com” and a result should come back. Or just cross your fingers and click the verify button in Google…
Posted in Google Analytics | 5 Comments »
January 8th, 2010
I received a new monitor for xmas and wanted to set up dual display (twinview) for Ubuntu 9.10. I already had the proprietary Nvidia drivers install, and it was very easy to get the dual monitors up and running. However, I always got this error when trying to save the configuration: Can’t parse /etc/X11/xorg.conf. And upon restarting, only one screen would show and I would have to set it up again.
Even when I launched Nvidia with sudo (sudo nvidia-settings), I still got this error on the command line:
VALIDATION ERROR: Data incomplete in file /etc/X11/xorg.conf.
Undefined Device “(null)” referenced by Screen “Default Screen”.
I moved /etc/X11/xorg.conf to a new filename, ran sudo nvidia-settings and was able to save as new xorg.conf file and now I have both monitors on start up. Also looks like you can simply edit the existing xorg.conf file and you will be able to save your settings.
Posted in Uncategorized, Ubuntu | No Comments »
December 18th, 2009
It seems like every time I upgrade Kubuntu, my sound doesn’t work anymore. I guess “doesn’t work” isn’t the right term. It seems that the output is muted. If I type pavucontrol into the command line and then go to output devices on the volume control window that pops up, the Internal Audio Analog Stereo is muted. I don’t know why the pulse audio volume control is defaulting to that setting every time I upgrade, but I fiddled around with my sound settings a couple of years ago when I was having issues and that’s likely the culprit. I think I need to do a fresh install one of these days….
Posted in Uncategorized, Ubuntu | No Comments »
December 13th, 2009
The Zend_Auth Db adapter will fail if you have more than one record returned, which makes sense. However, when I have coded something like this in the past, I would check how many records were returned with a matching username and password. Zend_Auth looks at how many records are returned for the username field regardless of whether the password matches, so you need to have a unique username field. I was trying to use a person’s last name and password to authenticate, but obviously people had the same last name, so it was failling.
Posted in Zend Framework | 3 Comments »