Skip to content

Commit

Permalink
add a test/helper method for loading Plugins with Application
Browse files Browse the repository at this point in the history
  • Loading branch information
saeideng committed Jul 4, 2018
1 parent f6cdc6f commit 5945d39
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/TestSuite/TestCase.php
Expand Up @@ -17,6 +17,7 @@
use Cake\Core\Configure;
use Cake\Datasource\ConnectionManager;
use Cake\Event\EventManager;
use Cake\Http\BaseApplication;
use Cake\ORM\Entity;
use Cake\ORM\Exception\MissingTableClassException;
use Cake\ORM\Locator\LocatorAwareTrait;
Expand Down Expand Up @@ -189,6 +190,34 @@ public function loadFixtures()
}
}

/**
* simulate running the Application
* @param string|array list of Plugins to load
* @return \Cake\Http\BaseApplication
*/
public function loadPlugins($plugins = [])
{
$app = $this->getMockForAbstractClass(
BaseApplication::class,
['']
);

if (is_string($plugins)) {
$plugins = (array)$plugins;
}
foreach ($plugins as $k => $opts) {
if (is_array($opts)) {
$app->addPlugin($k, $opts);
} else {
$app->addPlugin($opts);
}
}
$app->pluginBootstrap();
$builder = Router::createRouteBuilder('/');
$app->pluginRoutes($builder);
return $app;
}

/**
* Asserts that a global event was fired. You must track events in your event manager for this assertion to work
*
Expand Down

0 comments on commit 5945d39

Please sign in to comment.