Author: maksim_ka
Date: 2010-04-07 15:58:04 +0200 (Wed, 07 Apr 2010)
New Revision: 29033
Added:
plugins/sfPhpunitPlugin/branches/1.4/lib/test/sfPhpunitStubLatter.php
Modified:
plugins/sfPhpunitPlugin/branches/1.4/lib/fixture/data/sfPhpunitDoctrineData.php
plugins/sfPhpunitPlugin/branches/1.4/lib/test/sfBasePhpunitTestSuite.class.php
plugins/sfPhpunitPlugin/branches/1.4/lib/testcase/sfBasePhpunitTestCase.class.php
Log:
[sfPhpunitPlugin][sf1.4] add helper method getStub. simplier way to create
stubs.
Modified:
plugins/sfPhpunitPlugin/branches/1.4/lib/fixture/data/sfPhpunitDoctrineData.php
===================================================================
---
plugins/sfPhpunitPlugin/branches/1.4/lib/fixture/data/sfPhpunitDoctrineData.php
2010-04-07 13:57:47 UTC (rev 29032)
+++
plugins/sfPhpunitPlugin/branches/1.4/lib/fixture/data/sfPhpunitDoctrineData.php
2010-04-07 13:58:04 UTC (rev 29033)
@@ -7,7 +7,7 @@
* @see
plugins/sfPhpunitPlugin/lib/fixture/data/sfPhpunitDataInterface#getObject($id,
$class)
*/
public function getObject($id)
- {
+ {
if (strpos($id, '_') === false) {
throw new Exception('The id should match the pattern {table}_{id}
but you provide: `'.$id.'`');
}
Modified:
plugins/sfPhpunitPlugin/branches/1.4/lib/test/sfBasePhpunitTestSuite.class.php
===================================================================
---
plugins/sfPhpunitPlugin/branches/1.4/lib/test/sfBasePhpunitTestSuite.class.php
2010-04-07 13:57:47 UTC (rev 29032)
+++
plugins/sfPhpunitPlugin/branches/1.4/lib/test/sfBasePhpunitTestSuite.class.php
2010-04-07 13:58:04 UTC (rev 29033)
@@ -39,7 +39,7 @@
public function setUp()
{
if ($this instanceof sfPhpunitContextInitilizerInterface) {
- $this->_setupContext();
+ $this->setupContext();
}
$this->_start();
@@ -60,7 +60,7 @@
*/
protected function _setupDatabaseSchema()
{
- $this->_setupContext();
+ $this->setupContext();
$env = sfContext::getInstance()->getConfiguration()->getEnvironment();
chdir(sfConfig::get('sf_root_dir'));
@@ -74,7 +74,7 @@
*
* @return void
*/
- protected function _setupContext()
+ public function setupContext()
{
if (!$this instanceof sfPhpunitContextInitilizerInterface) {
throw new Exception('You should implement
`sfPhpunitContextInitilizerInterface` before initialazing context');
@@ -94,7 +94,7 @@
/**
* This methods has to be init by restriction of
`sfPhpunitContextInitilizerInterface
- * And used in @method _setupContext
+ * And used in @method setupContext
*
* This is default implementation. You can redefine it in child classes.
*
@@ -102,7 +102,7 @@
*/
public function getEnvironment()
{
- return sfConfig::get('sf_environment');
+ return sfConfig::get('sf_environment', 'test');
}
public function getPackageFixtureDir()
Added: plugins/sfPhpunitPlugin/branches/1.4/lib/test/sfPhpunitStubLatter.php
===================================================================
--- plugins/sfPhpunitPlugin/branches/1.4/lib/test/sfPhpunitStubLatter.php
(rev 0)
+++ plugins/sfPhpunitPlugin/branches/1.4/lib/test/sfPhpunitStubLatter.php
2010-04-07 13:58:04 UTC (rev 29033)
@@ -0,0 +1,11 @@
+<?php
+
+/**
+ * It can be used in sfBasePhpunitTestCase::getStub for methods that have to
be stubed later.
+ *
+ *
+ * @package sfPhpunitPlugin
+ * @subpackage lib
+ * @author Maksim Kotlyar <[email protected]>
+ */
+class sfPhpunitStubLatter {}
\ No newline at end of file
Modified:
plugins/sfPhpunitPlugin/branches/1.4/lib/testcase/sfBasePhpunitTestCase.class.php
===================================================================
---
plugins/sfPhpunitPlugin/branches/1.4/lib/testcase/sfBasePhpunitTestCase.class.php
2010-04-07 13:57:47 UTC (rev 29032)
+++
plugins/sfPhpunitPlugin/branches/1.4/lib/testcase/sfBasePhpunitTestCase.class.php
2010-04-07 13:58:04 UTC (rev 29033)
@@ -84,6 +84,61 @@
return implode(DIRECTORY_SEPARATOR, $path);
}
+
+ /**
+ * All stubed methods should be called at least one time.
+ */
+ public function getStubStrict($originalClassName, $stubedMethods, $arguments
= array(), $mockClassName = '', $callOriginalConstructor = true,
$callOriginalClone = true, $callAutoload = true)
+ {
+ return $this->getStub(
+ $originalClassName,
+ $stubedMethods,
+ $arguments,
+ $mockClassName,
+ $callOriginalConstructor,
+ $callOriginalClone,
+ $callAutoload,
+ true);
+ }
+
+ public function getStub($originalClassName, $stubedMethods, $arguments =
array(), $mockClassName = '', $callOriginalConstructor = true,
$callOriginalClone = true, $callAutoload = true, $strict = false)
+ {
+ $mock = $this->getMock(
+ $originalClassName,
+ array_keys($stubedMethods),
+ $arguments,
+ $mockClassName,
+ $callOriginalConstructor,
+ $callOriginalClone,
+ $callAutoload);
+
+ $expects = $strict ? $this->atLeastOnce() : $this->any();
+
+ foreach ($stubedMethods as $method => $stub) {
+
+ if ($stub instanceof sfPhpunitStubLatter) continue;
+
+ $stubedMethod = $mock->expects($expects)->method($method);
+ if ($stub instanceof sfCallable) {
+ $stubedMethod->will($this->returnCallback($stub->getCallable()));
+ } else if ($stub instanceof Exception) {
+ $stubedMethod->will($this->throwException($stub));
+ } else {
+ $stubedMethod->will($this->returnValue($stub));
+ }
+ }
+
+ return $mock;
+ }
+
+ /**
+ *
+ * @return sfPhpunitStubLatter
+ */
+ public function stubLater()
+ {
+ return new sfPhpunitStubLatter();
+ }
/**
*
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/symfony-svn?hl=en.