“Mutation Testing is basically testing…for tests. It ensures that your tests are truly capable of detecting errors and problems with the source code. It does this by mutating the source code itself (using ext/runkit) in such a way that an error is created in the code. If your tests detect the error, all is well with the world. If your tests do not detect the error…well, you better add a new test that does”
“phpcpd is a Copy/Paste Detector (CPD) for PHP code.
The goal of phpcpd is not not to replace more sophisticated tools such as phpcs, pdepend, or phpmd, but rather to provide an alternative to them when you just need to get a quick overview of duplicated code in a project.”
An example will explain better (applies to the php package):
class simplemath
{
/**
* subtract function.
*
* @access public
* @param int $a
* @param int $b
* @return int
*
* <code>
* //doctest: subtract
* echo simplemath::subtract(10,6);
* //expects:
* //4
* </code>
*/
public static function subtract($a, $b)
{
return (int)$a - (int)$b;
}
}
The test itself is inside the <code> tags. If I then run this code through doctest’s commandline runner for php, by running
$ phpdt simplemath.php
I’ll get something like this:
Doctests can serve as great documentation by example and as tests, both for your documentation - comments tend to get terribly out of date (when code changes the comments aren’t updated accordingly) - and for the code itself.
I’ve also found they’re an invaluable tool during development. Imagine you’re developing a method that validates credit card numbers and the only way to get to it in a browser is to perform several actions, eg going to the specific webpage, inputting the credit card number, and submitting the form - it’s hell basically. If you’re already doing TDD and using phpUnit you’re probably not doing this but doctest for me has an advantage there, the test and the code being tested are in the same file - it’s all there! and so it’s really easy to grasp the problem at hand.
My process has been,
write a test case in doctest
write the code itself
test
repeat as necessary
Due to this I submitted a patch to allow the testing of only 1 test, it’s not in the current release but it’s been accepted. This way instead of waiting for all the tests to run, i can run only the method I’m working on.
Another cool thing about it is you become aware of any initial setup code and dependencies. Look at the following:
/**
* Calculates the number of nights between the start and end date of the booking
* @return int
*
* <code>
* // doctest: booker->total_nights
* require_once('lib/utilities.class.php');
* $booker = new booker();
* $booker->startDate = '2009-02-23';
* $booker->endDate = '2009-02-26';
* echo $booker->total_nights(). "\n";
* // expects:
* // 3
* </code>
*
*/
public function total_nights()
{
if (!isset($this->startDate) || !isset($this->endDate)) {
return false;
}
return (int)utilities::date_diff($this->startDate,$this->endDate,'d');
}
Even without the rest of the class it’s immediately visible that this method requires that the start and end dates be set and the inclusion of another class.
I think doctests are a really easy way to start writing tests. If you’re like me and also use phpUnit, it’s easy to write an AllTests file that runs both the doctest tests and the phpunit tests.
I view doctest as unitestting in its simplest form, there’s no setup/teardown methods, no mocks, etc. But since not all classes need all that, that’s fine by me. You can use doctest and phpunit/simpletest side by side. This way you have tests for code and tests for documentation
You can also use YSlow + Firebug but I ran into a strange problem where YSlow did not detect the compressed content (gave an F on gzip components) when I knew I was actually compressing content. I then looked around for other tools and found those 2 which detected the compression correctly. So lesson learned, use several tools to validate compression - just to make sure.
Share and Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
Copy xdebug.so (choose the correct xdebug according to your php version) to xampp/xamppfiles/lib/php/php5/extensions/no-debug-non-zts-########/xdebug.so .
Configure php.ini:
At the end of php.ini (it’s in xampp/etc/php.ini) add
The “xdebug.profiler_output_name=”%p-%R”" sets the file name to process pid (default) + “-” + the REQUEST URI (helpful if you’re rewriting urls). The xdebug.dump commands are not for profiling but they improve var_dump & error messages. Check zend’s article series on xdebug for more info.
Run php info & check xdebug’s there.
If you get ‘could not load.. (null)’ you probably downloaded the wrong version for your mac. Also check the path to xdebug is correct (the no-debug-non-zts-####### part might be different)
Install webgrind: download from here and copy directory to xampp/xamppfiles/htdocs folder
Visit your script with ?XDEBUG_PROFILE=1 appended to the end of the url. Eg http://localhost/myapp/index.php?XDEBUG_PROFILE=1
Now navigate to webgrind (eg. http://localhost/webgrind/ ), select the correct file from the dropdown - you can see the files xdebug’s created in yout /tmp directory - and you should see the profiling info.
Since i’ve got my ipod touch, i’ve been trying out several applications. Some have sticked, others less. So here’s my current favorite list along with a few comments.
Stanza provides the best reading experience of all the ereaders i’ve tried (stanza, filemagnet, instapaper, ereader) . A feature suggestion: I really would like the ability to add notes on any page or at least to underline/highlight text. Highlighting would really be nice - it just makes the reading experience much better. Basically the physical action of highlighting makes it easier for me to process the information and remember it later.
A note on page turning: Stanza is the only app where you press the left/right side of the screen to go to the previous/next page which would be fine if everyone else was doing it as well. As it is, I frequently scroll down and then wonder why nothing’s happening. I actually would like for everyone else to use Stanza’s method - it just jumps to the exact spot you were on which is less tiring on the eyes.
Stanza Pros: free; good readability. Cons: Most pdfs i tried to convert were not converted correctly making the app much less usable than i initially thought. Especially images and indexes are really poorly converted. So the search for a decent experience on reading my pdf’s went on which led me to the next app.
FileMagnet - a file manager for the ipod/iphone. Does what it’s supposed to do allowing the ipod work like a thumb drive. Cons: Frequent warnings on low memory when reading large pdfs and much poorer reading experience than stanza. Price:3.99€. Pros: Everything that i can’t read on Stanza, i read here. Useful.
Instapaper - simple app for saving pages and then reading offline. This is probably the app i use the most now along with itunes. Free and paid version. No real cons.
SmartTime - an app i really appreciate. A todo list + calendar: it’s been done a thousand times before but they actually innovated in the ui. Cons: no integration with google calendar, no export/import.
Writing Pad - another innovator. Instead of the default experience we have on small software devices where we click letter after letter to write, we now basically draw a line in between all the letters - this simple difference makes the writing experience a bit less clumky and much faster. I’ve gotten so used to it that i miss it in other apps where i write. A really good idea for writing on small devices (and they’ve filed a patent).
Accountr - a simple app for finance management. Didn’t really like it at first but it’s really quick to register stuff and i keep using it so that’s a good sign. Price: 0.79€
I could also mention others like Evernote but those are the ones i’m using the most now. Suggestions welcome
Share and Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
Para me divertir e porque me era útil decidi criar 2 comandos ubiquity para o firefox, um para o pai.pt e outro para o dicionário priberam.
O pai.pt foi fácil, bastou usar o searchCommand et voilá:
makeSearchCommand({
name: "pai",
url: "http://pai.pt/search/{QUERY}.html",
icon: "http://pai.pt/favicon.ico",
description: "Pesquisa nas páginas amarelas (pai.pt); Seaches the portuguese yellow pages."
});
No caso do dicionário priberam a coisa foi um pouco mais trabalhosa, primeiro tudo aquilo funciona à base de javascript no site (após alguma leitura do código lá percebi que faziam à mesma um pedido GET) e depois porque foi necessário codificar os parametros GET porque palavras com acentos estavam a falhar. Neste caso tive que usar o createCommand pois por enquanto não é possível escapar os parâmetros GET no searchCommand.
CmdUtils.CreateCommand({
name: "priberam",
description: "Searches the portuguese dictionary priberam",
help: "Try issuing "priberam aglet"",
icon: "http://priberam.pt/favicon.ico",
takes: {"pal": noun_arb_text},
execute: function( directObj ) {
var word = directObj.text;
Utils.openUrlInBrowser( "http://priberam.pt/dlpo/definir_resultados.aspx?pal=" + escape(word) );
}
});
O comando das páginas amarelas está aqui (comando pai) e o da priberam está aqui (comando priberam).
[Update: Acabei de reparar que o Rui Moura já tinha construído um comando para o dicionário priberam aqui. De qualquer modo, ao menos não são iguais porque a versão dele usa o searchCommand e como tal falha no caso de palavras com acentos ou caracteres especiais, ex. doçura.]
[Update 2: O Miguel Pais tem a versão mais completa neste momento (instalar aqui), com preview e também lida bem com caracteres especiais. Vejam os comentários abaixo.]
[For the english readers: to sum it up, when you need to escape accented characters in the query parameter use createCommand instead of searchCommand; see example code above).]
Share and Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
Those that decided to try out the chrome cross over port on their macs probably noticed that when chrome is first run, it strongly encourages the installation of quartz-wm included in Apple X11, in turn included in the cd. First i tried to reinstall X11 but it said i had a newer version so tried this tip that proved helpful 10.4: Provide Crossover with a missing quartz-wm and curiosity satisfied (hmm.. probably killed the cat and a bit of my time as well), i now have a working chrome in my mac.
Share and Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
Just a quick tip for those that want to use phpSecurityScanner but also use xampp/mampp. By default the scanner uses the local mysql server but since i’m used to xampp i wanted to use its mysql server.
So when i first ran the tool i got
[nativecode=Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2)]
which was natural since what i’d started was xampp. To fix this i just added to bin/config.php, right after set_include_path, the following :
ini_set(’mysql.default_socket’,'/Applications/xampp/xamppfiles/var/mysql/mysql.sock’);
Share and Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
An anthropological introduction to YouTube presented at the Library of Congress in June 2008 by Michael Wesch, a professor of digital ethnography at Kansas State University.
Well worth the time, funny, endearing, informative :=).
Share and Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
Maybe this already exists but since my searches didn’t turn up anything, i thought i’d post this.
You have an app coded more or less rest style. Every post request implies there was a data change (-> cache becomes stale), every get request implies there was no change in the data (-> cache stays fresh). So you know that if a post request was made to domain.com/admin/news, the news cache becomes stale. I won’t go really deep here, in that if you change item 8 of the news table, you might only have 2 stale caches, the one that lists the news and the one that shows item 8 of the news table ( ie. domain.com/news and domain.com/news/8 or domain.com/news/title-of-article) and not every cache belonging to the news group but let’s keep it simple here.
I would like to know if there’s anything out there that parses the apache logs for post requests and if there was a post/put/delete in any url, according to a few configurable rules, it will automatically do a get to the correspondent url. For example, if a post was made to domain.com/admin/news/8 then it would be able to, upon parsing of the apache logs, do a get request to domain.com/news/8, generating the cache for the next user that comes along instead of waiting for the next user to generate a fresh cache - keeping him waiting . It would just increase the cache hit ratio per user. It would of course run as a cron job.
I like this solution because it really keeps the caching code (if cache exists, expire cache, use cache, etc) outside the app, becoming simply another layer, where it really should be.
I really think that this makes sense from a rest perspective so i suspect it’s already out there..
So anyone know of anything? Preferably in php, but python or ruby is ok too.
Thanx :=)
Share and Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.