Last active
February 14, 2017 17:54
-
-
Save mageekguy/e925b1fca6766e598bc811889698a9cd to your computer and use it in GitHub Desktop.
Tips to automatically generate a class which extends from tested class with atoum
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace estvoyage\risingsun\tests\units; | |
use | |
mageekguy\atoum\mock | |
; | |
class test extends \atoum | |
{ | |
function beforeTestMethod($method) | |
{ | |
$testedClassName = $this->getTestedClassName(); | |
if (class_exists($testedClassName) && ! class_exists($this->getClassNamespace() . '\childOfTestedClass')) | |
{ | |
eval('namespace ' . $this->getClassNamespace() . ' { class childOfTestedClass extends \\' . $testedClassName . ' {} }'); | |
} | |
/* | |
Now you can do `new childOfTestedClass(…) in your test class, very useful in case of immutability to test that a clone (and not a new instance) is generated! | |
->if( | |
$childOfTestedClass = new childOfTestedClass | |
) | |
->then | |
->object($childOfTestedClass->recipientOfDictionaryWithPairIs($pair, $recipient)) | |
->isEqualTo(new childOfTestedClass) | |
->mock($recipient) | |
->receive('dictionaryIs') | |
->withArguments(new childOfTestedClass($pair)) | |
->once | |
*/ | |
return parent::beforeTestMethod($method); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment