Skip to content

Commit 14f55d6

Browse files
committed
Merge remote-tracking branch 'origin/ACP2E-4214' into PR_2025_09_19_flowers
2 parents b7e9c0d + c54a9d5 commit 14f55d6

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework\Test\Unit\App;
9+
10+
use Magento\Framework\App\Bootstrap;
11+
use Magento\Framework\App\ObjectManagerFactory;
12+
use Magento\Framework\AppInterface;
13+
use Magento\Framework\HTTP\PhpEnvironment\Response;
14+
use Magento\Framework\ObjectManagerInterface;
15+
use PHPUnit\Framework\Attributes\CoversClass;
16+
use PHPUnit\Framework\MockObject\MockObject;
17+
use PHPUnit\Framework\TestCase;
18+
use Psr\Log\LoggerInterface;
19+
20+
#[
21+
CoversClass(Bootstrap::class),
22+
]
23+
class BootstrapTest extends TestCase
24+
{
25+
/**
26+
* @var Bootstrap
27+
*/
28+
private $bootstrap;
29+
30+
/**
31+
* @var Response|MockObject
32+
*/
33+
private $responseMock;
34+
35+
protected function setUp(): void
36+
{
37+
$loggerMock = $this->createMock(LoggerInterface::class);
38+
$this->responseMock = $this->createMock(Response::class);
39+
$objectManagerMock = $this->createMock(ObjectManagerInterface::class);
40+
$objectManagerMock->method('get')->willReturnMap(
41+
[
42+
[LoggerInterface::class, $loggerMock],
43+
[Response::class, $this->responseMock],
44+
]
45+
);
46+
$objectManagerFactoryMock = $this->createMock(ObjectManagerFactory::class);
47+
$objectManagerFactoryMock->expects(self::once())->method('create')->willReturn($objectManagerMock);
48+
49+
$initParams = [
50+
'MAGE_REQUIRE_MAINTENANCE' => null,
51+
'MAGE_REQUIRE_IS_INSTALLED' => null,
52+
'MAGE_MODE' => 'default',
53+
];
54+
$this->bootstrap = new Bootstrap(
55+
$objectManagerFactoryMock,
56+
'',
57+
$initParams,
58+
);
59+
}
60+
61+
public function testRunWithException(): void
62+
{
63+
$applicationMock = $this->createMock(AppInterface::class);
64+
$applicationMock->expects(self::once())->method('launch')->willThrowException(new \Exception());
65+
$applicationMock->expects(self::once())->method('catchException')->willReturn(false);
66+
67+
$this->responseMock->expects(self::once())->method('clearHeaders')->willReturnSelf();
68+
$this->responseMock->expects(self::once())->method('setHttpResponseCode')->with(500)->willReturnSelf();
69+
70+
// Throw exception from sendResponse to stop the method execution and prevent the process from termination
71+
$e = new \Exception();
72+
$this->responseMock->expects(self::once())->method('sendResponse')->willThrowException($e);
73+
self::expectExceptionObject($e);
74+
75+
$this->bootstrap->run($applicationMock);
76+
}
77+
}

0 commit comments

Comments
 (0)