PHP code example of fkupper / private-sniffer-module

1. Go to this page and download the library: Download fkupper/private-sniffer-module library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fkupper / private-sniffer-module example snippets

 php
class Foo
{
    private $someInt = 1;

    private sum(int $a, int $b): int
    {
        return $a + $b;
    }
}

class TestFoo extends \Codeception\Test\Unit
{
    /**
     * @var \UnitTester
     */
    protected $tester;

    // tests
    public function testSum()
    {
        $foo = new Foo();

        // get the value of the private attribute $someInt
        $someInt = $this->tester->getPrivatePropertyValue($foo, 'someInt');
        $this->assertEquals(1, $someInt);

        // get a closure of the private method sum
        $sum = $this->tester->getPrivateMethod($foo, 'sum');
        $this->assertEquals(2 + 3, $sum(2, 3));
    }
}