Skip to content
This repository was archived by the owner on Feb 6, 2020. It is now read-only.

Commit d6310a8

Browse files
Matt Kynastonweierophinney
authored andcommitted
Moved CommonPluginManagerTrait to src/Test, updated docs
1 parent 2b97820 commit d6310a8

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

doc/book/migration.md

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,11 +1240,12 @@ instance of your plugin manager and override `getV2InvalidPluginException()`
12401240
to return the classname of the exception your `validatePlugin()` method throws:
12411241

12421242
```php
1243+
use MyNamespace\ObserverInterface;
12431244
use MyNamespace\ObserverPluginManager;
12441245
use MyNamespace\Exception\RuntimeException;
12451246
use PHPUnit_Framework_TestCase as TestCase;
12461247
use Zend\ServiceManager\ServiceManager;
1247-
use ZendTest\ServiceManager\TestAsset\V2v3PluginManager;
1248+
use Zend\ServiceManager\Test\CommonPluginManagerTrait;
12481249

12491250
class MigrationTest extends TestCase
12501251
{
@@ -1259,6 +1260,11 @@ class MigrationTest extends TestCase
12591260
{
12601261
return RuntimeException::class;
12611262
}
1263+
1264+
protected function getInstanceOf()
1265+
{
1266+
return ObserverInterface::class;
1267+
}
12621268
}
12631269
```
12641270

@@ -1269,17 +1275,6 @@ This will check that:
12691275
- That requesting an invalid plugin throws the right exception
12701276
- That all your aliases resolve
12711277

1272-
Note that you will need to include ServiceManager's test directory in the `autoload-dev` section of your `compoer.json`
1273-
for this test to work:
1274-
1275-
```
1276-
"autoload-dev": {
1277-
"psr-4": {
1278-
"MyNamespaceTest\ObserverPluginManager\\": "test/",
1279-
"ZendTest\\ServiceManager\\": "vendor/zendframework/zend-servicemanager/test/"
1280-
}
1281-
}
1282-
```
12831278

12841279
### Post migration
12851280

test/CommonPluginManagerTrait.php renamed to src/Test/CommonPluginManagerTrait.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @license http://framework.zend.com/license/new-bsd New BSD License
88
*/
99

10-
namespace ZendTest\ServiceManager;
10+
namespace Zend\ServiceManager\Test;
1111

1212
use ReflectionClass;
1313
use ReflectionProperty;
@@ -22,12 +22,12 @@
2222
*/
2323
trait CommonPluginManagerTrait
2424
{
25-
public function testInstanceOfIsSet()
25+
public function testInstanceOfMatches()
2626
{
2727
$manager = $this->getPluginManager();
2828
$reflection = new ReflectionProperty($manager, 'instanceOf');
2929
$reflection->setAccessible(true);
30-
$this->assertNotNull($reflection->getValue($manager), 'instanceOf property not set');
30+
$this->assertEquals($this->getInstanceOf(), $reflection->getValue($manager), 'instanceOf does not match');
3131
}
3232

3333
public function testShareByDefaultAndSharedByDefault()
@@ -107,4 +107,10 @@ abstract protected function getPluginManager();
107107
* @return mixed
108108
*/
109109
abstract protected function getV2InvalidPluginException();
110+
111+
/**
112+
* Returns the value the instanceOf property has been set to
113+
* @return string
114+
*/
115+
abstract protected function getInstanceOf();
110116
}

test/ExamplePluginManagerTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
use PHPUnit_Framework_TestCase as TestCase;
1313
use Zend\ServiceManager\ServiceManager;
14+
use Zend\ServiceManager\Test\CommonPluginManagerTrait;
15+
use ZendTest\ServiceManager\TestAsset\InvokableObject;
1416
use ZendTest\ServiceManager\TestAsset\V2v3PluginManager;
1517

1618
/**
@@ -29,4 +31,9 @@ protected function getV2InvalidPluginException()
2931
{
3032
return \RuntimeException::class;
3133
}
34+
35+
protected function getInstanceOf()
36+
{
37+
return InvokableObject::class;
38+
}
3239
}

0 commit comments

Comments
 (0)