34
34
use OrangeHRM \Framework \Services ;
35
35
use OrangeHRM \Pim \Api \EmploymentContractAPI ;
36
36
use OrangeHRM \Pim \Dao \EmploymentContractDao ;
37
+ use OrangeHRM \Pim \Dto \PartialEmployeeAttachment ;
37
38
use OrangeHRM \Pim \Service \EmploymentContractService ;
38
39
use OrangeHRM \Tests \Util \EndpointTestCase ;
39
40
use OrangeHRM \Tests \Util \MockObject ;
@@ -326,13 +327,16 @@ public function testUpdateNewContractAttachment(): void
326
327
->getMock ();
327
328
328
329
$ attachTime = new DateTime ();
329
- $ empAttachment = new EmployeeAttachment ();
330
- $ empAttachment ->setAttachment ('test ' );
331
- $ empAttachment ->setAttachId (1 );
332
- $ empAttachment ->setFilename ('attachment.txt ' );
333
- $ empAttachment ->setFileType ('text/plain ' );
334
- $ empAttachment ->setSize (6 );
335
- $ empAttachment ->setAttachedTime ($ attachTime );
330
+ $ empAttachment = new PartialEmployeeAttachment (
331
+ 1 ,
332
+ null ,
333
+ 'attachment.txt ' ,
334
+ 6 ,
335
+ 'text/plain ' ,
336
+ null ,
337
+ null ,
338
+ $ attachTime
339
+ );
336
340
$ empContractDecorator = $ this ->getMockBuilder (EmpContractDecorator::class)
337
341
->onlyMethods (['getContractAttachment ' ])
338
342
->setConstructorArgs ([$ empContract ])
@@ -505,6 +509,7 @@ public function testUpdateDeleteContractAttachment(): void
505
509
[
506
510
'getEmploymentContractDao ' ,
507
511
'getContractAttachment ' ,
512
+ 'getContractAttachmentById ' ,
508
513
'saveContractAttachment ' ,
509
514
'deleteContractAttachment '
510
515
]
@@ -517,19 +522,37 @@ public function testUpdateDeleteContractAttachment(): void
517
522
$ employee = new Employee ();
518
523
$ employee ->setEmpNumber (1 );
519
524
$ contractAttachment = new EmployeeAttachment ();
525
+ $ contractAttachment ->setAttachId (20 );
520
526
$ contractAttachment ->setEmployee ($ employee );
521
527
$ contractAttachment ->setFilename ('attachment.txt ' );
522
528
$ contractAttachment ->setAttachment ('text ' );
523
529
$ contractAttachment ->setFileType ('text/plain ' );
524
530
$ contractAttachment ->setSize (1024 );
525
531
532
+ $ partialContractAttachment = new PartialEmployeeAttachment (
533
+ $ contractAttachment ->getAttachId (),
534
+ null ,
535
+ $ contractAttachment ->getFilename (),
536
+ $ contractAttachment ->getSize (),
537
+ $ contractAttachment ->getFileType (),
538
+ null ,
539
+ null ,
540
+ null
541
+ );
542
+
526
543
$ contractAttachmentMap = [
527
- [1 , $ contractAttachment ],
544
+ [1 , $ partialContractAttachment ],
528
545
[2 , null ],
529
546
];
530
547
$ employmentContractService ->expects ($ this ->once ())
531
548
->method ('getContractAttachment ' )
532
549
->will ($ this ->returnValueMap ($ contractAttachmentMap ));
550
+ $ employmentContractService ->expects ($ this ->once ())
551
+ ->method ('getContractAttachmentById ' )
552
+ ->will ($ this ->returnValueMap ([
553
+ [1 , 20 , $ contractAttachment ],
554
+ [2 , 1 , null ],
555
+ ]));
533
556
$ employmentContractService ->expects ($ this ->once ())
534
557
->method ('deleteContractAttachment ' );
535
558
@@ -546,7 +569,7 @@ public function testUpdateDeleteContractAttachment(): void
546
569
]
547
570
)->onlyMethods (['getEmploymentContractService ' ])
548
571
->getMock ();
549
- $ api ->expects ($ this ->exactly (4 ))
572
+ $ api ->expects ($ this ->exactly (5 ))
550
573
->method ('getEmploymentContractService ' )
551
574
->will ($ this ->returnValue ($ employmentContractService ));
552
575
@@ -590,13 +613,16 @@ public function testUpdateReplaceContractAttachment(): void
590
613
->getMock ();
591
614
592
615
$ attachTime = new DateTime ();
593
- $ empAttachment = new EmployeeAttachment ();
594
- $ empAttachment ->setAttachment ('test ' );
595
- $ empAttachment ->setAttachId (1 );
596
- $ empAttachment ->setFilename ('attachment.txt ' );
597
- $ empAttachment ->setFileType ('text/plain ' );
598
- $ empAttachment ->setSize (6 );
599
- $ empAttachment ->setAttachedTime ($ attachTime );
616
+ $ empAttachment = new PartialEmployeeAttachment (
617
+ 1 ,
618
+ null ,
619
+ 'attachment.txt ' ,
620
+ 6 ,
621
+ 'text/plain ' ,
622
+ null ,
623
+ null ,
624
+ $ attachTime
625
+ );
600
626
$ empContractDecorator = $ this ->getMockBuilder (EmpContractDecorator::class)
601
627
->onlyMethods (['getContractAttachment ' ])
602
628
->setConstructorArgs ([$ empContract ])
@@ -616,6 +642,7 @@ public function testUpdateReplaceContractAttachment(): void
616
642
[
617
643
'getEmploymentContractDao ' ,
618
644
'getContractAttachment ' ,
645
+ 'getContractAttachmentById ' ,
619
646
'saveContractAttachment ' ,
620
647
'deleteContractAttachment '
621
648
]
@@ -628,19 +655,37 @@ public function testUpdateReplaceContractAttachment(): void
628
655
$ employee = new Employee ();
629
656
$ employee ->setEmpNumber (1 );
630
657
$ contractAttachment = new EmployeeAttachment ();
658
+ $ contractAttachment ->setAttachId (30 );
631
659
$ contractAttachment ->setEmployee ($ employee );
632
660
$ contractAttachment ->setFilename ('attachment.txt ' );
633
661
$ contractAttachment ->setAttachment ('text ' );
634
662
$ contractAttachment ->setFileType ('text/plain ' );
635
663
$ contractAttachment ->setSize (1024 );
636
664
665
+ $ partialContractAttachment = new PartialEmployeeAttachment (
666
+ $ contractAttachment ->getAttachId (),
667
+ null ,
668
+ $ contractAttachment ->getFilename (),
669
+ $ contractAttachment ->getSize (),
670
+ $ contractAttachment ->getFileType (),
671
+ null ,
672
+ null ,
673
+ null
674
+ );
675
+
637
676
$ contractAttachmentMap = [
638
- [1 , $ contractAttachment ],
677
+ [1 , $ partialContractAttachment ],
639
678
[2 , null ],
640
679
];
641
680
$ employmentContractService ->expects ($ this ->once ())
642
681
->method ('getContractAttachment ' )
643
682
->will ($ this ->returnValueMap ($ contractAttachmentMap ));
683
+ $ employmentContractService ->expects ($ this ->once ())
684
+ ->method ('getContractAttachmentById ' )
685
+ ->will ($ this ->returnValueMap ([
686
+ [1 , 30 , $ contractAttachment ],
687
+ [2 , 1 , null ],
688
+ ]));
644
689
$ employmentContractService ->expects ($ this ->once ())
645
690
->method ('saveContractAttachment ' );
646
691
@@ -674,7 +719,7 @@ public function testUpdateReplaceContractAttachment(): void
674
719
]
675
720
)->onlyMethods (['getEmploymentContractService ' , 'getUserRoleManager ' ])
676
721
->getMock ();
677
- $ api ->expects ($ this ->exactly (4 ))
722
+ $ api ->expects ($ this ->exactly (5 ))
678
723
->method ('getEmploymentContractService ' )
679
724
->will ($ this ->returnValue ($ employmentContractService ));
680
725
$ api ->expects ($ this ->exactly (2 ))
0 commit comments