samedi 20 décembre 2014

How to test data passed to closure, with phpunit

I have a class, which generate a data object and pass it to given callable variable



<?php

class Foo {

public function bar(callable $closure)
{
$data = $this->generateData();

call_user_func_array($closure, compact($data));
}

}

// example usage
$baz = new Foo()
$baz->bar(function($data) {
var_dump($data); // I want to test $data type inside this closure
});


How can I test $data dataType pass to the anonymous function?


Aucun commentaire:

Enregistrer un commentaire