Entries tagged as php
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
Tja, schon Dienstag und ich bin mittlerweile 40h wieder in der Heimat, trotzdem ein kurzes Review.
Samstag morgen um kurz vor 10 kamen wir als Pulk von 10 Münchnern im Hamburger Geomatikum an, nicht ohne meine fassungslose Feststellung, dass man sich auch verlaufen kann, wenn 6 Leute auf 6 iPhones 6 mal Google Maps studieren.
Dann gings gleich los mit dem Begrüßen alter Bekannter (aus dem IRC, von Konferenzen und sonstigen Events) und... Frühstück! Dazu erstmal ein riesiges Lob, das Essen war 1a und auch reichlich vorhanden, dazu noch von einem grandiosen Team serviert.
Weiter gings mit der Planung/Abstimmung der Sessions, das hätte man irgendwie straffen sollen, ich weiss nur nicht wie. Dann folgten 4 Sessions mit viel Palaver dazwischen, bei mir Softwaremetriken, PHP Performance Un-Tuning, Enterprise PHP und Zukunft der QA in PHP. Enterprise war mir etwas zu allgemein, auf jeden Fall aber besser als die letztjährige Version, die sich auf ein PHP-Bashing vs. Java-Bashing herunterbrechen liess und die Zukunft der QA war mehr die Gegenwart der QA, aber trotzdem ein guter Überblick.
Samstag abend haben wir uns dann vom Mob ferngehalten, mir persönlich war der Gedanke an 180 Leute am selben Ort sowieso etwas suspekt. Also beim abends weggehen. Wir haben einen ausgedehnten Spaziergang von ca. 80min auf dem Weg zu einem geschätzt 10min entfernten Restaurant gemacht, wenigstens was von Hamburg gesehen, und dann weitergezogen.
Dann kam auch schon der Sonntagmorgen, wieder etwas lascher Beginn mit Abstimmung, die irgendwie unnötig lange dauerte, dann Zukunft der QA, zweiter Teil, gefolgt von MySQL Performance (schon das zweite Mal, dass ich den Talk von Kris höre, aber diesmal doch 90% anders als damals). Danach gabs MySQL und HA und noch PHPDocumentor.
Insgesamt hatte ich von einigen Talks mehr versprochen, aber wahrscheinlich könnte man eh nicht viel mehr behalten, und der Hauptaspekt, das Wecken von Interesse bzw. der Anreiz, tiefer in die Materie einzusteigen, wird erfüllt. Werde mir die Slides nochmal zu Gemüte führen, aber insgesamt waren die Sachen doch fast bzw. genau auf Konferenz-Niveau. Also bleibt schon ein Lob für die Speaker :)
Nach erneutem Umherziehen und dem Abfinden mit der Tatsache, dass man Sonntag, 18 Uhr in Hamburg kein Bier
bekommt sind wir dann eben doch zum Flughafen (weil mein Arbeitgeber Anreise und Übernachtung übernommen hat, dafür herzlichen Dank). Da gabs wenigstens Weißbier, wenn auch nur Schöfferhofer.
Zusammengefasst meine (kleinen) Kritikpunkte:
· Leute mit Talks sollten sich vorbereiten oder es als "Diskussionsrunde" ankündigen
· Ich hätte gerne 30- und 60-min-Slots, soll halt jeder selber entscheiden, ob er mehr oder weniger lang reden kann/danach noch Diskussion will, normal ist das abzusehen
· paar mehr Getränke - war aber nicht schlimm, hab beide Tage bis ~15:00 noch was erwischt
Bleibt dann nur ein Dank an alle Beteiligten, das ausgezeichnete Orga-Team und die Sponsoren.
Wir sehen uns nächstes Jahr :)
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
Auch wenn ich S9Y die Treue halte, auch andere Mütter haben schöne Töchter und so bin ich ja immer am rumsuchen nach "Konkurrenten".
Das wird dann installiert, getestet, Doku gelesen, Code angeschaut, Templates verglichen, wieder deinstalliert.
Was ich nicht schon alles angeschaut hab... Die "großen", also Wordpress und Textpattern sogar alle paar Versionen mal wieder, vor allem, wenn man sie auch als Mini-CMS missbrauchen kann (so wie Serendipity auch).
Interessante Entdeckungen der letzten Zeit:
Das wird dann installiert, getestet, Doku gelesen, Code angeschaut, Templates verglichen, wieder deinstalliert.
Was ich nicht schon alles angeschaut hab... Die "großen", also Wordpress und Textpattern sogar alle paar Versionen mal wieder, vor allem, wenn man sie auch als Mini-CMS missbrauchen kann (so wie Serendipity auch).
Interessante Entdeckungen der letzten Zeit:
- localblog - a python script which intends to provide the user a simple solution to maintain an online diary
- NanoBlogger - a small weblog engine written in Bash for the command line (via
- Web Content Viewer - tolle Idee, aber sehr krank umgesetzt - ziemlich overengineered, wie ich finde, aber trotzdem interessant. Und hat ein Blog-Modul.
- Fefes Blog, "Proudly made without PHP, Java, Perl, MySQL and Postgres" und "Blogsoftware in C gehackt". Inhalt ist König, aber gleich html, head und body weglassen? Wie das Ding genau arbeitet, würde mich trotzdem brennend interessieren.
- DokuWiki ist zwar toll, aber als Blog-Engine? Mhm, gefällt mir nicht so recht.
- gitology - ähnlich WCV, aber in python und git statt PHP und SVN
When I see one more whining post about Google using python for App Engine instead of php, I'm going to advocate LISP or Turbo Pascal for it, ffs.
(Page 1 of 2, totaling 6 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
10. March 2010, 23:33


