Skip to content

Instantly share code, notes, and snippets.

@davemfletcher
Forked from JeffreyWay/reflection.php
Created March 19, 2013 21:29
Show Gist options
  • Select an option

  • Save davemfletcher/5200321 to your computer and use it in GitHub Desktop.

Select an option

Save davemfletcher/5200321 to your computer and use it in GitHub Desktop.

Revisions

  1. @JeffreyWay JeffreyWay revised this gist Mar 19, 2013. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions reflection.php
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,7 @@
    <?php

    // ...

    public function testProtected()
    {
    $dateFormatter = new DateFormatter;
  2. @JeffreyWay JeffreyWay revised this gist Mar 19, 2013. 1 changed file with 3 additions and 4 deletions.
    7 changes: 3 additions & 4 deletions reflection.php
    Original file line number Diff line number Diff line change
    @@ -4,14 +4,13 @@ public function testProtected()

    $class = new \ReflectionClass('DateFormatter');

    // Find the protected/private method and make it public
    // Find the protected/private method and make it public
    $getSentence = $class->getMethod('getSentence');
    $getSentence->setAccessible(true);

    // Trigger the method, and pass in any applicable args
    // Trigger the method, and pass in any applicable args
    $sentence = $getSentence->invokeArgs($dateFormatter, [1, 'month']);

    // Do your test as usual
    // Do your test as usual
    $this->assertEquals('1 month from now.', $sentence);
    // getDocComment
    }
  3. @JeffreyWay JeffreyWay created this gist Mar 19, 2013.
    17 changes: 17 additions & 0 deletions reflection.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    public function testProtected()
    {
    $dateFormatter = new DateFormatter;

    $class = new \ReflectionClass('DateFormatter');

    // Find the protected/private method and make it public
    $getSentence = $class->getMethod('getSentence');
    $getSentence->setAccessible(true);

    // Trigger the method, and pass in any applicable args
    $sentence = $getSentence->invokeArgs($dateFormatter, [1, 'month']);

    // Do your test as usual
    $this->assertEquals('1 month from now.', $sentence);
    // getDocComment
    }