[TYPO3-mvc] RFC #11225: Tx_Extbase_DomainObject_AbstractDomainObject::getUid cannot be mocked as it is final

Bastian Waidelich bastian.waidelich at typo3.org
Thu Dec 2 18:48:46 CET 2010


Oliver Klee wrote:

Hi Oliver,

> Problem:
> phpunit cannot mock final, private or static methods [1].
> Tx_Extbase_DomainObject_AbstractDomainObject::getUid is final and thus
> cannot be mocked which makes unit testing unnecessary hard.

AbstractDomainObject::getUid() is final to prevent people from 
overriding it in their entity class.
Why do you need to mock this setter?
You can create an "accessible" mock that allows you to get and set all 
protected members:

$myDomainObject = 
$this->getAccessibleMock('Tx_Foo_Domain_MyDomainObject', array('dummy'));

  // set uid
$myDomainObject->_set('uid', 123);

  // get uid
$myDomainObject->_get('uid');

HTH,
Bastian


More information about the TYPO3-project-typo3v4mvc mailing list