Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 0933c7a

Browse files
committed
MAGETWO-90109: Customer Grid Indexer not working #10838
1 parent 4a2284c commit 0933c7a

File tree

1 file changed

+72
-3
lines changed

1 file changed

+72
-3
lines changed

lib/internal/Magento/Framework/Indexer/Test/Unit/Handler/AttributeHandlerTest.php

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@
55
*/
66
declare(strict_types=1);
77

8+
// @codingStandardsIgnoreStart
9+
namespace Magento\Framework\Indexer\Handler;
10+
11+
/**
12+
* Mock method for built-in function method_exists.
13+
*
14+
* @param mixed $object
15+
* @param string $method_name
16+
* @return bool
17+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
18+
*/
19+
function method_exists($object, $method_name)
20+
{
21+
return \Magento\Framework\Indexer\Test\Unit\Handler\AttributeHandlerTest::$methodExits;
22+
}
23+
// codingStandardsIgnoreEnd
24+
825
namespace Magento\Framework\Indexer\Test\Unit\Handler;
926

1027
use Magento\Framework\Indexer\Handler\AttributeHandler;
@@ -16,6 +33,13 @@
1633
*/
1734
class AttributeHandlerTest extends \PHPUnit\Framework\TestCase
1835
{
36+
/**
37+
* Static field responsible for mocking built-in method_exists function result.
38+
*
39+
* @var bool
40+
*/
41+
public static $methodExits = false;
42+
1943
/**
2044
* @var SourceProviderInterface|\PHPUnit_Framework_MockObject_MockObject
2145
*/
@@ -33,14 +57,60 @@ protected function setUp()
3357
{
3458
$this->source = $this->getMockBuilder(SourceProviderInterface::class)
3559
->disableOriginalConstructor()
60+
->setMethods(['joinAttribute'])
3661
->getMockForAbstractClass();
3762

3863
$objectManager = new ObjectManager($this);
3964

4065
$this->subject = $objectManager->getObject(AttributeHandler::class);
4166
}
4267

43-
public function testPrepareSql()
68+
public function testPrepareSqlWithBindAndMissingJoinAttributeMethod()
69+
{
70+
$alias = 'e';
71+
$fieldInfo = [
72+
'name' => 'is_approved',
73+
'origin' => 'is_approved',
74+
'type' => 'searchable',
75+
'dataType' => 'varchar',
76+
'entity' => 'customer',
77+
'bind' => '',
78+
];
79+
80+
self::$methodExits = false;
81+
$this->source->expects($this->never())->method('joinAttribute');
82+
83+
$this->subject->prepareSql($this->source, $alias, $fieldInfo);
84+
}
85+
86+
public function testPrepareSqlWithBindAndExistingJoinAttributeMethod()
87+
{
88+
$alias = 'e';
89+
$fieldInfo = [
90+
'name' => 'is_approved',
91+
'origin' => 'is_approved',
92+
'type' => 'searchable',
93+
'dataType' => 'varchar',
94+
'entity' => 'customer',
95+
'bind' => '',
96+
];
97+
98+
self::$methodExits = true;
99+
$this->source->expects($this->once())
100+
->method('joinAttribute')
101+
->with(
102+
$fieldInfo['name'],
103+
$fieldInfo['entity'] . '/' . $fieldInfo['origin'],
104+
$fieldInfo['bind'],
105+
null,
106+
'left'
107+
)
108+
->willReturnSelf();
109+
110+
$this->subject->prepareSql($this->source, $alias, $fieldInfo);
111+
}
112+
113+
public function testPrepareSqlWithoutBind()
44114
{
45115
$alias = 'e';
46116
$fieldInfo = [
@@ -53,8 +123,7 @@ public function testPrepareSql()
53123
];
54124
$this->source->expects($this->once())
55125
->method('addFieldToSelect')
56-
->with('is_approved', 'left')
57-
->willReturnSelf();
126+
->with('is_approved', 'left');
58127

59128
$this->subject->prepareSql($this->source, $alias, $fieldInfo);
60129
}

0 commit comments

Comments
 (0)