Skip to content

Commit de37077

Browse files
tjwiebellbbatsche
authored andcommitted
- Add unit test for UpwardControllerFactory (#7)
1 parent ae0910e commit de37077

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\UpwardConnector\Test\Unit\Controller;
9+
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
use Magento\Framework\App\RequestInterface;
12+
use Magento\Framework\ObjectManagerInterface;
13+
use Magento\Upward\Controller as UpwardController;
14+
use Magento\UpwardConnector\Controller\UpwardControllerFactory;
15+
16+
class UpwardControllerFactoryTest extends \PHPUnit\Framework\TestCase
17+
{
18+
/**
19+
* @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
20+
*/
21+
private $config;
22+
23+
/**
24+
* @var ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
25+
*/
26+
private $objectManager;
27+
28+
/**
29+
* @var UpwardControllerFactory
30+
*/
31+
private $upwardControllerFactory;
32+
33+
protected function setUp()
34+
{
35+
$objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
36+
$this->objectManager = $this->createMock(ObjectManagerInterface::class);
37+
$this->config = $this->createMock(ScopeConfigInterface::class);
38+
$this->upwardControllerFactory = $objectManagerHelper->getObject(UpwardControllerFactory::class, [
39+
'objectManager' => $this->objectManager,
40+
'config' => $this->config
41+
]);
42+
}
43+
44+
public function testCreateWillReturn()
45+
{
46+
$request = $this->createMock(RequestInterface::class);
47+
$upwardControllerMock = $this->createMock(UpwardController::class);
48+
$upwardConfig = 'upward/config/path';
49+
$this->config->expects($this->once())
50+
->method('getValue')
51+
->with(UpwardControllerFactory::UPWARD_CONFIG_PATH, 'default')
52+
->willReturn($upwardConfig);
53+
$this->objectManager->expects($this->once())
54+
->method('create')
55+
->with(UpwardController::class, compact('request', 'upwardConfig'))
56+
->willReturn($upwardControllerMock);
57+
58+
$this->assertSame($upwardControllerMock, $this->upwardControllerFactory->create($request));
59+
}
60+
61+
public function testCreateWillThrow()
62+
{
63+
$requestMock = $this->createMock(RequestInterface::class);
64+
$this->config->expects($this->once())
65+
->method('getValue')
66+
->with(UpwardControllerFactory::UPWARD_CONFIG_PATH, 'default')
67+
->willReturn(null);
68+
$this->objectManager->expects($this->never())->method('create');
69+
70+
$this->expectException(\RuntimeException::class);
71+
$this->expectExceptionMessage('Path to UPWARD configuration file not set.');
72+
$this->upwardControllerFactory->create($requestMock);
73+
74+
}
75+
}

0 commit comments

Comments
 (0)