1

I have a plugin in Symfony 1.4 and I have created for him some tests put them in ROOT/myPlugin/test/unit/MyTest.php

The plugin was generated with sfTaskExtraPlugin.

The content of MyTest.php is:

<?php

require_once dirname(__FILE__).'/../bootstrap/unit.php';
$t = new lime_test(1); 
$r = new My();
$v = $r->getSomething(2);
$t->is($v, true);         

?>

When I run ./symfony test:unit Rights the response is >> test no tests found

However if I copy MyTest.php file in ROOT/test/unit the command ./symfony test:unit Rights is working.

The plugin is enabled in ProjectConfiguration.class.php

Why the test are not working if I write them in plugin?

Alexander L. Hayes
  • 3,892
  • 4
  • 13
  • 34
radu c
  • 4,138
  • 7
  • 30
  • 45

1 Answers1

2

Plugin's tests are not run by default (for good reason - why would you want to run tests for a 3rd party plugin every time you want to test your app?).

Edit your ProjectConfiguration like this:

class ProjectConfiguration extends sfProjectConfiguration
{
  public function setup()
  {
    $this->enablePlugins('myPlugin');
  }

  public function setupPlugins()
  {
    $this->pluginConfigurations['myPlugin']->connectTests();
  }
}

this will run the given plugin's tests along with the project's. Taken from symfony.com, about testing plugins.

Maerlyn
  • 33,687
  • 18
  • 94
  • 85
  • Thank for the replay. I get this error now `PHP Fatal error: Cannot redeclare class ProjectConfiguration in ROOT/path/to/plugins/myPlugin/test/fixtures/project/config/ProjectConfiguration.class.php on line 18` – radu c Jun 21 '11 at 11:56
  • Don't just copypaste my code in there - edit yours to look like it (substituting myPlugin for your plugins name, etc.) – Maerlyn Jun 21 '11 at 12:27
  • Yes, this is what I did. I have put my plugin name in : `$this->pluginConfigurations['MY_PLUGIN_NAME']->connectTests();` – radu c Jun 21 '11 at 12:48
  • According to the error, you did copypaste the whole stuff in there. – Maerlyn Jun 21 '11 at 12:54
  • I think I have copy them all. But note that in the error is pointing to `ProjectConfiguration.‌​class.php` from the plugin `ROOT/path/to/plugins/myPlugin/test/fixtures/project/config` not the main `config/ProjectConfiguration.‌​class.php`. Why is pointing there? – radu c Jun 21 '11 at 13:01
  • Oh, did not notice it. Did you add it there? It should be added to the main project configuration file. – Maerlyn Jun 21 '11 at 14:49
  • Yes, it is in the main project configuration file. However, I get this error concerning other `ProjectConfiguration.‌​class.php` which is in `ROOT/path/to/plugins/myPlugin/test/fixtures/project/config/ProjectConfiguration.‌​class.php`. Strange... – radu c Jun 22 '11 at 06:49
  • That class (and file) should be called myPluginConfiguration, not ProjectConfiguration. – Maerlyn Jun 22 '11 at 11:27