PHP code example of uzulla / mockslimclient

1. Go to this page and download the library: Download uzulla/mockslimclient 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/ */

    

uzulla / mockslimclient example snippets



class myTest extends \PHPUnit\Framework\TestCase
{
    use \Uzulla\MockSlimClient; // use by trait

    // over ride \Uzulla\MockSlimClient::registrationRoute()
    static function registrationRoute($app)
    {
        $app->get('/', function() use ($app){
            //...
        });
        // or \myApp::registrationRoute($app);
    }
    
    // over ride \Uzulla\MockSlimClient::createSlim()
    static function createSlim()
    {
        return new \Slim\Slim([
            'templates.path' => __DIR__.'/../../sample_app/templates'
        ]);
    }    

    // sample test case.	
    public function testConfirmPost()
    {
        // get http://dummy/ html.
        $raw_html = $this->req('/');
        
        // get paquettg/php-html-parser instance
        $dom = $this->req_dom('/post/form');
        $this->assertTrue(!!$dom->find('input[name=name]'));

        // get CSRF token.
        $this->req('/');
        $csrf_token = $_SESSION['csrf_token'];

        $test_name = 'testname';
        $test_body = 'testbody';

        // build post data.
        $input = http_build_query([
            'nickname'=>$test_name,
            'body'=>$test_body,
            'csrf_token'=>$csrf_token
        ]);

        // do post.
        $dom = $this->req_dom('/post/confirm', 'POST', $input);
        $this->assertEquals($test_name, $dom->find('div.nickname-preview', 0)->text);
        $this->assertEquals($test_name, $dom->find('input[name=nickname]', 0)->value);
    }
}