PHP code example of kglogowski / rest-test-helper

1. Go to this page and download the library: Download kglogowski/rest-test-helper 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/ */

    

kglogowski / rest-test-helper example snippets


    class TestUserController extends AbstractController
    {
       const ROUTE = 'user.get';

       /**
        * testGetSuccess
       */
       public function testGetSuccess()
       {
           $crawler = $this->createCrawler();
     
           $crawler
               ->click(
                   Request::METHOD_GET, //Request type
                   $this->getRequestHeaders(), //Headers, overwrite method
                   $this->getUrl(self::ROUTE, ['id' => 1]) //Generate url
               )
               ->checkStatus(Response::HTTP_OK) //Check status response
               ->child('id') //Go to child
                   ->assertActive(ResponseCrawlerInterface::ASSERT_EQUALS, [
                       1
                   ])
               ->end()
               ->child('email')
                   ->assertActive(ResponseCrawlerInterface::ASSERT_NOT_NULL)
               ->end()
           ;
       }
    }
    

    class TestUserController extends AbstractController
    {
       const ROUTE = 'user.post';

       /**
        * testGetSuccess
       */
       public function testPostSuccess()
       {
           $crawler = $this->createCrawler();
     
           $crawler
               ->click(
                   Request::METHOD_POST,
                   $this->getRequestHeaders(),
                   $this->getUrl(self::ROUTE),
                           $this->getJsonMockFileContent($file)
                   
                   ;
        
           /**
            * {@inheritdoc}
            */
           public function getMockDir(): string
           {
               return __DIR__ . '/mock/';
           }
       }
    }