Codeception – Create Helper for Reusing Token


create the file on tests/_support/Helper/ folder, to reuse the token you need to create hook _before

 

tests/ApiCest.php
-----------------
<?php 

class ApiCest 
{
    private $token;
    
    
    function createMeetingTest(ApiTester $I) {
        $data = array(
            "meeting_title" => "Meeting title",
            "meeting_date" => "2019-11-21 10:00:00"
        );
        
        $this->token = $I->getToken();
        
        $I->wantToTest('Create a meeting');
    	$I->amBearerAuthenticated($this->token);
		$I->sendPOST('/meetings', $data);
		$I->seeResponseCodeIs(200);
		$I->seeResponseIsJson();        
    }

    
}

tests/_support/Helper/Api.php
-----------------------------
<?php
namespace Helper;

class Api extends \Codeception\Module
{
	public $credentials = array(
		'username' => 'remo.harsono',
		'password' => '12345678'
	);
    
	private $jwt;


	public function getToken() {
		return $this->jwt;
	}

    public function _before(\Codeception\TestInterface $test) {
		$I = $this->getModule('REST');
		$I->haveHttpHeader('Content-Type', 'application/json');
		
		$I->sendPOST("/auth/login", $this->arrCredentials);

		$I->seeResponseCodeIs(200);
		$I->seeResponseIsJson();

		$response = $I->grabResponse();
		$json = json_decode((string)$jesponse);
		
		if ($json->result == 'OK') {
			$this->jwt = $json->jwt;
		} else {
			// ....
		}
	}
}


sample json output when calling auth/login
------------------------------------------
{
  "result": "OK",
  "jwt": "blablablabla",
}

Yii : CGridView – Create Custom Column


I have a field which contains one character to represent project status (eg: F=Finished, S=Start, P=Pending, etc)

By default, CGridView will display one character value, but we want CGridView to display its description taken from other table, this is what I did:

First, create a component, let’s name it MyComponent. You can do it by create MyComponent.php and save it in component folder, I write something like this:

<?php
class MyComponent extends CApplicationComponent 
{
 public function getProjectStatus($statusCode)
 { 
 $sql = "SELECT STATUS_CODE,
 DESCRIPTION
 FROM REF_PROJECT_STATUS WHERE STATUS_CODE='$statusCode'";

 $rs = Yii::app()->db->createCommand($sql)->queryAll();

 $data = array();

 foreach($rs as $item){

 $statusCode = $item['STATUS_CODE'];
 $description = $item['DESCRIPTION'];

 $data[$statusCode] = $description;
 }
 
 return $data[$statusCode]; 
 } 
}

This way, you can call the function like this
Yii::app()->mycomponent->getProjectStatus($statusCode)

Then, replace the field name in your views (admin.php) with something like this

array('header' => 'Project Status', 'value' => 'Yii::app()->mycomponent->getProjectStatus($data->PROJECT_STATUS)'),

Some people suggest the function should be static

Yii version: 1.1.10

Adminer – Set Number of Rows to Display


I’ve ever wrote how to set this on PhpMyAdmin, now I want to do it on Adminer. I want Adminer to show 200 records when I select a table. I’ve try it using Adminer v4.1.0 and v4.2.0 both for MySQL english only.

I just search the string “selectLimitProcess(){” with no quote off course and then replace its default number from 50 to 200, you can use any number you want.