gluon-web-remote

Web remote Administration for big size of gluon routers
git clone git://archive.git.mtrnord.blog/MTRNord/gluon-web-remote.git
Log | Files | Refs | README

DoublerSpec.php (4535B)


      1 <?php
      2 
      3 namespace spec\Prophecy\Doubler;
      4 
      5 use PhpSpec\ObjectBehavior;
      6 use Prophecy\Argument;
      7 
      8 class DoublerSpec extends ObjectBehavior
      9 {
     10     /**
     11      * @param \Prophecy\Doubler\Generator\ClassMirror  $mirror
     12      * @param \Prophecy\Doubler\Generator\ClassCreator $creator
     13      * @param \Prophecy\Doubler\NameGenerator          $namer
     14      */
     15     function let($mirror, $creator, $namer)
     16     {
     17         $this->beConstructedWith($mirror, $creator, $namer);
     18     }
     19 
     20     function it_does_not_have_patches_by_default()
     21     {
     22         $this->getClassPatches()->shouldHaveCount(0);
     23     }
     24 
     25     /**
     26      * @param \Prophecy\Doubler\ClassPatch\ClassPatchInterface $patch
     27      */
     28     function its_registerClassPatch_adds_a_patch_to_the_doubler($patch)
     29     {
     30         $this->registerClassPatch($patch);
     31         $this->getClassPatches()->shouldReturn(array($patch));
     32     }
     33 
     34     /**
     35      * @param \Prophecy\Doubler\ClassPatch\ClassPatchInterface $alt1
     36      * @param \Prophecy\Doubler\ClassPatch\ClassPatchInterface $alt2
     37      * @param \Prophecy\Doubler\ClassPatch\ClassPatchInterface $alt3
     38      * @param \Prophecy\Doubler\ClassPatch\ClassPatchInterface $alt4
     39      */
     40     function its_getClassPatches_sorts_patches_by_priority($alt1, $alt2, $alt3, $alt4)
     41     {
     42         $alt1->getPriority()->willReturn(2);
     43         $alt2->getPriority()->willReturn(50);
     44         $alt3->getPriority()->willReturn(10);
     45         $alt4->getPriority()->willReturn(0);
     46 
     47         $this->registerClassPatch($alt1);
     48         $this->registerClassPatch($alt2);
     49         $this->registerClassPatch($alt3);
     50         $this->registerClassPatch($alt4);
     51 
     52         $this->getClassPatches()->shouldReturn(array($alt2, $alt3, $alt1, $alt4));
     53     }
     54 
     55     /**
     56      * @param \Prophecy\Doubler\ClassPatch\ClassPatchInterface $alt1
     57      * @param \Prophecy\Doubler\ClassPatch\ClassPatchInterface $alt2
     58      * @param \ReflectionClass                                 $class
     59      * @param \ReflectionClass                                 $interface1
     60      * @param \ReflectionClass                                 $interface2
     61      * @param \Prophecy\Doubler\Generator\Node\ClassNode       $node
     62      */
     63     function its_double_mirrors_alterates_and_instantiates_provided_class(
     64         $mirror, $creator, $namer, $alt1, $alt2, $class, $interface1, $interface2, $node
     65     )
     66     {
     67         $mirror->reflect($class, array($interface1, $interface2))->willReturn($node);
     68         $alt1->supports($node)->willReturn(true);
     69         $alt2->supports($node)->willReturn(false);
     70         $alt1->getPriority()->willReturn(1);
     71         $alt2->getPriority()->willReturn(2);
     72         $namer->name($class, array($interface1, $interface2))->willReturn('SplStack');
     73         $class->getName()->willReturn('stdClass');
     74         $interface1->getName()->willReturn('ArrayAccess');
     75         $interface2->getName()->willReturn('Iterator');
     76 
     77         $alt1->apply($node)->shouldBeCalled();
     78         $alt2->apply($node)->shouldNotBeCalled();
     79         $creator->create('SplStack', $node)->shouldBeCalled();
     80 
     81         $this->registerClassPatch($alt1);
     82         $this->registerClassPatch($alt2);
     83 
     84         $this->double($class, array($interface1, $interface2))
     85             ->shouldReturnAnInstanceOf('SplStack');
     86     }
     87 
     88     /**
     89      * @param \ReflectionClass                           $class
     90      * @param \Prophecy\Doubler\Generator\Node\ClassNode $node
     91      */
     92     function it_double_instantiates_a_class_with_constructor_argument($mirror, $class, $node, $namer)
     93     {
     94         $class->getName()->willReturn('ReflectionClass');
     95         $mirror->reflect($class, array())->willReturn($node);
     96         $namer->name($class, array())->willReturn('ReflectionClass');
     97 
     98         $double = $this->double($class, array(), array('stdClass'));
     99         $double->shouldBeAnInstanceOf('ReflectionClass');
    100         $double->getName()->shouldReturn('stdClass');
    101     }
    102 
    103     /**
    104      * @param \ReflectionClass                           $class
    105      * @param \Prophecy\Doubler\Generator\Node\ClassNode $node
    106      */
    107     function it_can_instantiate_class_with_final_constructor($mirror, $class, $node, $namer)
    108     {
    109         $class->getName()->willReturn('spec\Prophecy\Doubler\WithFinalConstructor');
    110         $mirror->reflect($class, array())->willReturn($node);
    111         $namer->name($class, array())->willReturn('spec\Prophecy\Doubler\WithFinalConstructor');
    112 
    113         $double = $this->double($class, array());
    114 
    115         $double->shouldBeAnInstanceOf('spec\Prophecy\Doubler\WithFinalConstructor');
    116     }
    117 }
    118 
    119 class WithFinalConstructor
    120 {
    121     final public function __construct() {}
    122 }