Skip to content

Commit 240a19d

Browse files
authored
Merge pull request #517 from magento-performance/ACPT-1223
ACPT-1223: Fix Unit Tests for application-server PR
2 parents 449c6ff + 8f5825f commit 240a19d

File tree

6 files changed

+53
-32
lines changed

6 files changed

+53
-32
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: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,46 @@
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+
parent::setUp();
36+
37+
}
1738
/**
1839
* @return void
1940
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
2041
*/
2142
public function testCheckDependencies(): void
2243
{
23-
$composerApp = $this->getMockBuilder(Application::class)
24-
->setMethods(['setAutoExit', 'resetComposer', 'run','__destruct'])
25-
->disableOriginalConstructor()
26-
->getMock();
44+
2745
$directoryList = $this->createMock(DirectoryList::class);
2846
$directoryList->expects($this->exactly(2))->method('getRoot');
29-
$composerApp->expects($this->once())->method('setAutoExit')->with(false);
30-
$composerApp->expects($this->any())->method('__destruct');
47+
$this->composerApp->expects($this->once())->method('setAutoExit')->with(false);
48+
$this->composerApp->expects($this->any())->method('__destruct');
3149

32-
$composerApp
50+
$this->composerApp
3351
->method('run')
3452
->willReturnOnConsecutiveCalls(
3553
$this->returnCallback(
@@ -52,7 +70,7 @@ function ($input, $buffer) {
5270
)
5371
);
5472

55-
$dependencyChecker = new DependencyChecker($composerApp, $directoryList);
73+
$dependencyChecker = new DependencyChecker($this->composerFactory, $directoryList);
5674
$expected = [
5775
'magento/package-a' => ['magento/package-b', 'magento/package-c'],
5876
'magento/package-b' => ['magento/package-c', 'magento/package-d'],
@@ -69,16 +87,12 @@ function ($input, $buffer) {
6987
*/
7088
public function testCheckDependenciesExcludeSelf(): void
7189
{
72-
$composerApp = $this->getMockBuilder(Application::class)
73-
->setMethods(['setAutoExit', 'resetComposer', 'run','__destruct'])
74-
->disableOriginalConstructor()
75-
->getMock();
7690
$directoryList = $this->createMock(DirectoryList::class);
7791
$directoryList->expects($this->exactly(3))->method('getRoot');
78-
$composerApp->expects($this->once())->method('setAutoExit')->with(false);
79-
$composerApp->expects($this->any())->method('__destruct');
92+
$this->composerApp->expects($this->once())->method('setAutoExit')->with(false);
93+
$this->composerApp->expects($this->any())->method('__destruct');
8094

81-
$composerApp
95+
$this->composerApp
8296
->method('run')
8397
->willReturnOnConsecutiveCalls(
8498
$this->returnCallback(
@@ -109,7 +123,7 @@ function ($input, $buffer) {
109123
)
110124
);
111125

112-
$dependencyChecker = new DependencyChecker($composerApp, $directoryList);
126+
$dependencyChecker = new DependencyChecker($this->composerFactory, $directoryList);
113127
$expected = [
114128
'magento/package-a' => [],
115129
'magento/package-b' => ['magento/package-d'],

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)