Author: maksim_ka
Date: 2010-01-26 20:00:06 +0100 (Tue, 26 Jan 2010)
New Revision: 27207
Added:
plugins/sfPhpunitPlugin/branches/1.2/lib/test/sfPhpunitContextInitilizerInterface.php
plugins/sfPhpunitPlugin/branches/1.2/lib/testcase/amf/
plugins/sfPhpunitPlugin/branches/1.2/lib/testcase/amf/sfPhpunitAmfService.php
Modified:
plugins/sfPhpunitPlugin/branches/1.2/data/unit/BasePhpunitTestSuite.tpl
plugins/sfPhpunitPlugin/branches/1.2/lib/fixture/sfPhpunitFixtureAggregatorInterface.php
plugins/sfPhpunitPlugin/branches/1.2/lib/task/sfPhpunitRuntestTask.class.php
plugins/sfPhpunitPlugin/branches/1.2/lib/test/sfBasePhpunitTestSuite.class.php
plugins/sfPhpunitPlugin/branches/1.2/lib/testcase/sfBasePhpunitAmfTestCase.class.php
Log:
[sfPhpunitPlugin] change the way to runtest from CLI. improve useability of the
amf testcase.
Modified:
plugins/sfPhpunitPlugin/branches/1.2/data/unit/BasePhpunitTestSuite.tpl
===================================================================
--- plugins/sfPhpunitPlugin/branches/1.2/data/unit/BasePhpunitTestSuite.tpl
2010-01-26 18:08:06 UTC (rev 27206)
+++ plugins/sfPhpunitPlugin/branches/1.2/data/unit/BasePhpunitTestSuite.tpl
2010-01-26 19:00:06 UTC (rev 27207)
@@ -1,6 +1,7 @@
<?php
class {className} extends sfBasePhpunitTestSuite
+ implements sfPhpunitContextInitilizerInterface
{
/**
* Dev hook for custom "setUp" stuff
Modified:
plugins/sfPhpunitPlugin/branches/1.2/lib/fixture/sfPhpunitFixtureAggregatorInterface.php
===================================================================
---
plugins/sfPhpunitPlugin/branches/1.2/lib/fixture/sfPhpunitFixtureAggregatorInterface.php
2010-01-26 18:08:06 UTC (rev 27206)
+++
plugins/sfPhpunitPlugin/branches/1.2/lib/fixture/sfPhpunitFixtureAggregatorInterface.php
2010-01-26 19:00:06 UTC (rev 27207)
@@ -4,8 +4,9 @@
* For using ability auto detect what fixtures type should be used
* you have to implement <b>one</b> of the following interfaces to the suite
or testcase
*
- * @author maksim
- *
+ * @package sfPhpunitPlugin
+ * @subpackage fixture
+ * @author Maksim Kotlyar <[email protected]>
*/
interface sfPhpunitFixtureAggregator
{
Modified:
plugins/sfPhpunitPlugin/branches/1.2/lib/task/sfPhpunitRuntestTask.class.php
===================================================================
---
plugins/sfPhpunitPlugin/branches/1.2/lib/task/sfPhpunitRuntestTask.class.php
2010-01-26 18:08:06 UTC (rev 27206)
+++
plugins/sfPhpunitPlugin/branches/1.2/lib/task/sfPhpunitRuntestTask.class.php
2010-01-26 19:00:06 UTC (rev 27207)
@@ -17,15 +17,10 @@
{
// // add your own arguments here
$this->addArguments(array(
- new sfCommandArgument('application', sfCommandArgument::REQUIRED,
'Application that will be used to load configuration before running tests'),
new sfCommandArgument('test', sfCommandArgument::OPTIONAL, 'Name of test
to run', ''),
));
- $this->addOptions(array(
- new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED,
'The environment', 'test'),
- new sfCommandOption('connection', null,
sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'propel'),
- // add your own options here
- ));
+ //$this->addOptions(array());
$this->namespace = 'phpunit';
$this->name = 'runtest';
@@ -33,13 +28,13 @@
$this->detailedDescription = <<<EOF
The [phpunit:runtest|INFO] Allow you to run simple test or test from the
directory or ofcourse all tests.
- [php symfony phpunit:runtest frontend foo|INFO] - run all test in the
phpunit directory and all subdirectories.
+ [php symfony phpunit:runtest foo|INFO] - run all test in the phpunit
directory and all subdirectories.
- [php symfony phpunit:runtest frontend unit |INFO] - run all test in the
/phpunit/unit directory.
+ [php symfony phpunit:runtest unit |INFO] - run all test in the /phpunit/unit
directory.
- [php symfony phpunit:runtest frontend unit/* |INFO] - run all test in the
/phpunit/unit directory and all subdirectories.
+ [php symfony phpunit:runtest unit/* |INFO] - run all test in the
/phpunit/unit directory and all subdirectories.
- [php symfony phpunit:runtest frontend unit/models/UserTest.php |INFO] - run
a single UserTest.php test case.
+ [php symfony phpunit:runtest unit/models/UserTest.php |INFO] - run a single
UserTest.php test case.
EOF;
}
@@ -52,8 +47,7 @@
shell_exec('./symfony phpunit:init');
$path = $arguments['test'];
- sfBasePhpunitTestSuite::setProjectConfiguration($this->configuration);
-
+
$runner = new PHPUnit_TextUI_TestRunner();
$runner->doRun(sfPhpunitSuiteLoader::factory($path)->getSuite());
}
Modified:
plugins/sfPhpunitPlugin/branches/1.2/lib/test/sfBasePhpunitTestSuite.class.php
===================================================================
---
plugins/sfPhpunitPlugin/branches/1.2/lib/test/sfBasePhpunitTestSuite.class.php
2010-01-26 18:08:06 UTC (rev 27206)
+++
plugins/sfPhpunitPlugin/branches/1.2/lib/test/sfBasePhpunitTestSuite.class.php
2010-01-26 19:00:06 UTC (rev 27207)
@@ -12,38 +12,13 @@
extends PHPUnit_Framework_TestSuite
implements sfPhpunitFixtureAggregator
{
- /**
- *
- * @var sfProjectConfiguration
- */
- protected static $_configuration;
-
/**
*
* @var sfPhpunitFixture
*/
protected $_fixture;
- public static function setProjectConfiguration(sfProjectConfiguration
$config)
- {
- self::$_configuration = $config;
- }
-
/**
- * @throws Exceptino if the sfProjectConfiguration instance was not set
previously
- *
- * @return sfProjectConfiguration
- */
- public static function getProjectConfiguration()
- {
- if (!self::$_configuration) {
- throw new Exception('Cannot create context. The project configuration
was not set before.');
- }
-
- return self::$_configuration;
- }
-
- /**
* Dev hook for custom "setUp" stuff
* Overwrite it in your test class, if you have to execute stuff before a
test is called.
*/
@@ -64,6 +39,10 @@
*/
public function setUp()
{
+ if ($this instanceof sfPhpunitContextInitilizerInterface) {
+ $this->_setupContext();
+ }
+
$this->_start();
}
@@ -96,17 +75,36 @@
*
* @return void
*/
- protected function _setupContext($name = null)
+ protected function _setupContext()
{
- if (!sfContext::hasInstance($name)) {
- if (!self::$_configuration) {
- throw new Exception('Cannot create context. The project
configuration was not set before.');
- }
-
- sfContext::createInstance(self::$_configuration, $name);
+ if (!$this instanceof sfPhpunitContextInitilizerInterface) {
+ throw new Exception('You should implement
`sfPhpunitContextInitilizerInterface` before initialazing context');
+ }
+
+ $app = $this->getApplication();
+ $env = $this->getEnvironment();
+
+ if (!sfContext::hasInstance($app)) {
+ sfContext::createInstance(
+ ProjectConfiguration::getApplicationConfiguration($app, $env,
true), $app);
}
+
+ sfContext::switchTo($app);
}
+ /**
+ * This methods has to be init by restriction of
`sfPhpunitContextInitilizerInterface
+ * And used in @method _setupContext
+ *
+ * This is default implementation. You can redefine it in child classes.
+ *
+ * @return string
+ */
+ public function getEnvironment()
+ {
+ return 'test';
+ }
+
public function getPackageFixtureDir()
{
return dirname($this->getOwnFixtureDir());
Added:
plugins/sfPhpunitPlugin/branches/1.2/lib/test/sfPhpunitContextInitilizerInterface.php
===================================================================
---
plugins/sfPhpunitPlugin/branches/1.2/lib/test/sfPhpunitContextInitilizerInterface.php
(rev 0)
+++
plugins/sfPhpunitPlugin/branches/1.2/lib/test/sfPhpunitContextInitilizerInterface.php
2010-01-26 19:00:06 UTC (rev 27207)
@@ -0,0 +1,8 @@
+<?php
+
+interface sfPhpunitContextInitilizerInterface
+{
+ function getApplication();
+
+ function getEnvironment();
+}
\ No newline at end of file
Added:
plugins/sfPhpunitPlugin/branches/1.2/lib/testcase/amf/sfPhpunitAmfService.php
===================================================================
---
plugins/sfPhpunitPlugin/branches/1.2/lib/testcase/amf/sfPhpunitAmfService.php
(rev 0)
+++
plugins/sfPhpunitPlugin/branches/1.2/lib/testcase/amf/sfPhpunitAmfService.php
2010-01-26 19:00:06 UTC (rev 27207)
@@ -0,0 +1,38 @@
+<?php
+
+if (!class_exists('SabreAMF_Client', true)) require_once 'SabreAMF/Client.php';
+
+/**
+ * sfBasePhpunitAmfService is the helper class for doing request to the amf
endpoint.
+ *
+ * @package sfPhpunitPlugin
+ * @subpackage testcase
+ * @author Maksim Kotlyar <[email protected]>
+ */
+class sfPhpunitAmfService
+{
+ protected
+ $_client,
+ $_service = false;
+
+ public function __construct($service, SabreAMF_Client $client)
+ {
+ $this->setService($service);
+ $this->_client = $client;
+ }
+
+ public function setService($name)
+ {
+ if (!(is_string($name) || !empty($name))) {
+ throw new Exception('Invalid amf service name. Should be none empty
string. You provide: `'.$name.'`');
+ }
+
+ $this->_service = $name;
+ }
+
+ public function __call($method, $args)
+ {
+ $request = "{$this->_service}.{$method}";
+ return $this->_client->sendRequest($request, $args);
+ }
+}
\ No newline at end of file
Modified:
plugins/sfPhpunitPlugin/branches/1.2/lib/testcase/sfBasePhpunitAmfTestCase.class.php
===================================================================
---
plugins/sfPhpunitPlugin/branches/1.2/lib/testcase/sfBasePhpunitAmfTestCase.class.php
2010-01-26 18:08:06 UTC (rev 27206)
+++
plugins/sfPhpunitPlugin/branches/1.2/lib/testcase/sfBasePhpunitAmfTestCase.class.php
2010-01-26 19:00:06 UTC (rev 27207)
@@ -1,5 +1,13 @@
<?php
+if (!class_exists('SabreAMF_ClassMapper', true)) {
+ require_once 'SabreAMF/ClassMapper.php'; //try to load from pear.
+}
+
+if (!class_exists('SabreAMF_Client', true)) {
+ require_once 'SabreAMF/Client.php'; //try to load from pear.
+}
+
/**
* sfBasePhpunitAmfTestCase is the super class for all test that cover amf
services
* tests using PHPUnit.
@@ -11,6 +19,13 @@
abstract class sfBasePhpunitAmfTestCase extends sfBasePhpunitTestCase
{
protected $_defaultMapping = array();
+
+ /**
+ * The service name where send the requests will send.
+ *
+ * @var false|string
+ */
+ protected $_amfservice = false;
public function setUp()
{
@@ -74,6 +89,8 @@
/**
* Send a request to amf gateway
*
+ * @deprecated
+ *
* @param string destination is requered. Example ObjectFoo.functbar
* @param array
*
@@ -98,4 +115,21 @@
{
return new SabreAMF_Client($this->_getAmfEndPoint());
}
+
+ /**
+ * @param SabreAMF_Client
+ *
+ * @throws Exception if the `_amfservice` propery is not defined.
+ *
+ * @return sfPhpunitAmfService
+ */
+ protected function service(SabreAMF_Client $client = null)
+ {
+ if (false === $this->_amfservice) {
+ throw new Exception('For using this method you have to se `_amfservice`
property');
+ }
+ if (is_null($client)) $client = $this->_getClient();
+
+ return new sfPhpunitAmfService($this->_amfservice, $client);
+ }
}
\ No newline at end of file
--
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.