Monday, August 25, 2008

Remote Debugging Flash or Flex Apps using Flex IDE

Theres a lot of information about this already, just mentioning it one more time won't hurt:

1] Make sure your Flash app is compiled permitting debugging. If using Flex make sure its not the release compilation. Lets pretend the compiled program is uploaded to http://blah.com/flashapp/flashapp.html.

2] Create a new Flex project, you can name it anything.

3] Right click on the new project, goto Properties then Run/Debug Settings. Make a new configuration with the Debug/Profile/Run path pointing to the application you want to debug, in our case: http://blah.com/flashapp/flashapp.html.

4] Click Debug project. It will pop up the application you want to debug.

5] When the window pops up, right click the program. If you have Flash Debug Player installed, there will be a context menu item called Debugger. Click this.

6] Tell it you want to connect the debugger to localhost (which your Flex IDE started).

7] Done, you should be able to see trace statements :)

Wednesday, August 13, 2008

CakePHP 1.1 Unit Testing Test Suite v 1.0.0.5 tutorial

So your stuck with CakePHP 1.1, but you need to add Unit Testing, what do you do?


You can grab Cake Test Suite v1.0.0.5 (using SimpleTest) here


The thing with this Test Suite is that I couldn't find documentation anywhere so I decided to write this little tutorial on how to get started.


Step 1: Setup
First make sure your CakePHP Project's debug level is set to at least 1.


Next, after unzipping the app folder into your project and trying to run the test controller(http://yourproject/test/) you might see that you will get this error:


Notice: Use of undefined constant CORE_PATH - assumed 'CORE_PATH' in D:\Flex Workspaces\cakeamfphp\cake\config\paths.php on line 44



To fix this open up /app/webroot/test/index.php and insert this on line 82:

if (!defined('CORE_PATH')) {
if (function_exists('ini_set')) {
ini_set('include_path', CAKE_CORE_INCLUDE_PATH . PATH_SEPARATOR . ROOT . DS . APP_DIR . DS . PATH_SEPARATOR . ini_get('include_path'));
define('APP_PATH', null);
define('CORE_PATH', null);
} else {
define('APP_PATH', ROOT . DS . APP_DIR . DS);
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
}
}

require CORE_PATH.'cake'.DS.'bootstrap.php';


Step 2: Writing the Tests

Lets say for example, I have a model user.php that I want to test, I have to create this file as /app/tests/app/cases/models/User.test.php

It will look something like this:


class UserTest extends UnitTestCase {

function testSomething() {
loadModel('User');
$user = &new User();
$this->assertEqual($user->name, 'User');
}
}

?>



If testing a controller, you would want to use the loadController method.


If I wanted to make a group test of my models I would for example make a file
in app/tests/app/groups/Model.group.php:



require_once(TESTS.'/app/cases/models/User.test.php');
require_once(TESTS.'/app/cases/models/User_Builder.test.php');

class ModelTest extends GroupTest {

function ModelTest(){
$this->addTestCase(new UserTest());
$this->addTestCase(new User_BuilderTest());
}

}

?>





Hope this helps get you on the right track. Take a look at the simpletest docs for more information on how to unit test your project.

Monday, August 11, 2008

Flex ArrayCollection CollectionEvent dispatching class changes

Lets say you have a class:


[ArrayElementType("com.my.AwesomeClass")]
private var myAC:ArrayCollection = new ArrayCollection();


your class is such that sometimes changing a property in AwesomeClass doesn't
make myAC dispatch CollectionEvent.COLLECTION_CHANGE. An example changing the
property awesomeClass.foo.x.

To tell myAC that an item is changed use ArrayCollection's itemUpdated method after changing an element in the ArrayCollection.


myAC.itemUpdated(awesomeClass);

Monday, August 4, 2008

Getting CakeAMFPHP w/ CakePHP 1.1 centralized database sessions working

CakePHP makes it a snap to create centralized database sessions.

However, If you wanted to use Flash and CakeAMFPHP with CakePHP's sessions, you'll find that it might not be working. Here are some fixes+workarounds to get it running.

Step 1] open /app/vendors/vendors/cakeamfphp/amf-core/app/Gateway.php
comment out line 93

//$this->filters['auth'] = 'authenticationFilter';


The auth filter was breaking the sessions for some reason.

Step 2] Open /app/config/core.php
change the CAKE_SESSION_SAVE to:

define('CAKE_SESSION_SAVE', 'database');


change CAKE_SESSION_COOKIE to your php cookie sessions name(look in phpinfo()):
for example mine is:

define('CAKE_SESSION_COOKIE', 'PHPSESSID');


change CAKE_SECURITY to low:

define('CAKE_SECURITY', 'low');


Step 3] create the sessions table in your $default(in database.php) database by importing the file at: /app/config/sql/sessions.sql


Step 4] open /cake/libs/session.php and comment out:
on line 132:

/*if (Configure::read('Session.checkAgent') === true) {
if (env('HTTP_USER_AGENT') != null) {
$this->_userAgent = md5(env('HTTP_USER_AGENT') . CAKE_SESSION_STRING);
}
}*/


on line 311:

if (/*Configure::read('Session.checkAgent') === false || $this->_userAgent == $this->read("Config.userAgent") && */$this->time <= $this->read("Config.time")) {


on line 541:

if (/*Configure::read('Session.checkAgent') === false || $this->_userAgent == $this->read("Config.userAgent") && */$this->time <= $this->read("Config.time")) {


the useragent works with the browser but we are connecting using flash to amf to for some reason this was breaking.



You are done, try playing around with the Session methods to see if your
sessions are being stored and retrieved from the database. For a tutorial on CakePHP sessions take a look here.



---edit----
still having problems? Try turning off cookies in your cake gateway.

Open /app/webroot/cake_gateway.php:

insert this at the top:

ini_set('session.use_trans_sid', 1); //make it so we can use cookie-less sessions
ini_set('session.use_cookies', 0);


open /cake/libs/session.php:

find all occurences of ini_set('session.use_trans_sid', 0);
and change them to

ini_set('session.use_trans_sid', 1);



in your delegate when you call the gateway it must pass in a PHPSESSID example:


//cookieless sessions
if (session_id != null) {
appendurl = '?PHPSESSID='+session_id;
}

var gateway:String="http://cakeamfphp/cake_gateway.php"+appendurl;