Skip to content

Commit

Permalink
Fix more broken tests, with help from #56
Browse files Browse the repository at this point in the history
Thanks to the PR from @gennadigennadigennadi
I've incorporated those fixes into this PR to get PHPUnit 9 support.

Signed-off-by: Drew Robinson <[email protected]>
  • Loading branch information
ocean committed Oct 16, 2020
1 parent d3a9795 commit 77e0761
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
8 changes: 4 additions & 4 deletions test/AbstractPluginManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public function testCallingSetServiceLocatorSetsCreationContextWithDeprecationNo
$pluginManager = new TestAsset\LenientPluginManager();
restore_error_handler();

self::assertAttributeSame($pluginManager, 'creationContext', $pluginManager);
self::assertSame($pluginManager, $pluginManager->getCreationContext());
$serviceManager = new ServiceManager();

set_error_handler(function ($errno, $errstr) {
Expand All @@ -215,7 +215,7 @@ public function testCallingSetServiceLocatorSetsCreationContextWithDeprecationNo
$pluginManager->setServiceLocator($serviceManager);
restore_error_handler();

self::assertAttributeSame($serviceManager, 'creationContext', $pluginManager);
self::assertSame($serviceManager, $pluginManager->getCreationContext());
}

/**
Expand All @@ -228,7 +228,7 @@ public function testPassingNoInitialConstructorArgumentSetsPluginManagerAsCreati
}, E_USER_DEPRECATED);
$pluginManager = new TestAsset\LenientPluginManager();
restore_error_handler();
self::assertAttributeSame($pluginManager, 'creationContext', $pluginManager);
self::assertSame($pluginManager, $pluginManager->getCreationContext());
}

/**
Expand All @@ -245,7 +245,7 @@ public function testCanPassConfigInterfaceAsFirstConstructorArgumentWithDeprecat
$pluginManager = new TestAsset\LenientPluginManager($config->reveal());
restore_error_handler();

self::assertAttributeSame($pluginManager, 'creationContext', $pluginManager);
self::assertSame($pluginManager, $pluginManager->getCreationContext());
}

public function invalidConstructorArguments()
Expand Down
30 changes: 24 additions & 6 deletions test/ServiceManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,17 @@ public function testMapsOneToOneInvokablesAsInvokableFactoriesInternally()
],
];

$serviceManager = new ServiceManager($config);
self::assertAttributeSame([
$serviceManager = new class ($config) extends ServiceManager
{
public function getFactories(): array
{
return $this->factories;
}
};

self::assertSame([
InvokableObject::class => InvokableFactory::class,
], 'factories', $serviceManager, 'Invokable object factory not found');
], $serviceManager->getFactories(), 'Invokable object factory not found');
}

public function testMapsNonSymmetricInvokablesAsAliasPlusInvokableFactory()
Expand All @@ -180,13 +187,24 @@ public function testMapsNonSymmetricInvokablesAsAliasPlusInvokableFactory()
],
];

$serviceManager = new ServiceManager($config);
$serviceManager = new class ($config) extends ServiceManager
{
public function getAliases(): array
{
return $this->aliases;
}

public function getFactories(): array
{
return $this->factories;
}
};
self::assertAttributeSame([
'Invokable' => InvokableObject::class,
], 'aliases', $serviceManager, 'Alias not found for non-symmetric invokable');
], $serviceManager->getAliases(), 'Alias not found for non-symmetric invokable');
self::assertAttributeSame([
InvokableObject::class => InvokableFactory::class,
], 'factories', $serviceManager, 'Factory not found for non-symmetric invokable target');
], $serviceManager->getFactories(), 'Factory not found for non-symmetric invokable target');
}

/**
Expand Down
6 changes: 6 additions & 0 deletions test/TestAsset/LenientPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace LaminasTest\ServiceManager\TestAsset;

use Laminas\ServiceManager\AbstractPluginManager;
use Psr\Container\ContainerInterface;

class LenientPluginManager extends AbstractPluginManager
{
Expand All @@ -21,4 +22,9 @@ public function validate($instance)
{
return;
}

public function getCreationContext(): ContainerInterface
{
return $this->creationContext;
}
}

0 comments on commit 77e0761

Please sign in to comment.