Completed
Pull Request — 2.0 (#39)
by Raphaël
01:18
created

ZohoDaoTest::testGetZCRMModule()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Wabel\Zoho\CRM;
4
5
use PHPUnit\Framework\TestCase;
6
use Psr\Log\NullLogger;
7
use Wabel\Zoho\CRM\Service\EntitiesGeneratorService;
8
9
class ZohoDaoTest extends TestCase
10
{
11
12
    /**
13
     * @var ZohoClient
14
     */
15
    private $zohoClient;
16
17 View Code Duplication
    protected function setUp()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
18
    {
19
        $this->zohoClient  = new ZohoClient(
20
            [
21
                'client_id' => getenv('client_id'),
22
                'client_secret' => getenv('client_secret'),
23
                'redirect_uri' => getenv('redirect_uri'),
24
                'currentUserEmail' => getenv('currentUserEmail'),
25
                'applicationLogFilePath' => getenv('applicationLogFilePath'),
26
                'persistence_handler_class' => getenv('persistence_handler_class'),
27
                'token_persistence_path' => getenv('token_persistence_path'),
28
            ],
29
            getenv('timeZone')
0 ignored issues
show
Unused Code introduced by
The call to ZohoClient::__construct() has too many arguments starting with getenv('timeZone').

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
30
        );
31
        $this->entitiesGeneratorService = new EntitiesGeneratorService($this->zohoClient, new NullLogger());
0 ignored issues
show
Bug introduced by
The property entitiesGeneratorService does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
32
    }
33
34
    /**
35
     * @depends Wabel\Zoho\CRM\Service\EntitiesGeneratorServiceTest::testGenerateAll
36
     */
37
    public function testDaoConstructor()
38
    {
39
        $this->assertFileExists(__DIR__.'/DaoGeneratedTest/AccountZohoDao.php');
40
        $this->assertFileExists(__DIR__.'/DaoGeneratedTest/Account.php');
41
        $fullQualifyName = 'Wabel\\Zoho\\CRM\\DaoGeneratedTest\\AccountZohoDao';
42
        include __DIR__.'/DaoGeneratedTest/AccountZohoDao.php';
43
        include __DIR__.'/DaoGeneratedTest/Account.php';
44
        $accountZohoDao =  new $fullQualifyName($this->zohoClient);
45
        $this->assertInstanceOf($fullQualifyName, $accountZohoDao);
46
        return $accountZohoDao;
47
    }
48
49
50
    /**
51
     * @depends testDaoConstructor
52
     */
53
    public function testGetZohoClient(AbstractZohoDao $accountZohoDao)
54
    {
55
        $this->assertInstanceOf('Wabel\Zoho\CRM\ZohoClient', $accountZohoDao->getZohoClient());
56
        $this->assertSame($this->zohoClient->getConfigurations(), $accountZohoDao->getZohoClient()->getConfigurations());
0 ignored issues
show
Bug introduced by
The method getConfigurations() does not seem to exist on object<Wabel\Zoho\CRM\ZohoClient>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
57
    }
58
59
60
    /**
61
     * @depends testDaoConstructor
62
     */
63
    public function testGetFields(AbstractZohoDao $accountZohoDao)
64
    {
65
        $fields = $accountZohoDao->getFields();
66
        $this->assertNotEmpty($accountZohoDao->getFields());
67
        $this->assertContainsOnlyInstancesOf('Wabel\Zoho\CRM\BeanComponents\Field', $fields);
68
    }
69
70
    /**
71
     * @depends testDaoConstructor
72
     */
73
    public function testGetZCRMModule(AbstractZohoDao $accountZohoDao)
74
    {
75
        $this->assertInstanceOf('\ZCRMModule', $accountZohoDao->getZCRMModule());
76
        $this->assertEquals('Accounts', $accountZohoDao->getZCRMModule()->getAPIName());
77
    }
78
79
    /**
80
     * @depends testDaoConstructor
81
     */
82
    public function testGetFieldFromFieldName(AbstractZohoDao $accountZohoDao)
83
    {
84
        $field = $accountZohoDao->getFieldFromFieldName('accountName');
85
        $this->assertInstanceOf('Wabel\Zoho\CRM\BeanComponents\Field', $field);
86
        $this->assertEquals('Account_Name', $field->getApiName());
87
    }
88
89
    /**
90
     * @depends testDaoConstructor
91
     * @param   AbstractZohoDao $accountZohoDao
92
     * @return  ZohoBeanInterface[]
93
     * @throws  Exceptions\ZohoCRMORMException
94
     */
95
    public function testCreateBeans(AbstractZohoDao $accountZohoDao)
96
    {
97
98
        $bean1 = $accountZohoDao->create();
99
        $bean1->setAccountName('Account Name Bean 1');
0 ignored issues
show
Bug introduced by
The method setAccountName() does not seem to exist on object<Wabel\Zoho\CRM\ZohoBeanInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
100
        $bean2 = $accountZohoDao->create();
101
        $bean2->setAccountName('Account Name Bean 2');
0 ignored issues
show
Bug introduced by
The method setAccountName() does not seem to exist on object<Wabel\Zoho\CRM\ZohoBeanInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
102
        $bean3 = $accountZohoDao->create();
103
        $bean3->setAccountName('Account Name Bean 3');
0 ignored issues
show
Bug introduced by
The method setAccountName() does not seem to exist on object<Wabel\Zoho\CRM\ZohoBeanInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
104
        $this->assertTrue($bean1->isDirty('accountName'));
105
        $this->assertTrue($bean2->isDirty('accountName'));
106
        $this->assertTrue($bean3->isDirty('accountName'));
107
        return [$bean1, $bean2, $bean3];
108
    }
109
110
111
    /**
112
     * @depends testCreateBeans
113
     * @param   ZohoBeanInterface[] $beans
114
     * @return  ZohoBeanInterface[]
115
     */
116
    public function testSaveInsert(array $beans)
117
    {
118
        $fullQualifyName = 'Wabel\\Zoho\\CRM\\DaoGeneratedTest\\AccountZohoDao';
119
        /**
120
         * @var $accountZohoDao AbstractZohoDao
121
         */
122
        $accountZohoDao =  new $fullQualifyName($this->zohoClient);
123
        $accountZohoDao->save($beans);
124
        $this->assertFalse($beans[0]->isDirty('accountName'));
125
        $this->assertFalse($beans[1]->isDirty('accountName'));
126
        $this->assertFalse($beans[2]->isDirty('accountName'));
127
        $this->assertNotEmpty($beans[0]->getZohoId());
128
        $this->assertNotEmpty($beans[1]->getZohoId());
129
        $this->assertNotEmpty($beans[2]->getZohoId());
130
        $this->assertEquals($beans[0]->getZohoId(), $beans[0]->getZCRMRecord()->getEntityId());
131
        $this->assertEquals($beans[1]->getZohoId(), $beans[1]->getZCRMRecord()->getEntityId());
132
        $this->assertEquals($beans[2]->getZohoId(), $beans[2]->getZCRMRecord()->getEntityId());
133
        $this->assertEquals('Account Name Bean 1', $beans[0]->getZCRMRecord()->getFieldValue('Account_Name'));
134
        $this->assertEquals('Account Name Bean 2', $beans[1]->getZCRMRecord()->getFieldValue('Account_Name'));
135
        $this->assertEquals('Account Name Bean 3', $beans[2]->getZCRMRecord()->getFieldValue('Account_Name'));
136
        return $beans;
137
    }
138
139
    /**
140
     * @depends testSaveInsert
141
     * @param   ZohoBeanInterface[] $beans
142
     * @return  ZohoBeanInterface[]
143
     */
144
    public function testSaveUpdate(array $beans)
145
    {
146
        $beans[0]->setAccountName('Account Name Bean 1 Modified');
0 ignored issues
show
Bug introduced by
The method setAccountName() does not seem to exist on object<Wabel\Zoho\CRM\ZohoBeanInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
147
        $beans[2]->setAccountName('Account Name Bean 3 Modified');
0 ignored issues
show
Bug introduced by
The method setAccountName() does not seem to exist on object<Wabel\Zoho\CRM\ZohoBeanInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
148
        $this->assertTrue($beans[0]->isDirty('accountName'));
149
        $this->assertTrue($beans[2]->isDirty('accountName'));
150
        $fullQualifyName = 'Wabel\\Zoho\\CRM\\DaoGeneratedTest\\AccountZohoDao';
151
        /**
152
         * @var $accountZohoDao AbstractZohoDao
153
         */
154
        $accountZohoDao =  new $fullQualifyName($this->zohoClient);
155
        $accountZohoDao->save([$beans[0], $beans[2]]);
156
        $this->assertFalse($beans[0]->isDirty('accountName'));
157
        $this->assertFalse($beans[2]->isDirty('accountName'));
158
        $record0 = $this->zohoClient->getRecordById($accountZohoDao->getModule(), $beans[0]->getZohoId());
0 ignored issues
show
Bug introduced by
The method getModule() cannot be called from this context as it is declared protected in class Wabel\Zoho\CRM\AbstractZohoDao.

This check looks for access to methods that are not accessible from the current context.

If you need to make a method accessible to another context you can raise its visibility level in the defining class.

Loading history...
159
        $record2 = $this->zohoClient->getRecordById($accountZohoDao->getModule(), $beans[2]->getZohoId());
0 ignored issues
show
Bug introduced by
The method getModule() cannot be called from this context as it is declared protected in class Wabel\Zoho\CRM\AbstractZohoDao.

This check looks for access to methods that are not accessible from the current context.

If you need to make a method accessible to another context you can raise its visibility level in the defining class.

Loading history...
160
        $this->assertEquals('Account Name Bean 1 Modified', $record0->getFieldValue('Account_Name'));
161
        $this->assertEquals('Account Name Bean 3 Modified', $record2->getFieldValue('Account_Name'));
162
        $beans[1]->setAccountName('Account Name Bean 2 Modified Solo');
0 ignored issues
show
Bug introduced by
The method setAccountName() does not seem to exist on object<Wabel\Zoho\CRM\ZohoBeanInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
163
        //Test Update Owner field
164
        $beans[1]->setOwnerOwnerID(getenv('userid_test'));
165
        $accountZohoDao->save($beans[1]);
166
        $record1 = $this->zohoClient->getRecordById($accountZohoDao->getModule(), $beans[1]->getZohoId());
0 ignored issues
show
Bug introduced by
The method getModule() cannot be called from this context as it is declared protected in class Wabel\Zoho\CRM\AbstractZohoDao.

This check looks for access to methods that are not accessible from the current context.

If you need to make a method accessible to another context you can raise its visibility level in the defining class.

Loading history...
167
        $this->assertEquals('Account Name Bean 2 Modified Solo', $record1->getFieldValue('Account_Name'));
168
        $this->assertEquals(getenv('userid_test'), $record1->getOwner()->getId());
169
        return $beans;
170
    }
171
172
    /**
173
     * @depends testSaveInsert
174
     * @param   ZohoBeanInterface[] $beans
175
     * @throws  Exceptions\ZohoCRMORMException
176
     * @throws  \ZCRMException
177
     */
178
    public function testGetRecords(array $beans)
179
    {
180
        $fullQualifyName = 'Wabel\\Zoho\\CRM\\DaoGeneratedTest\\AccountZohoDao';
181
        /**
182
         * @var $accountZohoDao AbstractZohoDao
183
         */
184
        $accountZohoDao =  new $fullQualifyName($this->zohoClient);
185
        $dateRecentRecords = (new \DateTime())->sub(new \DateInterval('PT30S'));
186
        $beanRecords = $accountZohoDao->getRecords(null, null, null, $dateRecentRecords);
187
        $idsRecord = array_map(
188
            function (ZohoBeanInterface $bean) {
189
                return $bean->getZohoId();
190
            }, $beanRecords
191
        );
192
        $this->assertContains($beans[0]->getZohoId(), $idsRecord);
193
        $this->assertContains($beans[1]->getZohoId(), $idsRecord);
194
        $this->assertContains($beans[2]->getZohoId(), $idsRecord);
195
196
    }
197
198
    /**
199
     * @depends testSaveUpdate
200
     * @param   ZohoBeanInterface[] $beans
201
     * @return  ZohoBeanInterface[]
202
     * @throws  Exceptions\ZohoCRMORMException
203
     * @throws  \ZCRMException
204
     */
205 View Code Duplication
    public function testGetRecordById(array $beans)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
206
    {
207
        $fullQualifyName = 'Wabel\\Zoho\\CRM\\DaoGeneratedTest\\AccountZohoDao';
208
        /**
209
         * @var $accountZohoDao AbstractZohoDao
210
         */
211
        $accountZohoDao =  new $fullQualifyName($this->zohoClient);
212
        $beanRecord = $accountZohoDao->getById($beans[1]->getZohoId());
213
        $this->assertNotSame($beans[1], $beanRecord);
214
        $this->assertEquals($beans[1]->getZohoId(), $beanRecord->getZohoId());
215
        return $beans;
216
    }
217
218
    /**
219
     * @depends testGetRecordById
220
     * @param   ZohoBeanInterface[] $beans
221
     * @return  ZohoBeanInterface
222
     * @throws  Exceptions\ZohoCRMORMException
223
     */
224 View Code Duplication
    public function testDeleteById(array $beans)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
225
    {
226
        $fullQualifyName = 'Wabel\\Zoho\\CRM\\DaoGeneratedTest\\AccountZohoDao';
227
        /**
228
         * @var $accountZohoDao AbstractZohoDao
229
         */
230
        $accountZohoDao =  new $fullQualifyName($this->zohoClient);
231
        $beanDeleted = $accountZohoDao->delete($beans[2]->getZohoId());
232
        $this->assertNotEmpty($beanDeleted);
233
        $this->assertEquals($beans[2]->getZohoId(), $beanDeleted[0]->getZohoId());
234
        return $beans[2];
235
    }
236
237
    /**
238
     * @depends testDeleteById
239
     * @param   ZohoBeanInterface $beanDeleted
240
     * @throws  \ZCRMException
241
     */
242
    public function testGetDeletedRecords(ZohoBeanInterface $beanDeleted)
243
    {
244
        $fullQualifyName = 'Wabel\\Zoho\\CRM\\DaoGeneratedTest\\AccountZohoDao';
245
        /**
246
         * @var $accountZohoDao AbstractZohoDao
247
         */
248
        $dateRecentRecords = (new \DateTime())->sub(new \DateInterval('PT30S'));
249
        $accountZohoDao =  new $fullQualifyName($this->zohoClient);
250
        $trashRecords = $accountZohoDao->getDeletedRecordIds($dateRecentRecords);
251
        $this->assertNotEmpty($trashRecords);
252
        $idsRecordTrash = array_map(
253
            function (\ZCRMTrashRecord $trashRecord) {
254
                return $trashRecord->getEntityId();
255
            }, $trashRecords
256
        );
257
        $this->assertContains($beanDeleted->getZohoId(), $idsRecordTrash);
258
    }
259
260
261
262
    /**
263
     * @depends Wabel\Zoho\CRM\Service\EntitiesGeneratorServiceTest::testGenerateAll
264
     * @return  AbstractZohoDao
265
     */
266
    public function testInitCustomModule()
267
    {
268
        $customModuleSingularName = getenv('custom_module_singular_name');
269
        $this->assertFileExists(__DIR__.'/DaoGeneratedTest/'.$customModuleSingularName.'ZohoDao.php');
270
        $this->assertFileExists(__DIR__.'/DaoGeneratedTest/'.$customModuleSingularName.'.php');
271
        $fullQualifyName = 'Wabel\\Zoho\\CRM\\DaoGeneratedTest\\'.$customModuleSingularName.'ZohoDao';
272
        include __DIR__.'/DaoGeneratedTest/'.$customModuleSingularName.'ZohoDao.php';
273
        include __DIR__.'/DaoGeneratedTest/'.$customModuleSingularName.'.php';
274
        /**
275
         * @var $customZohoDao AbstractZohoDao
276
         */
277
        $customZohoDao =  new $fullQualifyName($this->zohoClient);
278
        return $customZohoDao;
279
    }
280
281
    /**
282
     * @depends testInitCustomModule
283
     * @param   AbstractZohoDao $customZohoDao
284
     * @return  ZohoBeanInterface[]
285
     * @throws  Exceptions\ZohoCRMORMException
286
     */
287
    public function testCustomModuleCreateBeans(AbstractZohoDao $customZohoDao)
288
    {
289
290
        $fieldMandatoryRecordName = $customZohoDao->getFieldFromFieldName(getenv('custom_module_mandatory_field_name'));
291
        $fieldPickList = $customZohoDao->getFieldFromFieldName(getenv('custom_module_picklist_field_name'));
292
        $fieldDate = $customZohoDao->getFieldFromFieldName(getenv('custom_module_date_field_name'));
293
        $fieldText = $customZohoDao->getFieldFromFieldName(getenv('custom_module_text_field_name'));
294
        $bean1 = $customZohoDao->create();
295
        $bean1->{$fieldMandatoryRecordName->getSetter()}('Custom Name Bean 1');
296
        $bean1->{$fieldPickList->getSetter()}(getenv('custom_module_picklist_field_value1'));
297
        $bean1->{$fieldDate->getSetter()}($this->randomDateInRange(new \DateTime(), (new \DateTime())->add(new \DateInterval('P10D'))));
298
        $bean1->{$fieldText->getSetter()}('Custom Text 1');
299
300
        $bean2 = $customZohoDao->create();
301
        $bean2->{$fieldMandatoryRecordName->getSetter()}('Custom Name Bean 2');
302
        $bean2->{$fieldPickList->getSetter()}(getenv('custom_module_picklist_field_value2'));
303
        $bean2->{$fieldDate->getSetter()}($this->randomDateInRange(new \DateTime(), (new \DateTime())->add(new \DateInterval('P10D'))));
304
        $bean2->{$fieldText->getSetter()}('Custom Text 2');
305
306
        $this->assertTrue($bean1->isDirty($fieldMandatoryRecordName->getName()));
307
        $this->assertTrue($bean2->isDirty($fieldMandatoryRecordName->getName()));
308
        $this->assertTrue($bean1->isDirty($fieldPickList->getName()));
309
        $this->assertTrue($bean2->isDirty($fieldPickList->getName()));
310
        $this->assertTrue($bean1->isDirty($fieldDate->getName()));
311
        $this->assertTrue($bean2->isDirty($fieldDate->getName()));
312
        $this->assertTrue($bean1->isDirty($fieldText->getName()));
313
        $this->assertTrue($bean2->isDirty($fieldText->getName()));
314
        return ['dao' => $customZohoDao ,'beans' => [$bean1, $bean2]];
315
    }
316
317
    private function randomDateInRange(\DateTime $start, \DateTime $end)
318
    {
319
        $randomTimestamp = mt_rand($start->getTimestamp(), $end->getTimestamp());
320
        $randomDate = new \DateTime();
321
        $randomDate->setTimestamp($randomTimestamp);
322
        return $randomDate;
323
    }
324
325
    /**
326
     * @depends testCustomModuleCreateBeans
327
     * @param   array $customZohoDaoBeans
328
     * @return  ZohoBeanInterface[]
329
     */
330
    public function testCustomModuleSaveInsert(array $customZohoDaoBeans)
331
    {
332
333
        /**
334
         * @var $customZohoDao AbstractZohoDao
335
         */
336
        $customZohoDao = $customZohoDaoBeans['dao'];
337
338
        /**
339
         * @var $beans ZohoBeanInterface[]
340
         */
341
        $beans = $customZohoDaoBeans['beans'];
342
        $customZohoDao->save($beans);
343
344
        $this->assertFalse($beans[0]->isDirty(getenv('custom_module_mandatory_field_name')));
345
        $this->assertFalse($beans[0]->isDirty(getenv('custom_module_picklist_field_name')));
346
        $this->assertFalse($beans[0]->isDirty(getenv('custom_module_date_field_name')));
347
        $this->assertFalse($beans[0]->isDirty(getenv('custom_module_text_field_name')));
348
        $this->assertFalse($beans[1]->isDirty(getenv('custom_module_mandatory_field_name')));
349
        $this->assertFalse($beans[1]->isDirty(getenv('custom_module_picklist_field_name')));
350
        $this->assertFalse($beans[1]->isDirty(getenv('custom_module_date_field_name')));
351
        $this->assertFalse($beans[1]->isDirty(getenv('custom_module_text_field_name')));
352
353
        $this->assertNotEmpty($beans[0]->getZohoId());
354
        $this->assertNotEmpty($beans[1]->getZohoId());
355
356
        $this->assertEquals($beans[0]->getZohoId(), $beans[0]->getZCRMRecord()->getEntityId());
357
        $this->assertEquals($beans[1]->getZohoId(), $beans[1]->getZCRMRecord()->getEntityId());
358
359
        return ['dao' => $customZohoDao ,'beans' => $beans];
360
    }
361
362
    /**
363
     * @depends testCustomModuleSaveInsert
364
     * @param   array $customZohoDaoBeans
365
     * @throws  \Exception
366
     */
367
    public function testCustomModuleSaveUpdate(array $customZohoDaoBeans)
368
    {
369
370
        /**
371
         * @var $customZohoDao AbstractZohoDao
372
         */
373
        $customZohoDao = $customZohoDaoBeans['dao'];
374
375
        /**
376
         * @var $beans ZohoBeanInterface[]
377
         */
378
        $beans = $customZohoDaoBeans['beans'];
379
380
        $fieldMandatoryRecordName = $customZohoDao->getFieldFromFieldName(getenv('custom_module_mandatory_field_name'));
381
        $fieldPickList = $customZohoDao->getFieldFromFieldName(getenv('custom_module_picklist_field_name'));
382
        $fieldDate = $customZohoDao->getFieldFromFieldName(getenv('custom_module_date_field_name'));
383
        $fieldText = $customZohoDao->getFieldFromFieldName(getenv('custom_module_text_field_name'));
384
385
        $beans[0]->{$fieldMandatoryRecordName->getSetter()}('Custom Name Bean 1 - Modified');
386
        $beans[0]->{$fieldPickList->getSetter()}(getenv('custom_module_picklist_field_value2'));
387
        $beans[0]->{$fieldDate->getSetter()}($this->randomDateInRange(new \DateTime(), (new \DateTime())->add(new \DateInterval('P10D'))));
388
        $beans[0]->{$fieldText->getSetter()}('Custom Text 1- Modified');
389
390
        $beans[1]->{$fieldMandatoryRecordName->getSetter()}('Custom Name Bean 2 - Modified');
391
        $beans[1]->{$fieldPickList->getSetter()}(getenv('custom_module_picklist_field_value1'));
392
        $beans[1]->{$fieldDate->getSetter()}($this->randomDateInRange(new \DateTime(), (new \DateTime())->add(new \DateInterval('P10D'))));
393
394
        $this->assertTrue($beans[0]->isDirty(getenv('custom_module_mandatory_field_name')));
395
        $this->assertTrue($beans[0]->isDirty(getenv('custom_module_picklist_field_name')));
396
        $this->assertTrue($beans[0]->isDirty(getenv('custom_module_date_field_name')));
397
        $this->assertTrue($beans[0]->isDirty(getenv('custom_module_text_field_name')));
398
399
        $this->assertTrue($beans[1]->isDirty(getenv('custom_module_mandatory_field_name')));
400
        $this->assertTrue($beans[1]->isDirty(getenv('custom_module_picklist_field_name')));
401
        $this->assertTrue($beans[1]->isDirty(getenv('custom_module_date_field_name')));
402
        $this->assertFalse($beans[1]->isDirty(getenv('custom_module_text_field_name')));;
403
404
        $customZohoDao->save($beans);
405
406
        $this->assertFalse($beans[0]->isDirty(getenv('custom_module_mandatory_field_name')));
407
        $this->assertFalse($beans[0]->isDirty(getenv('custom_module_picklist_field_name')));
408
        $this->assertFalse($beans[0]->isDirty(getenv('custom_module_date_field_name')));
409
        $this->assertFalse($beans[0]->isDirty(getenv('custom_module_text_field_name')));
410
411
        $this->assertFalse($beans[1]->isDirty(getenv('custom_module_mandatory_field_name')));
412
        $this->assertFalse($beans[1]->isDirty(getenv('custom_module_picklist_field_name')));
413
        $this->assertFalse($beans[1]->isDirty(getenv('custom_module_date_field_name')));
414
415
        $record0 = $this->zohoClient->getRecordById($customZohoDao->getModule(), $beans[0]->getZohoId());
0 ignored issues
show
Bug introduced by
The method getModule() cannot be called from this context as it is declared protected in class Wabel\Zoho\CRM\AbstractZohoDao.

This check looks for access to methods that are not accessible from the current context.

If you need to make a method accessible to another context you can raise its visibility level in the defining class.

Loading history...
416
        $record1 = $this->zohoClient->getRecordById($customZohoDao->getModule(), $beans[1]->getZohoId());
0 ignored issues
show
Bug introduced by
The method getModule() cannot be called from this context as it is declared protected in class Wabel\Zoho\CRM\AbstractZohoDao.

This check looks for access to methods that are not accessible from the current context.

If you need to make a method accessible to another context you can raise its visibility level in the defining class.

Loading history...
417
418
        $this->assertEquals($beans[0]->{$fieldMandatoryRecordName->getGetter()}(), $record0->getFieldValue($fieldMandatoryRecordName->getApiName()));
419
        $this->assertEquals($beans[0]->{$fieldPickList->getGetter()}(), $record0->getFieldValue($fieldPickList->getApiName()));
420
        $this->assertEquals($beans[0]->{$fieldDate->getGetter()}()->format('Y-m-d'), $record0->getFieldValue($fieldDate->getApiName()));
421
        $this->assertEquals($beans[0]->{$fieldText->getGetter()}(), $record0->getFieldValue($fieldText->getApiName()));
422
423
        $this->assertEquals($beans[1]->{$fieldMandatoryRecordName->getGetter()}(), $record1->getFieldValue($fieldMandatoryRecordName->getApiName()));
424
        $this->assertEquals($beans[1]->{$fieldPickList->getGetter()}(), $record1->getFieldValue($fieldPickList->getApiName()));
425
        $this->assertEquals($beans[1]->{$fieldDate->getGetter()}()->format('Y-m-d'), $record1->getFieldValue($fieldDate->getApiName()));
426
427
    }
428
429
}
430