From 13dbdbc8fc6b06039432a4933886f19010630481 Mon Sep 17 00:00:00 2001 From: "Andrey F. Mindubaev" Date: Thu, 28 Jun 2018 21:40:08 +0000 Subject: [PATCH] Read KERNEL_DIR and KERNEL_CLASS from phpunit.xml.dist for bin/console (#182) * Read KERNEL_DIR and KERNEL_CLASS from phpunit.xml.dist for bin/console * Fix condition --- bootstrap/kernel_bootstrap.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/bootstrap/kernel_bootstrap.php b/bootstrap/kernel_bootstrap.php index 396b63e..34a5fa0 100644 --- a/bootstrap/kernel_bootstrap.php +++ b/bootstrap/kernel_bootstrap.php @@ -25,9 +25,18 @@ } $xml = new \SimpleXMLElement(file_get_contents($phpUnitFile)); -$kernelDir = $xml->php[0]->server[0]['value']; -$kernelFile = $rootDir.'/'.$kernelDir.'/AppKernel.php'; +$envDir = $xml->xpath("//php/server[@name='KERNEL_DIR']"); +if (!count($envDir)) { + throw new \Exception( + 'Kernel path must be set via ' + ); +} +$envClass = $xml->xpath("//php/env[@name='KERNEL_CLASS']"); + +$kernelClass = count($envClass) ? (string) $envClass[0]['value'] : 'AppKernel'; +$kernelNs = explode('\\', $kernelClass); +$kernelFile = $rootDir.'/'.$envDir[0]['value'].'/'.array_pop($kernelNs).'.php'; if (!file_exists($kernelFile)) { throw new \Exception(sprintf( @@ -38,4 +47,4 @@ require_once $kernelFile; -return new AppKernel($env, true); +return new $kernelClass($env, true);