Welcome Guest, Not a member yet? Register   Sign In
CIModelTester: Front-end for Model Testing (new)
#1
Star 
(This post was last modified: 10-27-2015, 03:56 AM by cwingrav.)

CIModelTester : Front-end for Model Testing

A CodeIgniter interactive model tester web interface. Directly call your model functionality for testing and debugging.

   Github Repo: https://github.com/cwingrav/CIModelTester

Basically, I wanted to test my model as I was coding it. Sure, test scripts are good, but sometimes I just want to directly use it. It works by reading your models and creating a webpage with a form for each method and its parameters. Then, it calls your model with ajax and displays the results.

I use this constantly, keeping it open during development. Hope you find it useful too!



There are three main pages for searching through your models, finding and calling their methods and running unit tests.

1) Find a model:
[Image: mainpage.png]

Then, 2) review the methods on that model:
[Image: modelpage.png]

... and call them:
[Image: amethod.png]

And, 3) run unit tests on that model.
[Image: unit_test_output.png]
Reply
#2

My gosh, I use this every day when I code. Somebody's gotta have a comment on this!  Huh
Reply
#3

Its only been up for a day.  Tongue

It looks very good and I can certainly see times when this could be handy.

I like that it looks simple and to the point.

I have not tried it out yet (no time) but you should suggest it for this list:
https://github.com/codeigniter-id/awesome-codeigniter

Have made a note to try it out. If you run a test on the model, that, say, writes a record to the database, does it actually write the record during the test? The same with deletion, does it actually delete a record in a unit test? Or simulate the deletion?

Will feedback when I do test it.

Best wishes,

Paul.
Reply
#4

Looks reasonably useful, so I guess it automagically reads your models, figures out how many variables a method has and builds a front end for testing, right? The only thing I'd say is most apps don't function WITHOUT interaction from other models and controllers. Is this something you're planning to work on?

Also a brief note on your coding style, please avoid using one letter and two letter variables, it's not good practice.

Have you thought about moving your html out of your php files because at the moment it makes it very difficult to maintain.
Practical guide to IgnitedCMS - Book coming soon, www.ignitedcms.com
Reply
#5

(10-23-2015, 11:03 AM)PaulD Wrote: Its only been up for a day.  Tongue

It looks very good and I can certainly see times when this could be handy.

I like that it looks simple and to the point.

I have not tried it out yet (no time) but you should suggest it for this list:
https://github.com/codeigniter-id/awesome-codeigniter

Have made a note to try it out. If you run a test on the model, that, say, writes a record to the database, does it actually write the record during the test? The same with deletion, does it actually delete a record in a unit test? Or simulate the deletion?

Will feedback when I do test it.

Best wishes,

Paul.

Thanks for the response! I'll take a look at that link.

Regarding your question, if you call a method of your model, it does EXACTLY what that method does, as if it were called by your controller (it actually uses Ajax to call it so there is no page reload or anything). If you run a unit test, it does EXACTLY what your unit test tells it to do. So, I often use this instead of SQL calls for messing with data during development.

Because of this potential issue, and to not blow up a deployed system, it monitors the ENVIRONMENT define of your project. I only allow this to operate when in 'development' or 'testing' states. For unit tests, I only allow when 'testing'.

Personally, I switch databases in my projects based upon this ENVIRONMENT define anyway (i.e. my config/database.php file has "$db['default']['database'] = 'projectname_'.ENVIRONMENT.'_'.VERSION;") so testing won't screw up development and visa versa. For my unit tests, I reload test data in my testing database for each test via a script call to mysql. I leave this up to the user to implement.

To help loading SQL data, here's what I use:
$r = shell_exec("/usr/local/bin/mysql --defaults-file=$dbd/.my.cnf $db < $dbf 2>&1");
... where $dbd is the path to my mysql defaults file (i.e. passwords), $db is the database name and $dbf is the SQL file to load. This sets $r to any error messages from the mysql import. In unit test methods, any returned values are displayed so you can see any mysql data loading errors if you return $r.

Hope that helps!
Reply
#6

This looks interesting but I had trouble reading through your code, all that HTML and Logic combined !
Codeigniter is simply one of the tools you need to learn to be a successful developer. Always add more tools to your coding arsenal!
Reply
#7

(10-23-2015, 11:10 AM)iamthwee Wrote: Looks reasonably useful, so I guess it automagically reads your models, figures out how many variables a method has and builds a front end for testing, right? The only thing I'd say is most apps don't function WITHOUT interaction from other models and controllers. Is this something you're planning to work on?

Also a brief note on your coding style, please avoid using one letter and two letter variables, it's not good practice.

Have you thought about moving your html out of your php files because at the moment it makes it very difficult to maintain.

Yes. It uses PHP's ReflectionClass to pick apart the file and build everything.

Regarding loading controllers/models, the ajax side of this ensures it approaches your code just like a normal call. So, if it breaks on a call, you need to fix it. Am I answering this right? Hasn't been an issue so far.

Coding style: This was hacked together over time by me. Yeah, it's ugly. I'll refactor it next release... Wink .

Moving the HTML out to a mustache template would be ideal. It wouldn't take long either; just haven't done. At first, I loaded views, but then I wanted one file for faster installation so I put my views all in one file. Then the project started getting longer and longer... and well... yeah.
Reply
#8

(10-23-2015, 11:33 AM)albertleao Wrote: This looks interesting but I had trouble reading through your code, all that HTML and Logic combined !

Sorry. Smile

But hey, only ONE FILE to install! I'll fix with a template.
Reply
#9

I liked the fact it was just one file!
Reply
#10

(10-23-2015, 12:20 PM)PaulD Wrote: I liked the fact it was just one file!

True, but remember he/she is calling online bootstrap files to render his views so technically it's more if he actually hardcoded them into his app Big Grin
Practical guide to IgnitedCMS - Book coming soon, www.ignitedcms.com
Reply




Theme © iAndrew 2016 - Forum software by © MyBB