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/13 10:56]
smayr [Unit Tests]
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 434: Line 446:
 <?php <?php
 namespace test\models; namespace test\models;
-use app\models\User;    // to access User model+use app\models\User;      // to access User model 
 +use app\models\Address;   // to access Address model
  
 //... //...
Line 689: 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 708: 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 776: Line 791:
   * [[https://codeception.com/docs/05-UnitTests#Stubs|Stubs in Codeception]].   * [[https://codeception.com/docs/05-UnitTests#Stubs|Stubs in Codeception]].
   * [[https://codeception.com/docs/05-UnitTests#Mocks|Mocks in Codeception]].   * [[https://codeception.com/docs/05-UnitTests#Mocks|Mocks in Codeception]].
 +
 +
 +== Test Examples ==
 +  * See: [[systems:yii2:Testing Examples]]
  
 == References == == References ==
Line 798: Line 817:
   * [[https://github.com/fzaninotto/Faker|Faker Data Types]]   * [[https://github.com/fzaninotto/Faker|Faker Data Types]]
   * [[https://martinfowler.com/articles/mocksArentStubs.html|Mocks Aren't Stubs]]   * [[https://martinfowler.com/articles/mocksArentStubs.html|Mocks Aren't Stubs]]
 +  * [[https://www.w3schools.com/cssref/css_selectors.asp|CSS Selectors]]