First Step before Creating a Webapp with YII


  1. Install LAMP Server
  2. Install PHPunit
  3. % sudo pear channel-discover pear.phpunit.de
    % sudo pear install phpunit/PHPUnit

  4. Install Selenium
  5. Download Selenium Remote Control (Selenium RC) zip file from http://seleniumhq.org/download/.
    Run Server from shell

    % java -jar selenium-server.jar

  6. Running the Functional Tests
  7. Before we can run this functional test, we need to make a couple of configuration changes to our application. First we need to alter protected/tests/WebTestCase. php to properly define our test URL that Selenium will attempt to open when it runs
    the tests. Open up that file and make sure the TEST_BASE_URL definition matches the URL to your webapp

    define(‘TEST_BASE_URL’,’http://localhost/webapp/index-test.php/’);

    The file protected/tests/phpunit.xml houses some configuration settings for Selenium Server. It is configured to use IE as the primary browser. We can remove the following highlighted line of code to ensure only Firefox will be used when running Selenium:

    name=”Internet Explorer” browser=”*iexplore”

    Now, as long as you have installed PHPUnitand have ensured that Selenium Server is running, and then we can navigate to our tests folder at the command prompt and run this functional test:

    % cd protected/tests/
    % phpunit functional/SiteTest.php

    What should happen is that you will see your browser being automatically invoked, as the Selenium Server platform is using the browser to access the end-user functionality of the site that we configured in the WebTestCase.php file. As it runs through the test methods, it actually automates the behavior of a real user of the site.

  8. Configure Gedit for PHP
  9. Install Netbeans
  10. SVN update the latest YII
  11. install the webapp in the webroot
  12. Testing the DB Connection
  13. we know we add our unit tests under protected/tests/unit/. Let’s create a simple database connectivity test file under this folder called DbTest.php. Create this new file with the following contents:

    class DbTest extends CTestCase
    {
    public function testConnection()
    {
    $this->assertTrue(true);
    }
    }

    Here we have added a fairly trivial test. The assertTrue() method, which is part of phpUnit, is an assertion that will pass if the argument passed to it is true, and it will fail if it is false. So, in this case, it will pass if true is true. Of course it is, so this test will pass. We are doing this to make sure our new application is working as expected for testing. Navigate to the tests folder and execute this new test:

    % cd /WebRoot/trackstar/protected/tests
    % phpunit unit/DbTest.php

    Change the trivial assertEquals(true) statement in the testConnection() test method to:

    $this->assertNotEquals(NULL, Yii::app()->db);

    And rerun the test:

  14. Configuring YII to use MySQL
  15. To customize our application configuration, we normally provide a configuration file
    to initialize its property values when the application instance is being created. The
    main application configuration file is located in /protected/config/main.php.

Advertisements

One thought on “First Step before Creating a Webapp with YII

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s