Skip to content

Instantly share code, notes, and snippets.

<?php
require __DIR__ . '/classes/autoloader.php';
use mageekguy\atoum;
$rootData = array('name' => 'atoum', 'children' => array());
$tokenFilter = function($token) {
if (is_array($token) === true)
@mageekguy
mageekguy / gist:5222226
Created March 22, 2013 15:35
Using scripts\treemap.php
To known how to use it, just do `php scripts/treemap.php --help`.
By default, there is no analyzer defined, so to add them, create a configuration file and add in it:`
```
<?php
use mageekguy\atoum\scripts\treemap\analyzers;
$script
->addAnalyzer(new analyzers\token())
->addAnalyzer(new analyzers\size())
@mageekguy
mageekguy / .treemap.php
Created March 26, 2013 13:01
Configruation file to generate atoum treemap
<?php
use
mageekguy\atoum\scripts\treemap,
mageekguy\atoum\scripts\treemap\analyzers,
mageekguy\atoum\scripts\treemap\categorizer
;
class commit implements treemap\analyzer
{
@mageekguy
mageekguy / gist:5394811
Created April 16, 2013 10:07
Command to replace spaces by tabs in a file.
command! -buffer -range=% -nargs=? SpaceToTab execute '<line1>,<line2>s#^\( \{'.(<q-args> ? <q-args> : &ts).'\}\)\+#\=repeat("\t", len(submatch(0))/' . &ts . ')#e'
@mageekguy
mageekguy / class_implements() vs reflection
Created April 19, 2013 13:32
class_implements() vs reflection
<?php
class foo implements iteratorAggregate { function getIterator() {} }
$timeClassImplements = 0;
for ($i = 0; $i < 1000; $i++)
{
$start = microtime(true);
class_implements('foo');
@mageekguy
mageekguy / gist:5451571
Last active December 16, 2015 14:49
To generate coverage treemap with atoum, just put this in your .atoum.php or a specific configuration file (and use -c argument to use it in this case)
<?php
/*
Sample atoum configuration file to have code coverage in html format and the treemap.
Do "php path/to/test/file -c path/to/this/file" or "php path/to/atoum/scripts/runner.php -c path/to/this/file -f path/to/test/file" to use it.
*/
use \mageekguy\atoum;
// HTML
17> rm -f tests/units/classes/foo.php && php scripts/runner.php -f tests/units/classes/foo.php
> PHP path: /usr/local/bin/php
> PHP version:
=> PHP 5.4.13 (cli) (built: Apr 5 2013 08:55:20)
=> Copyright (c) 1997-2013 The PHP Group
=> Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
> mageekguy\atoum\tests\units\foo...
[E___________________________________________________________][1/1]
=> Test duration: 0.00 second.
=> Memory usage: 0.00 Mb.
60> rm -f tests/units/classes/foo.php && rm -f classes/foo.php && php scripts/runner.php -f tests/units/classes/foo.php
> PHP path: /usr/local/bin/php
> PHP version:
=> PHP 5.4.13 (cli) (built: Apr 5 2013 08:55:20)
=> Copyright (c) 1997-2013 The PHP Group
=> Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
> mageekguy\atoum\tests\units\foo...
[0___________________________________________________________][1/1]
=> Test duration: 0.00 second.
=> Memory usage: 0.00 Mb.
<?php
$file = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'atoum.' . md5(__FILE__);
if (is_file($file) === false || filemtime(__FILE__) > filemtime($file))
{
file_put_contents($file, substr(file_get_contents(__FILE__), __COMPILER_HALT_OFFSET__ + 1));
}
require $file;
<?php
class dotFilter extends \recursiveFilterIterator
{
public function accept()
{
return (substr($this->getInnerIterator()->current(), 0, 1) != '.');
}
}