5
5
*/
6
6
declare (strict_types=1 );
7
7
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
+
8
25
namespace Magento \Framework \Indexer \Test \Unit \Handler ;
9
26
10
27
use Magento \Framework \Indexer \Handler \AttributeHandler ;
16
33
*/
17
34
class AttributeHandlerTest extends \PHPUnit \Framework \TestCase
18
35
{
36
+ /**
37
+ * Static field responsible for mocking built-in method_exists function result.
38
+ *
39
+ * @var bool
40
+ */
41
+ public static $ methodExits = false ;
42
+
19
43
/**
20
44
* @var SourceProviderInterface|\PHPUnit_Framework_MockObject_MockObject
21
45
*/
@@ -33,14 +57,60 @@ protected function setUp()
33
57
{
34
58
$ this ->source = $ this ->getMockBuilder (SourceProviderInterface::class)
35
59
->disableOriginalConstructor ()
60
+ ->setMethods (['joinAttribute ' ])
36
61
->getMockForAbstractClass ();
37
62
38
63
$ objectManager = new ObjectManager ($ this );
39
64
40
65
$ this ->subject = $ objectManager ->getObject (AttributeHandler::class);
41
66
}
42
67
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 ()
44
114
{
45
115
$ alias = 'e ' ;
46
116
$ fieldInfo = [
@@ -53,8 +123,7 @@ public function testPrepareSql()
53
123
];
54
124
$ this ->source ->expects ($ this ->once ())
55
125
->method ('addFieldToSelect ' )
56
- ->with ('is_approved ' , 'left ' )
57
- ->willReturnSelf ();
126
+ ->with ('is_approved ' , 'left ' );
58
127
59
128
$ this ->subject ->prepareSql ($ this ->source , $ alias , $ fieldInfo );
60
129
}
0 commit comments