Skip to content

Instantly share code, notes, and snippets.

@mageekguy
Last active February 14, 2017 17:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mageekguy/e925b1fca6766e598bc811889698a9cd to your computer and use it in GitHub Desktop.
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
<?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