Next major version 2 with PHP 8.1, Symfony 6, Tabler UI, 2FA ... (#2902)
This commit is contained in:
@@ -13,18 +13,12 @@ use App\Plugin\PluginInterface;
|
||||
|
||||
class TestPlugin implements PluginInterface
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
public function getName(): string
|
||||
{
|
||||
return 'TestPlugin';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPath()
|
||||
public function getPath(): string
|
||||
{
|
||||
return __DIR__;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
"description": "Just a test fixture for the PluginManager",
|
||||
"homepage": "https://github.com/kimai/kimai",
|
||||
"type": "kimai-plugin",
|
||||
"version": "1.0",
|
||||
"require": {
|
||||
"kimai/kimai2-composer": "*",
|
||||
"kevinpapst/kimai2": "*"
|
||||
@@ -20,8 +21,7 @@
|
||||
],
|
||||
"extra": {
|
||||
"kimai": {
|
||||
"require": "0.9",
|
||||
"version": "1.0",
|
||||
"require": 10000,
|
||||
"name": "TestPlugin from composer.json",
|
||||
"license": []
|
||||
}
|
||||
|
||||
@@ -13,18 +13,12 @@ use App\Plugin\PluginInterface;
|
||||
|
||||
class TestPlugin2 implements PluginInterface
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
public function getName(): string
|
||||
{
|
||||
return 'TestPlugin';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPath()
|
||||
public function getPath(): string
|
||||
{
|
||||
return __DIR__;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ namespace App\Tests\Plugin;
|
||||
use App\Plugin\Plugin;
|
||||
use App\Plugin\PluginInterface;
|
||||
use App\Plugin\PluginManager;
|
||||
use App\Plugin\PluginMetadata;
|
||||
use App\Tests\Plugin\Fixtures\TestPlugin\TestPlugin;
|
||||
use App\Tests\Plugin\Fixtures\TestPlugin2\TestPlugin2;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
@@ -37,16 +36,18 @@ class PluginManagerTest extends TestCase
|
||||
|
||||
public function testAdd()
|
||||
{
|
||||
$sut = new PluginManager([]);
|
||||
|
||||
$plugin = $this->createMock(PluginInterface::class);
|
||||
$plugin->expects($this->any())->method('getName')->willReturn('foo');
|
||||
$plugin->expects($this->any())->method('getPath')->willReturn('bar');
|
||||
|
||||
$sut->addPlugin(new TestPlugin());
|
||||
$sut->addPlugin($plugin);
|
||||
$sut->addPlugin(new TestPlugin2());
|
||||
$sut->addPlugin(new TestPlugin());
|
||||
$plugins = [
|
||||
new TestPlugin(),
|
||||
$plugin,
|
||||
new TestPlugin2(),
|
||||
new TestPlugin(),
|
||||
];
|
||||
|
||||
$sut = new PluginManager($plugins);
|
||||
|
||||
// make sure a plugin with the same name is not added twice, the first one wins!
|
||||
$this->assertEquals(2, \count($sut->getPlugins()));
|
||||
@@ -59,7 +60,7 @@ class PluginManagerTest extends TestCase
|
||||
$test = $sut->getPlugin('TestPlugin');
|
||||
$this->assertInstanceOf(Plugin::class, $test);
|
||||
$this->assertEquals('TestPlugin', $test->getName());
|
||||
$this->assertEquals(new PluginMetadata(), $test->getMetadata());
|
||||
$this->assertNull($test->getMetadata());
|
||||
}
|
||||
|
||||
public function testLoadMetadata()
|
||||
@@ -69,10 +70,10 @@ class PluginManagerTest extends TestCase
|
||||
$sut->loadMetadata($plugin);
|
||||
|
||||
$meta = $plugin->getMetadata();
|
||||
$this->assertEquals('0.9', $meta->getKimaiVersion());
|
||||
$this->assertEquals(10000, $meta->getKimaiVersion());
|
||||
$this->assertEquals('1.0', $meta->getVersion());
|
||||
$this->assertEquals('TestPlugin', $plugin->getId());
|
||||
$this->assertEquals('TestPlugin from composer.json', $plugin->getName());
|
||||
$this->assertEquals('TestPlugin from composer.json', $meta->getName());
|
||||
$this->assertEquals('Just a test fixture for the PluginManager', $meta->getDescription());
|
||||
$this->assertEquals('https://github.com/kimai/kimai', $meta->getHomepage());
|
||||
}
|
||||
|
||||
@@ -25,18 +25,4 @@ class PluginMetadataTest extends TestCase
|
||||
$this->assertNull($sut->getVersion());
|
||||
$this->assertNull($sut->getKimaiVersion());
|
||||
}
|
||||
|
||||
public function testGetterAndSetter()
|
||||
{
|
||||
$sut = new PluginMetadata();
|
||||
$this->assertInstanceOf(PluginMetadata::class, $sut->setVersion('13.7'));
|
||||
$this->assertInstanceOf(PluginMetadata::class, $sut->setHomepage('http://www.example.com'));
|
||||
$this->assertInstanceOf(PluginMetadata::class, $sut->setDescription('foo bar'));
|
||||
$this->assertInstanceOf(PluginMetadata::class, $sut->setKimaiVersion('1.0'));
|
||||
|
||||
$this->assertEquals('13.7', $sut->getVersion());
|
||||
$this->assertEquals('http://www.example.com', $sut->getHomepage());
|
||||
$this->assertEquals('foo bar', $sut->getDescription());
|
||||
$this->assertEquals('1.0', $sut->getKimaiVersion());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
namespace App\Tests\Plugin;
|
||||
|
||||
use App\Plugin\Plugin;
|
||||
use App\Plugin\PluginInterface;
|
||||
use App\Plugin\PluginMetadata;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
@@ -20,32 +21,20 @@ class PluginTest extends TestCase
|
||||
{
|
||||
public function testEmptyObject()
|
||||
{
|
||||
$plugin = new Plugin();
|
||||
$this->assertNull($plugin->getId());
|
||||
$this->assertNull($plugin->getName());
|
||||
$this->assertNull($plugin->getPath());
|
||||
$plugin = new Plugin($this->createMock(PluginInterface::class));
|
||||
$this->assertEquals('', $plugin->getId());
|
||||
$this->assertEquals('', $plugin->getName());
|
||||
$this->assertEquals('', $plugin->getPath());
|
||||
$this->assertNull($plugin->getMetadata());
|
||||
}
|
||||
|
||||
public function testGetterAndSetter()
|
||||
{
|
||||
$metadata = new PluginMetadata();
|
||||
$metadata
|
||||
->setDescription('foo')
|
||||
->setHomepage('http://www.example.com')
|
||||
->setVersion('13.7')
|
||||
->setKimaiVersion('1.1')
|
||||
;
|
||||
|
||||
$plugin = new Plugin();
|
||||
$this->assertInstanceOf(Plugin::class, $plugin->setId('foo2'));
|
||||
$this->assertInstanceOf(Plugin::class, $plugin->setName('foo'));
|
||||
$this->assertInstanceOf(Plugin::class, $plugin->setPath('bar'));
|
||||
$this->assertInstanceOf(Plugin::class, $plugin->setMetadata($metadata));
|
||||
$plugin = new Plugin($this->createMock(PluginInterface::class));
|
||||
$plugin->setMetadata($metadata);
|
||||
|
||||
$this->assertEquals('foo2', $plugin->getId());
|
||||
$this->assertEquals('foo', $plugin->getName());
|
||||
$this->assertEquals('bar', $plugin->getPath());
|
||||
$this->assertSame($metadata, $plugin->getMetadata());
|
||||
$this->assertEquals($metadata, $plugin->getMetadata());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user