PHP code example of luyadev / luya-testsuite

1. Go to this page and download the library: Download luyadev/luya-testsuite library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

luyadev / luya-testsuite example snippets


namespace app\tests;

use Yii;

class MyTest extends \luya\testsuite\cases\WebApplicationTestCase
{
    public function getConfigArray()
    {
        return [
            'id' => 'mytestapp',
            'basePath' => dirname(__DIR__),
        ];
    }
    
    public function testInstance()
    {
        // add your phpunit tests here, like:
        $this->assertInstanceOf('luya\web\Application', Yii::$app);
        $this->assertInstanceOf('luya\base\Boot', $this->boot);
        $this->assertInstanceOf('luya\web\Application', $this->app);
    }
}

namespace app\tests;

class MyWebsiteTest extends ServerTestCase
{
   public function getConfigArray()
   {
      return [
          'id' => 'mytestapp',
          'basePath' => dirname(__DIR__),
      ];
  }
  
  public function testSites()
  {
      $this->assertUrlHomepageIsOk(); // checks the root url like: http://localhost/mywebsite.com
      $this->assertUrlIsOk('about'); // checks: http://localhost/mywebsite.com/about
      $this->assertUrlGetResponseContains('about/me', 'Hello World'); // checks: http://localhost/mywebsite.com/about/me
      $this->assertUrlIsError('errorpage'); // checks: http://localhost/mywebsite.com/errorpage
  }
}

public function testActionIndex()
{
    $module = Yii::$app->getModule('addressbook');
    
    $this->assertInstanceOf('luya\addressbook\frontend\Module', $module);
    $mock = $this->getMockBuilder(DefaultController::class)
        ->setConstructorArgs(["id" => "default", "module" => $module])
        ->getMock();
        
    $mock->method("actionIndex");
}
sh
sudo apt-get install php-sqlite3