Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
systems:yii2:testing_setup [2018/04/20 09:54]
smayr [References]
systems:yii2:testing_setup [2018/04/26 09:38] (current)
smayr [Configure Tests]
Line 192: Line 192:
       - Filesystem       - Filesystem
       - Yii2       - Yii2
 +           #part: [init, orm, email, fixtures]
 +           configFile: 'config/test.php'
 +           entryScript: index-test.php
 +      - Db:
 +          dsn: "mysql:host=localhost;dbname=mydatabase"
 +          user: "dbuser"
 +          password: "dbsecret"
 +      #- REST
 +      #    depends: PhpBrowser
 +      #    url: http://localhost:8080/yii/basic-userdb/web/
 </code> </code>
  
Line 205: Line 215:
     enabled:     enabled:
       - Asserts       - Asserts
-      - Db: 
-          dsn: "mysql:host=localhost;dbname=acme_test" 
-          user: "root" 
-          password: "" 
       - Yii2:       - Yii2:
             part: [orm, email]             part: [orm, email]
 +            configFile: 'config/test.php'
 +            entryScript: index-test.php
 +      #- Db:
 +      #    dsn: "mysql:host=localhost;dbname=mydatabase"
 +      #    user: "dbuser"
 +      #    password: "dbsecret"
 </code> </code>
  
Line 690: Line 702:
     'fixture' => [     'fixture' => [
         'class'           => 'yii\faker\FixtureController',         'class'           => 'yii\faker\FixtureController',
-        //'templatePath'    => '@app/tests/templates/fixtures',+        'templatePath'    => '@app/tests/unit/templates/fixtures',
         //'fixtureDataPath' => '@app/tests/fixtures/data',         //'fixtureDataPath' => '@app/tests/fixtures/data',
         'fixtureDataPath' => '@app/tests/_data',         'fixtureDataPath' => '@app/tests/_data',
Line 709: Line 721:
 </code> </code>
  
 +Get more generators from: [[https://github.com/fzaninotto/Faker]]
 === Template for Fixtures === === Template for Fixtures ===
 If you need unit tests to load faker data using fixtures, create a fixture template under ''@tests/unit/templates/fixtures'' Eg: File ''users.php'': If you need unit tests to load faker data using fixtures, create a fixture template under ''@tests/unit/templates/fixtures'' Eg: File ''users.php'':
 <code php> <code php>
 +<?php
 // users.php file under the template path (by default @tests/unit/templates/fixtures) // users.php file under the template path (by default @tests/unit/templates/fixtures)
 /** /**
Line 780: Line 794:
  
 == Test Examples == == Test Examples ==
 +  * See: [[systems:yii2:Testing Examples]]
  
-=== Comments === 
-<code php> 
-$I->wantTo('query the customer info using his phone number'); 
-$I->expectTo('see query result'); 
-</code> 
- 
-=== Users === 
-<code php> 
-// Login 
-$I->amLoggedInAs(\app\models\User::findByUsername('admin')); 
-$I->amOnPage(['site/index']); 
-$I->see('Logout'); 
- 
-// Logout 
-\Yii::$app->user->logout(); 
-$I->amOnPage(['site/index']); 
-$I->see('Signup'); 
-$I->see('Login'); 
-</code> 
 == References == == References ==
   * [[https://github.com/yiisoft/yii2-app-basic/blob/master/README.md#testing|Yii2 Testing with Basic App Template]]   * [[https://github.com/yiisoft/yii2-app-basic/blob/master/README.md#testing|Yii2 Testing with Basic App Template]]