Skip to content

Commit 1d2a23f

Browse files
committed
ACPT-1223: Fix Unit Tests for application-server PR
1 parent 38961d4 commit 1d2a23f

File tree

7 files changed

+53
-33
lines changed

7 files changed

+53
-33
lines changed

app/code/Magento/CustomerGraphQl/Test/Unit/Model/Context/AddUserInfoToContextTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,6 @@ public function testExecuteForCustomer(): void
8484
$this->contextParametersMock
8585
->expects($this->once())
8686
->method('setUserType');
87-
$this->sessionMock
88-
->expects($this->once())
89-
->method('isLoggedIn')
90-
->willReturn(true);
91-
$this->sessionMock
92-
->expects($this->once())
93-
->method('getCustomerData')
94-
->willReturn($this->customerMock);
9587
$this->customerRepositoryMock
9688
->expects($this->once())
9789
->method('getById')

lib/internal/Magento/Framework/Composer/DependencyChecker.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
class DependencyChecker
1818
{
1919
/**
20-
* @var Application
20+
* @var ApplicationFactory
2121
*/
2222
private $applicationFactory;
2323

@@ -29,7 +29,7 @@ class DependencyChecker
2929
/**
3030
* Constructor
3131
*
32-
* @param Application $applicationFactory
32+
* @param ApplicationFactory $applicationFactory
3333
* @param DirectoryList $directoryList
3434
*/
3535
public function __construct(ApplicationFactory $applicationFactory, DirectoryList $directoryList)

lib/internal/Magento/Framework/Composer/Test/Unit/DependencyCheckerTest.php

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,45 @@
88
namespace Magento\Framework\Composer\Test\Unit;
99

1010
use Composer\Console\Application;
11+
use Composer\Console\ApplicationFactory;
1112
use Magento\Framework\App\Filesystem\DirectoryList;
1213
use Magento\Framework\Composer\DependencyChecker;
1314
use PHPUnit\Framework\TestCase;
1415

1516
class DependencyCheckerTest extends TestCase
1617
{
18+
19+
private ApplicationFactory $composerFactory;
20+
21+
private Application $composerApp;
22+
23+
protected function setUp(): void
24+
{
25+
$this->composerFactory = $this->getMockBuilder(ApplicationFactory::class)
26+
->setMethods(['create'])
27+
->disableOriginalConstructor()
28+
->getMock();
29+
30+
$this->composerApp = $this->getMockBuilder(Application::class)
31+
->setMethods(['setAutoExit', 'resetComposer', 'run','__destruct'])
32+
->disableOriginalConstructor()
33+
->getMock();
34+
$this->composerFactory->method('create')->willReturn($this->composerApp);
35+
36+
}
1737
/**
1838
* @return void
1939
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
2040
*/
2141
public function testCheckDependencies(): void
2242
{
23-
$composerApp = $this->getMockBuilder(Application::class)
24-
->setMethods(['setAutoExit', 'resetComposer', 'run','__destruct'])
25-
->disableOriginalConstructor()
26-
->getMock();
43+
2744
$directoryList = $this->createMock(DirectoryList::class);
2845
$directoryList->expects($this->exactly(2))->method('getRoot');
29-
$composerApp->expects($this->once())->method('setAutoExit')->with(false);
30-
$composerApp->expects($this->any())->method('__destruct');
46+
$this->composerApp->expects($this->once())->method('setAutoExit')->with(false);
47+
$this->composerApp->expects($this->any())->method('__destruct');
3148

32-
$composerApp
49+
$this->composerApp
3350
->method('run')
3451
->willReturnOnConsecutiveCalls(
3552
$this->returnCallback(
@@ -52,7 +69,7 @@ function ($input, $buffer) {
5269
)
5370
);
5471

55-
$dependencyChecker = new DependencyChecker($composerApp, $directoryList);
72+
$dependencyChecker = new DependencyChecker($this->composerFactory, $directoryList);
5673
$expected = [
5774
'magento/package-a' => ['magento/package-b', 'magento/package-c'],
5875
'magento/package-b' => ['magento/package-c', 'magento/package-d'],
@@ -69,16 +86,12 @@ function ($input, $buffer) {
6986
*/
7087
public function testCheckDependenciesExcludeSelf(): void
7188
{
72-
$composerApp = $this->getMockBuilder(Application::class)
73-
->setMethods(['setAutoExit', 'resetComposer', 'run','__destruct'])
74-
->disableOriginalConstructor()
75-
->getMock();
7689
$directoryList = $this->createMock(DirectoryList::class);
7790
$directoryList->expects($this->exactly(3))->method('getRoot');
78-
$composerApp->expects($this->once())->method('setAutoExit')->with(false);
79-
$composerApp->expects($this->any())->method('__destruct');
91+
$this->composerApp->expects($this->once())->method('setAutoExit')->with(false);
92+
$this->composerApp->expects($this->any())->method('__destruct');
8093

81-
$composerApp
94+
$this->composerApp
8295
->method('run')
8396
->willReturnOnConsecutiveCalls(
8497
$this->returnCallback(
@@ -109,7 +122,7 @@ function ($input, $buffer) {
109122
)
110123
);
111124

112-
$dependencyChecker = new DependencyChecker($composerApp, $directoryList);
125+
$dependencyChecker = new DependencyChecker($this->composerFactory, $directoryList);
113126
$expected = [
114127
'magento/package-a' => [],
115128
'magento/package-b' => ['magento/package-d'],

lib/internal/Magento/Framework/ObjectManager/Test/Unit/Code/Generator/ProxyTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ protected function setUp(): void
2727
$this->ioObjectMock = $this->createMock(Io::class);
2828
}
2929

30-
public function testGenerate()
30+
public function testGenerasste()
3131
{
3232
require_once __DIR__ . '/_files/Sample.php';
3333
$model = $this->getMockBuilder(Proxy::class)

lib/internal/Magento/Framework/ObjectManager/Test/Unit/Code/Generator/_files/SampleMixedProxy.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ class SampleMixed_Proxy extends SampleMixed implements \Magento\Framework\Object
7171
$this->_subject = clone $this->_getSubject();
7272
}
7373

74+
/**
75+
* Clone proxied instance
76+
*/
77+
public function __debugInfo()
78+
{
79+
return ['i' => $this->_subject];
80+
}
81+
7482
/**
7583
* Get proxied instance
7684
*

lib/internal/Magento/Framework/ObjectManager/Test/Unit/Code/Generator/_files/SampleProxy.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ class Sample_Proxy extends Sample implements \Magento\Framework\ObjectManager\No
7171
$this->_subject = clone $this->_getSubject();
7272
}
7373

74+
/**
75+
* Clone proxied instance
76+
*/
77+
public function __debugInfo()
78+
{
79+
return ['i' => $this->_subject];
80+
}
81+
7482
/**
7583
* Get proxied instance
7684
*

lib/internal/Magento/Framework/Webapi/Test/Unit/Rest/Response/RendererFactoryTest.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function testGet()
6060
$acceptTypes = ['application/json'];
6161

6262
/** Mock request getAcceptTypes method to return specified value. */
63-
$this->_requestMock->expects($this->once())->method('getAcceptTypes')->willReturn($acceptTypes);
63+
$this->_requestMock->expects($this->once())->method('getHeader')->willReturn('application/json');
6464
/** Mock renderer. */
6565
$rendererMock = $this->getMockBuilder(
6666
Json::class
@@ -84,14 +84,14 @@ public function testGet()
8484
*/
8585
public function testGetWithWrongAcceptHttpHeader()
8686
{
87-
/** Mock request to return empty Accept Types. */
88-
$this->_requestMock->expects($this->once())->method('getAcceptTypes')->willReturn('');
87+
/** Mock request to return invalid Accept Types. */
88+
$this->_requestMock->expects($this->once())->method('getHeader')->willReturn('invalid');
8989
try {
9090
$this->_factory->get();
9191
$this->fail("Exception is expected to be raised");
9292
} catch (Exception $e) {
9393
$exceptionMessage = 'Server cannot match any of the given Accept HTTP header media type(s) ' .
94-
'from the request: "" with media types from the config of response renderer.';
94+
'from the request: "invalid" with media types from the config of response renderer.';
9595
$this->assertInstanceOf(Exception::class, $e, 'Exception type is invalid');
9696
$this->assertEquals($exceptionMessage, $e->getMessage(), 'Exception message is invalid');
9797
$this->assertEquals(
@@ -107,9 +107,8 @@ public function testGetWithWrongAcceptHttpHeader()
107107
*/
108108
public function testGetWithWrongRendererClass()
109109
{
110-
$acceptTypes = ['application/json'];
111110
/** Mock request getAcceptTypes method to return specified value. */
112-
$this->_requestMock->expects($this->once())->method('getAcceptTypes')->willReturn($acceptTypes);
111+
$this->_requestMock->expects($this->once())->method('getHeader')->willReturn('application/json');
113112
/** Mock object to return \Magento\Framework\DataObject */
114113
$this->_objectManagerMock->expects(
115114
$this->once()

0 commit comments

Comments
 (0)