Make PHPStan passing

This commit is contained in:
Kamil Kokot
2019-01-10 00:10:27 +01:00
parent 05f4fe789f
commit 4405596ca1
3 changed files with 34 additions and 10 deletions

View File

@@ -60,11 +60,12 @@ final class ContextServiceEnvironmentHandler implements EnvironmentHandler
}
/**
* @param UninitialisedContextServiceEnvironment $uninitializedEnvironment
*
* @throws EnvironmentIsolationException
*/
public function isolateEnvironment(Environment $uninitializedEnvironment, $testSubject = null): Environment
{
/** @var UninitialisedContextServiceEnvironment $uninitializedEnvironment */
$this->assertEnvironmentCanBeIsolated($uninitializedEnvironment, $testSubject);
$environment = new InitialisedContextServiceEnvironment($uninitializedEnvironment->getSuite());
@@ -136,22 +137,31 @@ final class ContextServiceEnvironmentHandler implements EnvironmentHandler
return $class;
}
throw new \Exception('wtf?');
throw new \DomainException(sprintf('There is no service or class "%s".', $contextId));
}
private function getContext(string $contextId): Context
{
if ($this->getContainer()->has($contextId)) {
return $this->getContainer()->get($contextId);
}
$class = '\\' . ltrim($contextId, '\\');
if (class_exists($class)) {
return new $class();
if ($this->getContainer()->has($contextId)) {
$context = $this->getContainer()->get($contextId);
} elseif (class_exists($class)) {
$context = new $class();
} else {
throw new \DomainException(sprintf('There is no service or class "%s".', $contextId));
}
throw new \Exception('wtf?');
if (!$context instanceof Context) {
throw new \DomainException(sprintf(
'Context "%s" referenced as "%s" needs to implement "%s".',
get_class($context),
$contextId,
Context::class
));
}
return $context;
}
private function getContainer(): ContainerInterface

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace FriendsOfBehat\SymfonyExtension\Driver;
use Behat\Mink\Driver\BrowserKitDriver;
use Symfony\Component\BrowserKit\Client;
use Symfony\Component\HttpKernel\KernelInterface;
final class SymfonyDriver extends BrowserKitDriver
@@ -21,6 +22,16 @@ final class SymfonyDriver extends BrowserKitDriver
));
}
parent::__construct($kernel->getContainer()->get('test.client'), $baseUrl);
$testClient = $kernel->getContainer()->get('test.client');
if (!$testClient instanceof Client) {
throw new \RuntimeException(sprintf(
'Service "test.client" should be an instance of "%s", "%s" given.',
Client::class,
get_class($testClient)
));
}
parent::__construct($testClient, $baseUrl);
}
}