I recently ran into a problem that stopped me from having 100% test coverage on a file.
This is the piece of code, the overall reasoning for it can be found on the microtime manual page:
In case you did not spot it, the else path is never accessed if your system has a "microtime" function available. Additionally the change can be non-trivial because time() returns something like 1012314124 and microtime() returns "0.80057400 1257872321" or "1257872326.3036".
My first idea was something like this in the test case:
Then the idea was to use variable functions, but in the end I think it's not worth to change the source code to something less intelligable only to achieve 100% test coverage for a trivial case.
Of course you could always invoke a CLI php with a special php.ini if you have bigger chunks of code to be tested depending on the availability of certain functions.
Another idea could be to create a wrapper for microtime that you can mock and in your mock object always return the output of time() instead of microtime(), this would probably be the best tradeoff between readability and testability.
Any ideas?
This is the piece of code, the overall reasoning for it can be found on the microtime manual page:
This function is only available on operating systems that support the gettimeofday() system call.
In case you did not spot it, the else path is never accessed if your system has a "microtime" function available. Additionally the change can be non-trivial because time() returns something like 1012314124 and microtime() returns "0.80057400 1257872321" or "1257872326.3036".
My first idea was something like this in the test case:
Then the idea was to use variable functions, but in the end I think it's not worth to change the source code to something less intelligable only to achieve 100% test coverage for a trivial case.
Of course you could always invoke a CLI php with a special php.ini if you have bigger chunks of code to be tested depending on the availability of certain functions.
Another idea could be to create a wrapper for microtime that you can mock and in your mock object always return the output of time() instead of microtime(), this would probably be the best tradeoff between readability and testability.
Any ideas?
Posted by fa
in PHP
| Comments (11)
| Trackbacks (0)
Defined tags for this entry: code coverage, php
Yes, it's the new hype - URL shorteners (mostly for use in Twitter).
Some use the classic tinyurl, then there's is.gd and bit.ly and a fair bunch of others.
As some people already wrote, and I feel no different here, broken links are baaad, mkay?
So the easiest way would be to get a short domain for yourself and run your own url shortener.
I am happy enough to have secured myself a not yet publicly announced 3-char .de domain which I'm planning to use for that. This and being bored for 2h led me to roll out my own shortening service.
Enter Shortcore - 259 lines of php code, working already.
It needs PHP 5.2.0+ (I think :P) and sqlite and I've put it up on github - it's BSD licenced and comments and patches are very much appreciated.
How to use it when it's installed:
Some use the classic tinyurl, then there's is.gd and bit.ly and a fair bunch of others.
As some people already wrote, and I feel no different here, broken links are baaad, mkay?
So the easiest way would be to get a short domain for yourself and run your own url shortener.
I am happy enough to have secured myself a not yet publicly announced 3-char .de domain which I'm planning to use for that. This and being bored for 2h led me to roll out my own shortening service.
Enter Shortcore - 259 lines of php code, working already.
It needs PHP 5.2.0+ (I think :P) and sqlite and I've put it up on github - it's BSD licenced and comments and patches are very much appreciated.
How to use it when it's installed:
- http://example.org/_[uniqueid] redirects to what you saved.
- http://example.org/_[uniqueid]_ shows a preview
- So I have "xxx.de/_ab" - as low as 10 chars for an url (excluding http://), that's not less than a bit.ly url (currently at 5+ chars after the /) and I can still put normal content (not starting with a "_") on the domain - fair deal I think
- there's a bookmarklet for easy saving, either provide the [uniqueid] or let it be generated automatically
- it's not meant as a public shortening service, so probably some basic auth has to be added
You might skip this entry if you don't speak German - but you're still welcome to help translate the PHP manual to *your* language :) news.php.net shows you the documentation mailinglists as php.doc.*
Sammy posted a little reminder (and an addendum) for the German PHP documentation team, how to update your outdated files, so at least the technical barrier won't be a reason.
If you did some translation work in the past you're very welcome to join again and if you didn't, feel free to give it a try, it's really not hard and there's always a lot of stuff to do.
Sammy posted a little reminder (and an addendum) for the German PHP documentation team, how to update your outdated files, so at least the technical barrier won't be a reason.
If you did some translation work in the past you're very welcome to join again and if you didn't, feel free to give it a try, it's really not hard and there's always a lot of stuff to do.
Back when installing ZendStudio 5.5.0 on Ubuntu I sometimes had the following error:
This is because the \u variable of bash (username in the prompt) is mistaken for an (illegal) \uXXXX unicode character.
After searching back then I found out (and back then it wasn't #1 hit on a google search) that you just have to temporarily alter your .bashrc:
then start the installer and after you're finished, removed the last line and source it again.
For another problem, see that posting.
An internal LaunchAnywhere application error has occured and this application cannot proceed. (LAX)
Stack Trace:
java.lang.IllegalArgumentException: Malformed \uxxxx encoding.
at java.util.Properties.loadConvert(Unknown Source)
at java.util.Properties.load(Unknown Source)
at com.zerog.common.java.util.PropertiesUtil.loadProperties(DashoA8113)
at com.zerog.lax.LAX.(DashoA8113)
at com.zerog.lax.LAX.main(DashoA8113)
This is because the \u variable of bash (username in the prompt) is mistaken for an (illegal) \uXXXX unicode character.
After searching back then I found out (and back then it wasn't #1 hit on a google search) that you just have to temporarily alter your .bashrc:
(fa@don):(~) $ echo 'export PS1="# "' >> .bashrc
(fa@don):(~) $ source ~/.bashrc
then start the installer and after you're finished, removed the last line and source it again.
For another problem, see that posting.
Back from the PHP Unconference 2008 in Hamburg, so here's a little review. I arrived a little early so I didn't have to queue up for my checkin, but that problem was also solved soon for the rest. The voting for the suggested talks took a while, so we didn't start before lunch as planned, but at least that gave some time to meet and greet. After lunch I listened to one of Kris' excellent talk about MySQL Performance Tuning of which I'm sure he could've talked 3h more and it still wouldn't have been boring and then Secure PHP installations by Johann-Peter Hartmann which also had some stuff I hadn't thought of and from my impression some folks also had some a-ha experience.
In the evening we had some beers (or what they call beer in Hamburg) and excellent Chili Con Carne in the Recycel Bar. This went along with more chatting about the talks, own projects and PHP in general.
The second day started with Judith Andresen's talk about Intranets where we tried to get to a common understanding what we developers and customers especially think when they want to 'improve the intranet'. This led to some discussion which is summed up on the conference page (in German). After that I listened to Manuel Pichler and Sebastian Bergmann who talked about Continuous Integretion with phpUnderControl which was a good introduction to phpUnderControl for me, but I was missing details on the topic in general because I've done my share of work in this field lately - so not much new.
After that I attended PHP is not Java, a panel discussion lead by Gaylord Aulke, Johann-Peter Hartmann, Lars Strojny and Stefan Priebsch, that involved more into a discussion with the whole audience, but I think that sparked some even more interesting thoughts. Finally I went to Kore Nordmann who talked about Regular Expressions with the help of Thomas Weinert (who seems to have been bugged about the stalled progress of Weaverslave all the time :P). The talk was more introductory level, but also had some hints towards not-so-well-known features and even recursions and some theory with the proof via Pumping Lemma. Not much new to me, but very interesting nevertheless.
And so it ended and after a little sightseeing tour of Hamburg by Markus Wolff, who originally just planned to take us along to the central station.
To sum it up it was a very nice weekend, not only for the talks but especially for the discussions started in the talks and to meet some people I've known from online talk for years in person finally. Big Thank You! to all the people involved, the orga team for a near perfect event, Reinhard for WLAN access, the sponsoring of the yummy food and all the people I've had some nice chat with.
In the evening we had some beers (or what they call beer in Hamburg) and excellent Chili Con Carne in the Recycel Bar. This went along with more chatting about the talks, own projects and PHP in general.
The second day started with Judith Andresen's talk about Intranets where we tried to get to a common understanding what we developers and customers especially think when they want to 'improve the intranet'. This led to some discussion which is summed up on the conference page (in German). After that I listened to Manuel Pichler and Sebastian Bergmann who talked about Continuous Integretion with phpUnderControl which was a good introduction to phpUnderControl for me, but I was missing details on the topic in general because I've done my share of work in this field lately - so not much new.
After that I attended PHP is not Java, a panel discussion lead by Gaylord Aulke, Johann-Peter Hartmann, Lars Strojny and Stefan Priebsch, that involved more into a discussion with the whole audience, but I think that sparked some even more interesting thoughts. Finally I went to Kore Nordmann who talked about Regular Expressions with the help of Thomas Weinert (who seems to have been bugged about the stalled progress of Weaverslave all the time :P). The talk was more introductory level, but also had some hints towards not-so-well-known features and even recursions and some theory with the proof via Pumping Lemma. Not much new to me, but very interesting nevertheless.
And so it ended and after a little sightseeing tour of Hamburg by Markus Wolff, who originally just planned to take us along to the central station.
To sum it up it was a very nice weekend, not only for the talks but especially for the discussions started in the talks and to meet some people I've known from online talk for years in person finally. Big Thank You! to all the people involved, the orga team for a near perfect event, Reinhard for WLAN access, the sponsoring of the yummy food and all the people I've had some nice chat with.
Posted by fa
in PHP
| Comments (0)
| Trackbacks (0)
Defined tags for this entry: phpunconference2008
(Page 1 of 3, totaling 15 entries)
next page »
Layout by Ricky Wilson | Serendipity Template by Carl Galloway | Login
About
Life's a bitch, life's a whore. Nothing less, nothing more.
Read More
Der Autor...
... studiert Informatik. Und zwar an der LMU München. Das mittlerweile schon eine ganze Weile. Nebenher arbeitet er als PHP-Entwickler und Admin. Seit geraumer Zeit sogar regelmäßig und in Farbe
Quicksearch
last.fm
Song: Weather Experience (Top Buzz remix)
Artist: The Prodigy
14. June 2009, 19:23
Song: Charly (Trip Into Drum and Bass version)
Artist: The Prodigy
14. June 2009, 19:17
Song: Wind It Up (Rewound)
Artist: The Prodigy
14. June 2009, 19:11
11. March 2010, 16:49


