Skip to content

Instantly share code, notes, and snippets.

@kdambekalns
Last active August 29, 2015 14:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kdambekalns/6fd1e3b924c07acb5a2d to your computer and use it in GitHub Desktop.
Save kdambekalns/6fd1e3b924c07acb5a2d to your computer and use it in GitHub Desktop.
Using injected properties of Flow functional test in @dataProvider

PHPUnit collects the data from a dataProvider early during test execution, so the PersistenceManager instance is NULL, if used directly in the provider. Returning a closure that is re-bound during the the test makes this work.

<?php
/**
* Testcase for FooController
*/
class FooControllerTest extends \TYPO3\Flow\Tests\FunctionalTestCase {
/**
* @return array
*/
public function invalidFooIdentifiers() {
return array(
array(function() {return 'abcdef123456';}),
array(function() {return $this->persistenceManager->getIdentifierByObject($this->foo);}),
);
}
/**
* @test
* @dataProvider invalidFooIdentifiers
*/
public function invalidFooIdentifierDoesSomething(\Closure $invalidFooIdentifierClosure) {
$invalidAppIdentifier = $invalidAppIdentifierClosure->bindTo($this)->__invoke();
// ...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment