SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    May 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SimpleTest to check environment

    im very newbie to SimpleTest and i need help from you guys/
    anyone who knows/familiar with SimpleTest framework?
    anyone familiar with using SimpleTest to check the environment
    sample:
    + main DB user must be able to create databases
    + php must have the following extensions loaded
    - PDO
    - PDO-mysql
    - GD
    - APC or XCache
    + logfiles must be writable
    + mod_rewrite must be on

    pls help me...thanks...

  2. #2
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just pick one to get started. Regardless of SimpleTest or any other testing framework, how would you detect that an extension like GD is enabled on a server?
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  3. #3
    SitePoint Member
    Join Date
    May 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i would like to try first on "main DB user be able to creat databases"..but i dont know how create the right php script..please help me..many thanks..

  4. #4
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I happen to use adodb for a database access layer. In a particular application I an working on, I have a service locator which I can use to get the connected database connection object. I might write a test case like:

    PHP Code:
    class DbTestCase extends UnitTestCase {
        function 
    testGetDbConnection() {
            
    $this->assertIsA($db ServiceLocator::getDb(), 'adodb_mysql');
            
    $this->assertMethodExists($db'execute');
            
    $this->assertMethodExists($db'getArray');
            
    $this->assertMethodExists($db'getCol');
            
    $this->assertMethodExists($db'getOne');
        }
        
        function 
    TestCreateDatabase() {
            
    $db ServiceLocator::getDb();
            
    $this->assertTrue($db->execute('create database foo'), 'Attempt to create database');
            
    $this->assertEqual(''$db->errorMsg());
        }
        
        function 
    assertMethodExists($obj$meth) {
            
    $this->assertExpectation(new MethodExistsExpectation($meth), $obj);
        }

    In my case this returns something like:
    Code:
    Setup Tests
    1) Attempt to create database at [/data/home/sweatje/public_html/hellbored/test2.php line 20]
            in TestCreateDatabase
            in DbTestCase
    2) Equal expectation fails at character 0 with [] and [Access denied for user 'theuser'@'localhost' to database 'foo'] at [/data/home/sweatje/public_html/hellbored/test2.php line 21]
            in TestCreateDatabase
            in DbTestCase
    
    FAILURES!!!
    Test cases run: 1/1, Passes: 5, Failures: 2, Exceptions: 0
    because I intentionally don't allow my normal user the web application connects with the rights to create a database.
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  5. #5
    SitePoint Addict Jasper Bekkers's Avatar
    Join Date
    May 2007
    Location
    The Netherlands
    Posts
    282
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sweatje View Post
    Just pick one to get started. Regardless of SimpleTest or any other testing framework, how would you detect that an extension like GD is enabled on a server?
    Just in case it's not a rhetoric question; ReflectionExtension or get_loaded_extensions().

  6. #6
    SitePoint Member
    Join Date
    May 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    huhuhuhu...really cant digest the things you guys mentioned...

    can you give me a sample like a step by step on how to test if the "main database user" could create database...pls...

  7. #7
    SitePoint Evangelist
    Join Date
    Jun 2003
    Location
    Melbourne, Australia
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by psyd_1 View Post
    i would like to try first on "main DB user be able to creat databases"..but i dont know how create the right php script
    I don't mean to be harsh, but I find this plea very telling. If you understood how to work with databases -- even at a basic level-- you'd know what SQL to issue to create a database. If you understood PHP and at least one set of its database functions (mysql or mysqli, for example), you'd know how to write a script which connects to the database server and issues that query.

    At a basic level, you should be able to test whether or not that query was successful by echoing the output of the database function that issues queries; e.g. mysql_query(). Jason's example is a good one: using ADODB, in which the execute() method appears to return a boolean, true for success and false for failure. As another example, if you were using native mysql functions, you could echo or print_r the output of any of them.

    After that it's probably not too much of a stretch to see that SimpleTest wraps all that it a nice "reporter". As you can see from Jason's script, every time you want to test (and report) whether or not something succeeded, or whether or not some state was what you expected it to be, you use one or more of the assert* functions.
    Zealotry is contingent upon 100 posts and addiction 200?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •