From 06e3558a0b7249eab44aaf9ad40e6b892db7b342 Mon Sep 17 00:00:00 2001 From: dnna Date: Sat, 25 Aug 2018 19:50:37 +0300 Subject: [PATCH 01/15] Add test infrastructure and symfony test --- .travis.yml | 2 ++ composer.json | 7 ++++++- phpunit.xml.dist | 19 +++++++++++++++++ tests/HttpKernelTest.php | 24 +++++++++++++++++++++ tests/SymfonyBootstrapTest.php | 32 ++++++++++++++++++++++++++++ tests/SymfonyMocks/Container.php | 9 ++++++++ tests/SymfonyMocks/Kernel.php | 36 ++++++++++++++++++++++++++++++++ tests/bootstrap.php | 3 +++ 8 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 phpunit.xml.dist create mode 100644 tests/HttpKernelTest.php create mode 100644 tests/SymfonyBootstrapTest.php create mode 100644 tests/SymfonyMocks/Container.php create mode 100644 tests/SymfonyMocks/Kernel.php create mode 100644 tests/bootstrap.php diff --git a/.travis.yml b/.travis.yml index 9e284ba..b77a6ba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,6 +19,8 @@ jobs: # dependencies for phpstan - composer require --dev "symfony/symfony" "laravel/framework" "drupal/drupal" script: + # Unit test + - ./vendor/bin/phpunit # Static analyzer check - ./vendor/bin/phpstan analyze -c .phpstan.neon --level=4 --no-progress Bootstraps Bridges Laravel || true # Check the code style diff --git a/composer.json b/composer.json index 90577c6..eae2ca8 100644 --- a/composer.json +++ b/composer.json @@ -7,9 +7,14 @@ "symfony/http-kernel": "^2.6|^3.0|^4", "ringcentral/psr7": "^1.2" }, + "require-dev": { + "mockery/mockery": "^1.0", + "phpunit/phpunit": "^5.7" + }, "autoload": { "psr-4": { - "PHPPM\\": "" + "PHPPM\\": "", + "PHPPM\\Tests\\": "tests" } } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..6bb5742 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,19 @@ + + + + + + tests/ + + + + \ No newline at end of file diff --git a/tests/HttpKernelTest.php b/tests/HttpKernelTest.php new file mode 100644 index 0000000..468f134 --- /dev/null +++ b/tests/HttpKernelTest.php @@ -0,0 +1,24 @@ +getMockBuilder(ServerRequestInterface::class) + ->getMock(); + $response = $bridge->handle($request); + $this->assertEquals(500, $response->getStatusCode()); + $this->assertEquals('Application not configured during bootstrap', (string)$response->getBody()); + } +} diff --git a/tests/SymfonyBootstrapTest.php b/tests/SymfonyBootstrapTest.php new file mode 100644 index 0000000..4b3a41b --- /dev/null +++ b/tests/SymfonyBootstrapTest.php @@ -0,0 +1,32 @@ +bootstrap('Symfony', 'test', true); + + $request = $this + ->getMockBuilder(ServerRequestInterface::class) + ->getMock(); + $request->method('getHeader')->with('Cookie')->willReturn(array()); + $request->method('getUploadedFiles')->willReturn(array()); + $request->method('getQueryParams')->willReturn(array()); + $request->method('getMethod')->willReturn('GET'); + + $response = $bridge->handle($request); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertEquals('Success', (string)$response->getBody()); + } +} diff --git a/tests/SymfonyMocks/Container.php b/tests/SymfonyMocks/Container.php new file mode 100644 index 0000000..6a333b1 --- /dev/null +++ b/tests/SymfonyMocks/Container.php @@ -0,0 +1,9 @@ +bundlesInitialized = true; + } + + public function initializeContainer() { + $this->containerInitialized = true; + } + + public function getBundles() { + return array(); + } + + public function getContainer() { + return new Container(); + } + + public function handle(Request $request) { + if(!$this->bundlesInitialized) { throw new \Exception('Bundles not initialized'); } + if(!$this->containerInitialized) { throw new \Exception('Container not initialized'); } + + // Simple get request + return new Response('Success', 200); + } +} \ No newline at end of file diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..0ec8857 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,3 @@ + Date: Sat, 25 Aug 2018 19:54:30 +0300 Subject: [PATCH 02/15] Fix CS --- tests/SymfonyBootstrapTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/SymfonyBootstrapTest.php b/tests/SymfonyBootstrapTest.php index 4b3a41b..df33a3a 100644 --- a/tests/SymfonyBootstrapTest.php +++ b/tests/SymfonyBootstrapTest.php @@ -20,9 +20,9 @@ public function testGetRequest() $request = $this ->getMockBuilder(ServerRequestInterface::class) ->getMock(); - $request->method('getHeader')->with('Cookie')->willReturn(array()); - $request->method('getUploadedFiles')->willReturn(array()); - $request->method('getQueryParams')->willReturn(array()); + $request->method('getHeader')->with('Cookie')->willReturn([]); + $request->method('getUploadedFiles')->willReturn([]); + $request->method('getQueryParams')->willReturn([]); $request->method('getMethod')->willReturn('GET'); $response = $bridge->handle($request); From ffd8ea32637a71533f3e00732c692c01e82e9ccc Mon Sep 17 00:00:00 2001 From: dnna Date: Sat, 25 Aug 2018 19:57:37 +0300 Subject: [PATCH 03/15] Fix CS again --- tests/SymfonyMocks/Container.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/SymfonyMocks/Container.php b/tests/SymfonyMocks/Container.php index 6a333b1..4bc7df7 100644 --- a/tests/SymfonyMocks/Container.php +++ b/tests/SymfonyMocks/Container.php @@ -3,7 +3,8 @@ namespace PHPPM\Tests\SymfonyMocks; class Container { - public function has($service) { + public function has($service) + { return false; } } \ No newline at end of file From ce4bfc38a9b59a8812c91539d83f15505c15ac1a Mon Sep 17 00:00:00 2001 From: dnna Date: Sat, 25 Aug 2018 20:00:48 +0300 Subject: [PATCH 04/15] Fix CS again --- tests/SymfonyMocks/Container.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/SymfonyMocks/Container.php b/tests/SymfonyMocks/Container.php index 4bc7df7..b290ad3 100644 --- a/tests/SymfonyMocks/Container.php +++ b/tests/SymfonyMocks/Container.php @@ -2,7 +2,8 @@ namespace PHPPM\Tests\SymfonyMocks; -class Container { +class Container +{ public function has($service) { return false; From 9ebe35db3f835bc739134f3db9c9b9aa98633154 Mon Sep 17 00:00:00 2001 From: dnna Date: Sat, 25 Aug 2018 20:04:02 +0300 Subject: [PATCH 05/15] Fix CS again --- tests/SymfonyMocks/Container.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/SymfonyMocks/Container.php b/tests/SymfonyMocks/Container.php index b290ad3..9f27388 100644 --- a/tests/SymfonyMocks/Container.php +++ b/tests/SymfonyMocks/Container.php @@ -8,4 +8,4 @@ public function has($service) { return false; } -} \ No newline at end of file +} From b93ee775740cb223e7f5d650c45c88155ba77910 Mon Sep 17 00:00:00 2001 From: dnna Date: Sat, 25 Aug 2018 20:05:13 +0300 Subject: [PATCH 06/15] Fix CS again --- tests/SymfonyMocks/Kernel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/SymfonyMocks/Kernel.php b/tests/SymfonyMocks/Kernel.php index 277f5e5..a89be24 100644 --- a/tests/SymfonyMocks/Kernel.php +++ b/tests/SymfonyMocks/Kernel.php @@ -33,4 +33,4 @@ public function handle(Request $request) { // Simple get request return new Response('Success', 200); } -} \ No newline at end of file +} From 4f65275435710ea9fb1215fa63455632f65b55a1 Mon Sep 17 00:00:00 2001 From: dnna Date: Sat, 25 Aug 2018 20:07:18 +0300 Subject: [PATCH 07/15] Fix CS again --- tests/SymfonyMocks/Kernel.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/tests/SymfonyMocks/Kernel.php b/tests/SymfonyMocks/Kernel.php index a89be24..30cb775 100644 --- a/tests/SymfonyMocks/Kernel.php +++ b/tests/SymfonyMocks/Kernel.php @@ -8,25 +8,32 @@ class Kernel { private $bundlesInitialized = false; private $containerInitialized = false; - public function __construct($env, $debug) {} + public function __construct($env, $debug) + { + } - public function initializeBundles() { + public function initializeBundles() + { $this->bundlesInitialized = true; } - public function initializeContainer() { + public function initializeContainer() + { $this->containerInitialized = true; } - public function getBundles() { + public function getBundles() + { return array(); } - public function getContainer() { + public function getContainer() + { return new Container(); } - public function handle(Request $request) { + public function handle(Request $request) + { if(!$this->bundlesInitialized) { throw new \Exception('Bundles not initialized'); } if(!$this->containerInitialized) { throw new \Exception('Container not initialized'); } From fb67105e3ae4c6c46c6f9f0f73ead5269aa4e02e Mon Sep 17 00:00:00 2001 From: dnna Date: Sat, 25 Aug 2018 20:08:54 +0300 Subject: [PATCH 08/15] Fix CS again --- tests/SymfonyMocks/Kernel.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/SymfonyMocks/Kernel.php b/tests/SymfonyMocks/Kernel.php index 30cb775..317855c 100644 --- a/tests/SymfonyMocks/Kernel.php +++ b/tests/SymfonyMocks/Kernel.php @@ -34,8 +34,12 @@ public function getContainer() public function handle(Request $request) { - if(!$this->bundlesInitialized) { throw new \Exception('Bundles not initialized'); } - if(!$this->containerInitialized) { throw new \Exception('Container not initialized'); } + if(!$this->bundlesInitialized) { + throw new \Exception('Bundles not initialized'); + } + if(!$this->containerInitialized) { + throw new \Exception('Container not initialized'); + } // Simple get request return new Response('Success', 200); From c68849b6d8eb78386e3bd7968a60c15490ed15a6 Mon Sep 17 00:00:00 2001 From: dnna Date: Sat, 25 Aug 2018 20:11:28 +0300 Subject: [PATCH 09/15] Fix CS again --- tests/SymfonyMocks/Kernel.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/SymfonyMocks/Kernel.php b/tests/SymfonyMocks/Kernel.php index 317855c..8a83e5c 100644 --- a/tests/SymfonyMocks/Kernel.php +++ b/tests/SymfonyMocks/Kernel.php @@ -1,10 +1,12 @@ bundlesInitialized) { + if (!$this->bundlesInitialized) { throw new \Exception('Bundles not initialized'); } - if(!$this->containerInitialized) { + if (!$this->containerInitialized) { throw new \Exception('Container not initialized'); } From 949e7350a2d6ae28eae4da38bec3ef87adb52b76 Mon Sep 17 00:00:00 2001 From: dnna Date: Sat, 25 Aug 2018 21:20:29 +0300 Subject: [PATCH 10/15] Add file upload test --- tests/SymfonyBootstrapTest.php | 53 ++++++++++++++++++++++++++++++---- tests/SymfonyMocks/Kernel.php | 12 ++++++-- 2 files changed, 57 insertions(+), 8 deletions(-) diff --git a/tests/SymfonyBootstrapTest.php b/tests/SymfonyBootstrapTest.php index df33a3a..0ce4dba 100644 --- a/tests/SymfonyBootstrapTest.php +++ b/tests/SymfonyBootstrapTest.php @@ -5,9 +5,20 @@ use PHPUnit\Framework\TestCase; use PHPPM\Bridges\HttpKernel; use Psr\Http\Message\ServerRequestInterface; +use Psr\Http\Message\UploadedFileInterface; class SymfonyBootstrapTest extends TestCase { + private function getMockedRequest() + { + $request = $this + ->getMockBuilder(ServerRequestInterface::class) + ->getMock(); + $request->method('getHeader')->with('Cookie')->willReturn([]); + $request->method('getQueryParams')->willReturn([]); + return $request; + } + /** * @runInSeparateProcess */ @@ -17,16 +28,46 @@ public function testGetRequest() $bridge = new HttpKernel(); $bridge->bootstrap('Symfony', 'test', true); - $request = $this - ->getMockBuilder(ServerRequestInterface::class) - ->getMock(); - $request->method('getHeader')->with('Cookie')->willReturn([]); + $request = $this->getMockedRequest(); $request->method('getUploadedFiles')->willReturn([]); - $request->method('getQueryParams')->willReturn([]); $request->method('getMethod')->willReturn('GET'); - + $response = $bridge->handle($request); $this->assertEquals(200, $response->getStatusCode()); $this->assertEquals('Success', (string)$response->getBody()); } + + /** + * @runInSeparateProcess + */ + public function testFileUpload() + { + putenv('APP_KERNEL_NAMESPACE=PHPPM\\Tests\\SymfonyMocks\\'); + $bridge = new HttpKernel(); + $bridge->bootstrap('Symfony', 'test', true); + + $fileOK = $this + ->getMockBuilder(UploadedFileInterface::class) + ->getMock(); + $fileOK->method('getClientFilename')->willReturn('testOK.pdf'); + $fileOK->method('getClientMediaType')->willReturn('pdf'); + $fileOK->method('getSize')->willReturn(1000); + $fileOK->method('getError')->willReturn(UPLOAD_ERR_OK); + + $fileErr = $this + ->getMockBuilder(UploadedFileInterface::class) + ->getMock(); + $fileErr->method('getClientFilename')->willReturn('testErr.pdf'); + $fileErr->method('getClientMediaType')->willReturn('pdf'); + $fileErr->method('getSize')->willReturn(0); + $fileErr->method('getError')->willReturn(UPLOAD_ERR_NO_FILE); + + $request = $this->getMockedRequest(); + $request->method('getUploadedFiles')->willReturn([$fileOK, $fileErr]); + $request->method('getMethod')->willReturn('POST'); + + $response = $bridge->handle($request); + $this->assertEquals(201, $response->getStatusCode()); + $this->assertEquals('Uploaded files: testOK.pdf,NULL', (string)$response->getBody()); + } } diff --git a/tests/SymfonyMocks/Kernel.php b/tests/SymfonyMocks/Kernel.php index 8a83e5c..4eea442 100644 --- a/tests/SymfonyMocks/Kernel.php +++ b/tests/SymfonyMocks/Kernel.php @@ -43,7 +43,15 @@ public function handle(Request $request) throw new \Exception('Container not initialized'); } - // Simple get request - return new Response('Success', 200); + if ($request->getMethod() == 'POST') { + $mappedFileNames = array_map(function($f) { + if(!isset($f)) { return 'NULL'; } + return $f->getClientOriginalName(); + }, $request->files->all()); + return new Response('Uploaded files: '.implode(',', $mappedFileNames), 201); + } else if ($request->getMethod() == 'GET') { + // Simple get request + return new Response('Success', 200); + } } } From 722739276a86a69421aaf69f5816c0b4bc788eb2 Mon Sep 17 00:00:00 2001 From: dnna Date: Sat, 25 Aug 2018 21:23:35 +0300 Subject: [PATCH 11/15] Fix CS --- tests/SymfonyMocks/Kernel.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/SymfonyMocks/Kernel.php b/tests/SymfonyMocks/Kernel.php index 4eea442..e9c20c3 100644 --- a/tests/SymfonyMocks/Kernel.php +++ b/tests/SymfonyMocks/Kernel.php @@ -44,12 +44,14 @@ public function handle(Request $request) } if ($request->getMethod() == 'POST') { - $mappedFileNames = array_map(function($f) { - if(!isset($f)) { return 'NULL'; } + $mappedFileNames = array_map(function ($f) { + if (!isset($f)) { + return 'NULL'; + } return $f->getClientOriginalName(); }, $request->files->all()); return new Response('Uploaded files: '.implode(',', $mappedFileNames), 201); - } else if ($request->getMethod() == 'GET') { + } elseif ($request->getMethod() == 'GET') { // Simple get request return new Response('Success', 200); } From 30ca731936693ad62fba9a1d53b4a2bad2f382ff Mon Sep 17 00:00:00 2001 From: dnna Date: Sat, 25 Aug 2018 22:02:10 +0300 Subject: [PATCH 12/15] Add POST JSON test --- tests/SymfonyBootstrapTest.php | 47 ++++++++++++++++++++++------------ tests/SymfonyMocks/Kernel.php | 21 ++++++++++----- 2 files changed, 45 insertions(+), 23 deletions(-) diff --git a/tests/SymfonyBootstrapTest.php b/tests/SymfonyBootstrapTest.php index 0ce4dba..ef5ad13 100644 --- a/tests/SymfonyBootstrapTest.php +++ b/tests/SymfonyBootstrapTest.php @@ -9,15 +9,6 @@ class SymfonyBootstrapTest extends TestCase { - private function getMockedRequest() - { - $request = $this - ->getMockBuilder(ServerRequestInterface::class) - ->getMock(); - $request->method('getHeader')->with('Cookie')->willReturn([]); - $request->method('getQueryParams')->willReturn([]); - return $request; - } /** * @runInSeparateProcess @@ -28,7 +19,9 @@ public function testGetRequest() $bridge = new HttpKernel(); $bridge->bootstrap('Symfony', 'test', true); - $request = $this->getMockedRequest(); + $request = $this->getMockBuilder(ServerRequestInterface::class)->getMock(); + $request->method('getHeader')->with('Cookie')->willReturn([]); + $request->method('getQueryParams')->willReturn([]); $request->method('getUploadedFiles')->willReturn([]); $request->method('getMethod')->willReturn('GET'); @@ -46,23 +39,21 @@ public function testFileUpload() $bridge = new HttpKernel(); $bridge->bootstrap('Symfony', 'test', true); - $fileOK = $this - ->getMockBuilder(UploadedFileInterface::class) - ->getMock(); + $fileOK = $this->getMockBuilder(UploadedFileInterface::class)->getMock(); $fileOK->method('getClientFilename')->willReturn('testOK.pdf'); $fileOK->method('getClientMediaType')->willReturn('pdf'); $fileOK->method('getSize')->willReturn(1000); $fileOK->method('getError')->willReturn(UPLOAD_ERR_OK); - $fileErr = $this - ->getMockBuilder(UploadedFileInterface::class) - ->getMock(); + $fileErr = $this->getMockBuilder(UploadedFileInterface::class)->getMock(); $fileErr->method('getClientFilename')->willReturn('testErr.pdf'); $fileErr->method('getClientMediaType')->willReturn('pdf'); $fileErr->method('getSize')->willReturn(0); $fileErr->method('getError')->willReturn(UPLOAD_ERR_NO_FILE); - $request = $this->getMockedRequest(); + $request = $this->getMockBuilder(ServerRequestInterface::class)->getMock(); + $request->method('getHeader')->with('Cookie')->willReturn([]); + $request->method('getQueryParams')->willReturn([]); $request->method('getUploadedFiles')->willReturn([$fileOK, $fileErr]); $request->method('getMethod')->willReturn('POST'); @@ -70,4 +61,26 @@ public function testFileUpload() $this->assertEquals(201, $response->getStatusCode()); $this->assertEquals('Uploaded files: testOK.pdf,NULL', (string)$response->getBody()); } + + /** + * @runInSeparateProcess + */ + public function testPostJSON() + { + putenv('APP_KERNEL_NAMESPACE=PHPPM\\Tests\\SymfonyMocks\\'); + $bridge = new HttpKernel(); + $bridge->bootstrap('Symfony', 'test', true); + + $_SERVER["CONTENT_TYPE"] = 'application/json'; + $request = $this->getMockBuilder(ServerRequestInterface::class)->getMock(); + $request->method('getHeader')->with('Cookie')->willReturn([]); + $request->method('getQueryParams')->willReturn([]); + $request->method('getUploadedFiles')->willReturn([]); + $request->method('getBody')->willReturn('{"some_json_array":[{"map1":"value1"},{"map2":"value2"}]}'); + $request->method('getMethod')->willReturn('POST'); + + $response = $bridge->handle($request); + $this->assertEquals(201, $response->getStatusCode()); + $this->assertEquals('Received JSON: {"some_json_array":[{"map1":"value1"},{"map2":"value2"}]}', (string)$response->getBody()); + } } diff --git a/tests/SymfonyMocks/Kernel.php b/tests/SymfonyMocks/Kernel.php index e9c20c3..c3594c3 100644 --- a/tests/SymfonyMocks/Kernel.php +++ b/tests/SymfonyMocks/Kernel.php @@ -44,13 +44,22 @@ public function handle(Request $request) } if ($request->getMethod() == 'POST') { - $mappedFileNames = array_map(function ($f) { - if (!isset($f)) { - return 'NULL'; + if(count($request->files->all()) > 0) { + $mappedFileNames = array_map(function ($f) { + if (!isset($f)) { + return 'NULL'; + } + return $f->getClientOriginalName(); + }, $request->files->all()); + return new Response('Uploaded files: '.implode(',', $mappedFileNames), 201); + } + if($request->getContentType() == 'json') { + $body = json_decode($request->getContent(), true); + if ($request->getContent() == null || !$body) { + throw new \Exception('Invalid JSON body'); } - return $f->getClientOriginalName(); - }, $request->files->all()); - return new Response('Uploaded files: '.implode(',', $mappedFileNames), 201); + return new Response('Received JSON: '.$request->getContent(), 201); + } } elseif ($request->getMethod() == 'GET') { // Simple get request return new Response('Success', 200); From 0956816218f5b8d15b347c066473a8f94db3310f Mon Sep 17 00:00:00 2001 From: dnna Date: Sat, 25 Aug 2018 22:06:03 +0300 Subject: [PATCH 13/15] Fix CS --- tests/SymfonyMocks/Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/SymfonyMocks/Kernel.php b/tests/SymfonyMocks/Kernel.php index c3594c3..0ea9466 100644 --- a/tests/SymfonyMocks/Kernel.php +++ b/tests/SymfonyMocks/Kernel.php @@ -44,7 +44,7 @@ public function handle(Request $request) } if ($request->getMethod() == 'POST') { - if(count($request->files->all()) > 0) { + if (count($request->files->all()) > 0) { $mappedFileNames = array_map(function ($f) { if (!isset($f)) { return 'NULL'; @@ -53,7 +53,7 @@ public function handle(Request $request) }, $request->files->all()); return new Response('Uploaded files: '.implode(',', $mappedFileNames), 201); } - if($request->getContentType() == 'json') { + if ($request->getContentType() == 'json') { $body = json_decode($request->getContent(), true); if ($request->getContent() == null || !$body) { throw new \Exception('Invalid JSON body'); From 2221c6e7c76d7aa74bec6f44749117e013f6a871 Mon Sep 17 00:00:00 2001 From: dnna Date: Sat, 25 Aug 2018 22:06:38 +0300 Subject: [PATCH 14/15] Remove mockery as its not needed --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index eae2ca8..4d922c5 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,6 @@ "ringcentral/psr7": "^1.2" }, "require-dev": { - "mockery/mockery": "^1.0", "phpunit/phpunit": "^5.7" }, "autoload": { From bd5ddc38668d39bda33c96097e0559bb75b2e298 Mon Sep 17 00:00:00 2001 From: dnna Date: Sun, 26 Aug 2018 02:45:13 +0300 Subject: [PATCH 15/15] Add extra sanity check in getBundles and getContainer --- tests/SymfonyMocks/Kernel.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/SymfonyMocks/Kernel.php b/tests/SymfonyMocks/Kernel.php index 0ea9466..6e1c75e 100644 --- a/tests/SymfonyMocks/Kernel.php +++ b/tests/SymfonyMocks/Kernel.php @@ -26,11 +26,19 @@ public function initializeContainer() public function getBundles() { + if (!$this->bundlesInitialized) { + throw new \Exception('Bundles not initialized'); + } + return []; } public function getContainer() { + if (!$this->containerInitialized) { + throw new \Exception('Container not initialized'); + } + return new Container(); }