Code Duplication    Length = 73-73 lines in 3 locations

tests/Http/Controllers/ValidateControllerTest.php 3 locations

@@ 613-685 (lines=73) @@
610
        $this->assertEquals('authSuccessResponse called', $method->invokeArgs($controller, [$request, false, false]));
611
    }
612
613
    public function testCasValidateWithValidTicketAndServiceAndPgtButCallPgtUrlFailed()
614
    {
615
        $request          = $this->getValidRequest('http://app1.com/pgtCallback');
616
        $user             = Mockery::mock(User::class)
617
            ->shouldReceive('getName')
618
            ->andReturn('test_user')
619
            ->once()
620
            ->getMock();
621
        $ticket           = Mockery::mock(Ticket::class)
622
            ->shouldReceive('isProxy')
623
            ->andReturn(false)
624
            ->times(2)
625
            ->shouldReceive('getAttribute')
626
            ->withArgs(['service_url'])
627
            ->andReturn('http://leo108.com')
628
            ->once()
629
            ->shouldReceive('getAttribute')
630
            ->withArgs(['user'])
631
            ->andReturn($user)
632
            ->times(2)
633
            ->getMock();
634
        $ticketRepository = Mockery::mock(TicketRepository::class)
635
            ->shouldReceive('getByTicket')
636
            ->andReturn($ticket)
637
            ->once()
638
            ->shouldReceive('invalidTicket')
639
            ->once()
640
            ->getMock();
641
        app()->instance(TicketRepository::class, $ticketRepository);
642
        $pgTicketRepository = Mockery::mock(PGTicketRepository::class)
643
            ->shouldReceive('applyTicket')
644
            ->andReturn('some string')
645
            ->once()
646
            ->getMock();
647
        app()->instance(PGTicketRepository::class, $pgTicketRepository);
648
        $ticketGenerator = Mockery::mock(TicketGenerator::class)
649
            ->shouldReceive('generateOne')
650
            ->andReturn('pgtiou string')
651
            ->once()
652
            ->getMock();
653
        app()->instance(TicketGenerator::class, $ticketGenerator);
654
        $pgtCaller = Mockery::mock(PGTCaller::class)
655
            ->shouldReceive('call')
656
            ->andReturn(false)
657
            ->once()
658
            ->getMock();
659
        app()->instance(PGTCaller::class, $pgtCaller);
660
        $controller = $this->initController()
661
            ->makePartial()
662
            ->shouldAllowMockingProtectedMethods()
663
            ->shouldReceive('lockTicket')
664
            ->andReturn(true)
665
            ->once()
666
            ->shouldReceive('unlockTicket')
667
            ->once()
668
            ->shouldReceive('authSuccessResponse')
669
            ->andReturnUsing(
670
                function ($name, $format, $attributes, $proxies, $iou) {
671
                    $this->assertEquals('test_user', $name);
672
                    $this->assertEmpty($attributes);
673
                    $this->assertEquals('JSON', $format);
674
                    $this->assertEmpty($proxies);
675
                    $this->assertNull($iou);
676
677
                    return 'authSuccessResponse called';
678
                }
679
            )
680
            ->once()
681
            ->getMock();
682
683
        $method = self::getNonPublicMethod($controller, 'casValidate');
684
        $this->assertEquals('authSuccessResponse called', $method->invokeArgs($controller, [$request, false, false]));
685
    }
686
687
    public function testCasValidateWithValidTicketAndServiceAndPgtButCallPgtUrlSuccess()
688
    {
@@ 687-759 (lines=73) @@
684
        $this->assertEquals('authSuccessResponse called', $method->invokeArgs($controller, [$request, false, false]));
685
    }
686
687
    public function testCasValidateWithValidTicketAndServiceAndPgtButCallPgtUrlSuccess()
688
    {
689
        $request          = $this->getValidRequest('http://app1.com/pgtCallback');
690
        $user             = Mockery::mock(User::class)
691
            ->shouldReceive('getName')
692
            ->andReturn('test_user')
693
            ->once()
694
            ->getMock();
695
        $ticket           = Mockery::mock(Ticket::class)
696
            ->shouldReceive('isProxy')
697
            ->andReturn(false)
698
            ->times(2)
699
            ->shouldReceive('getAttribute')
700
            ->withArgs(['service_url'])
701
            ->andReturn('http://leo108.com')
702
            ->once()
703
            ->shouldReceive('getAttribute')
704
            ->withArgs(['user'])
705
            ->andReturn($user)
706
            ->times(2)
707
            ->getMock();
708
        $ticketRepository = Mockery::mock(TicketRepository::class)
709
            ->shouldReceive('getByTicket')
710
            ->andReturn($ticket)
711
            ->once()
712
            ->shouldReceive('invalidTicket')
713
            ->once()
714
            ->getMock();
715
        app()->instance(TicketRepository::class, $ticketRepository);
716
        $pgTicketRepository = Mockery::mock(PGTicketRepository::class)
717
            ->shouldReceive('applyTicket')
718
            ->andReturn('some string')
719
            ->once()
720
            ->getMock();
721
        app()->instance(PGTicketRepository::class, $pgTicketRepository);
722
        $ticketGenerator = Mockery::mock(TicketGenerator::class)
723
            ->shouldReceive('generateOne')
724
            ->andReturn('pgtiou string')
725
            ->once()
726
            ->getMock();
727
        app()->instance(TicketGenerator::class, $ticketGenerator);
728
        $pgtCaller = Mockery::mock(PGTCaller::class)
729
            ->shouldReceive('call')
730
            ->andReturn(true)
731
            ->once()
732
            ->getMock();
733
        app()->instance(PGTCaller::class, $pgtCaller);
734
        $controller = $this->initController()
735
            ->makePartial()
736
            ->shouldAllowMockingProtectedMethods()
737
            ->shouldReceive('lockTicket')
738
            ->andReturn(true)
739
            ->once()
740
            ->shouldReceive('unlockTicket')
741
            ->once()
742
            ->shouldReceive('authSuccessResponse')
743
            ->andReturnUsing(
744
                function ($name, $format, $attributes, $proxies, $iou) {
745
                    $this->assertEquals('test_user', $name);
746
                    $this->assertEmpty($attributes);
747
                    $this->assertEquals('JSON', $format);
748
                    $this->assertEmpty($proxies);
749
                    $this->assertEquals('pgtiou string', $iou);
750
751
                    return 'authSuccessResponse called';
752
                }
753
            )
754
            ->once()
755
            ->getMock();
756
757
        $method = self::getNonPublicMethod($controller, 'casValidate');
758
        $this->assertEquals('authSuccessResponse called', $method->invokeArgs($controller, [$request, false, false]));
759
    }
760
761
    public function testCasValidateWithValidProxyTicketAndServiceAndPgtButCallPgtUrlSuccess()
762
    {
@@ 761-833 (lines=73) @@
758
        $this->assertEquals('authSuccessResponse called', $method->invokeArgs($controller, [$request, false, false]));
759
    }
760
761
    public function testCasValidateWithValidProxyTicketAndServiceAndPgtButCallPgtUrlSuccess()
762
    {
763
        $request          = $this->getValidRequest('http://app1.com/pgtCallback');
764
        $user             = Mockery::mock(User::class)
765
            ->shouldReceive('getName')
766
            ->andReturn('test_user')
767
            ->once()
768
            ->getMock();
769
        $ticket           = Mockery::mock(Ticket::class)
770
            ->shouldReceive('isProxy')
771
            ->andReturn(false)
772
            ->times(2)
773
            ->shouldReceive('getAttribute')
774
            ->withArgs(['service_url'])
775
            ->andReturn('http://leo108.com')
776
            ->once()
777
            ->shouldReceive('getAttribute')
778
            ->withArgs(['user'])
779
            ->andReturn($user)
780
            ->times(2)
781
            ->getMock();
782
        $ticketRepository = Mockery::mock(TicketRepository::class)
783
            ->shouldReceive('getByTicket')
784
            ->andReturn($ticket)
785
            ->once()
786
            ->shouldReceive('invalidTicket')
787
            ->once()
788
            ->getMock();
789
        app()->instance(TicketRepository::class, $ticketRepository);
790
        $pgTicketRepository = Mockery::mock(PGTicketRepository::class)
791
            ->shouldReceive('applyTicket')
792
            ->andReturn('some string')
793
            ->once()
794
            ->getMock();
795
        app()->instance(PGTicketRepository::class, $pgTicketRepository);
796
        $ticketGenerator = Mockery::mock(TicketGenerator::class)
797
            ->shouldReceive('generateOne')
798
            ->andReturn('pgtiou string')
799
            ->once()
800
            ->getMock();
801
        app()->instance(TicketGenerator::class, $ticketGenerator);
802
        $pgtCaller = Mockery::mock(PGTCaller::class)
803
            ->shouldReceive('call')
804
            ->andReturn(true)
805
            ->once()
806
            ->getMock();
807
        app()->instance(PGTCaller::class, $pgtCaller);
808
        $controller = $this->initController()
809
            ->makePartial()
810
            ->shouldAllowMockingProtectedMethods()
811
            ->shouldReceive('lockTicket')
812
            ->andReturn(true)
813
            ->once()
814
            ->shouldReceive('unlockTicket')
815
            ->once()
816
            ->shouldReceive('authSuccessResponse')
817
            ->andReturnUsing(
818
                function ($name, $format, $attributes, $proxies, $iou) {
819
                    $this->assertEquals('test_user', $name);
820
                    $this->assertEmpty($attributes);
821
                    $this->assertEquals('JSON', $format);
822
                    $this->assertEmpty($proxies);
823
                    $this->assertEquals('pgtiou string', $iou);
824
825
                    return 'authSuccessResponse called';
826
                }
827
            )
828
            ->once()
829
            ->getMock();
830
831
        $method = self::getNonPublicMethod($controller, 'casValidate');
832
        $this->assertEquals('authSuccessResponse called', $method->invokeArgs($controller, [$request, false, false]));
833
    }
834
835
    public function testLockTicket()
836
    {