Skip to content

Commit

Permalink
change default plugin name
Browse files Browse the repository at this point in the history
  • Loading branch information
sparkcz committed Nov 20, 2017
1 parent 2983226 commit ce74f8f
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function getPluginDirectory()


/**
* @return array
* @return array|\SplFileInfo[]
*/
public function getNeonConfigFilesPaths()
{
Expand Down Expand Up @@ -84,7 +84,14 @@ public function isEnable()
*/
public function getName()
{
return str_replace('-', '.', Strings::webalize(get_called_class()));
$name = get_called_class();

if ($name == Plugin::class) {
$paths = explode(DIRECTORY_SEPARATOR, $this->getPluginDirectory());
$name.= "." . end($paths);
}

return str_replace('-', '.', Strings::webalize($name));
}

}
32 changes: 32 additions & 0 deletions tests/cases/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require __DIR__ . '/../bootstrap.php';

use Grapesc\GrapeFluid\Plugins\Container;
use Grapesc\GrapeFluid\Plugins\Plugin;
use Nette\Caching\Storages\DevNullStorage;
use Tester\TestCase;
use Tester\Assert;
Expand All @@ -28,6 +29,37 @@ public function testGetEmptyPlugins()
Assert::count(0, $this->container->getPlugins());
}


public function testAddPluginWithoutOwnPluginClass()
{
$this->container->addPluginDirectory(__DIR__ . '/../fixtures/plugins_one');
$plugins = $this->container->getPlugins();

Assert::count(1, $this->container->getPlugins());

$plugin = current($plugins);

Assert::same('grapesc.grapefluid.plugins.plugin.testpluginone', $plugin->getName());
Assert::true($plugin->isEnable());
Assert::type(Plugin::class, $plugin);
}


public function testAddPluginWithOwnPluginClass()
{
$this->container->addPluginDirectory(__DIR__ . '/../fixtures/plugins_two');
$plugins = $this->container->getPlugins();

Assert::count(1, $this->container->getPlugins());

$plugin = current($plugins);

Assert::same('tests.fixtures.plugin', $plugin->getName());
Assert::true($plugin->isEnable());
Assert::type(Plugin::class, $plugin);
Assert::type(\Tests\Fixtures\Plugin::class, $plugin);
}

}

(new ContainerTest)->run();
44 changes: 44 additions & 0 deletions tests/cases/PluginTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Tests\Cases;

require __DIR__ . '/../bootstrap.php';

use Grapesc\GrapeFluid\Plugins\Plugin;
use Tester\TestCase;
use Tester\Assert;


class PluginTest extends TestCase
{

/**
* @dataProvider getPluginDirectory
*/
public function testCreatePlugin($directory)
{
$plugin = new Plugin($directory);

Assert::same(realpath($directory), $plugin->getPluginDirectory());
Assert::same(realpath($directory) . DIRECTORY_SEPARATOR . "commands", $plugin->getCommandsDirectory());

Assert::count(1, $plugin->getNeonConfigFilesPaths());

foreach ($plugin->getNeonConfigFilesPaths() AS $file) {
Assert::same($file->getRealPath(), realpath($directory) . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "config.neon");
}

}


public function getPluginDirectory()
{
return [
[__DIR__ . '/../fixtures/plugins_one/TestPluginOne'],
[__DIR__ . '/../fixtures/plugins_two/TestPluginTwo']
];
}

}

(new PluginTest)->run();
Empty file.
9 changes: 9 additions & 0 deletions tests/fixtures/plugins_two/TestPluginTwo/Plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Tests\Fixtures;


class Plugin extends \Grapesc\GrapeFluid\Plugins\Plugin
{

}
Empty file.

0 comments on commit ce74f8f

Please sign in to comment.