2017 © Pedro Peláez
 

luya-core luya-testsuite

TestCases and Data for LUYA Modules and Components. Makes testing less pain.

image

luyadev/luya-testsuite

TestCases and Data for LUYA Modules and Components. Makes testing less pain.

  • Thursday, July 19, 2018
  • by nadar
  • Repository
  • 5 Watchers
  • 4 Stars
  • 9,932 Installations
  • PHP
  • 39 Dependents
  • 0 Suggesters
  • 2 Forks
  • 2 Open issues
  • 16 Versions
  • 21 % Grown

The README.md

LUYA Test Suite

Build Status Test Coverage Total Downloads Latest Stable Version Join the chat at https://gitter.im/luyadev/luya, (*1)

Providing PHPUnit Testcases and a built in Webserver to test your Application, Modules, Components, APIs or Classes., (*2)

Whats included?, (*3)

Test Cases + Web application test case + Console application test case + Server (for APIs) test case + CMS Block test case + NgRest test case (for model, controller and API), (*4)

Traits + Message file compare trait + Migration file check trait, (*5)

Fixtures + ActiveRecord fixture creates the table on loading based from array or rule definition., (*6)

See the full Documentation, (*7)

Install

Add the luyadev/luya-testsuite package to the require-dev section of your composer.json file:, (*8)

composer require luyadev/luya-testsuite --dev

Create a new folder tests inside your appliation folder and create a test classes:, (*9)

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);
    }
}

To run the unit tests while (assuming your tests are in directory tests/) run in your terminal:, (*10)

./vendor/bin/phpunit tests/

In order to support sqlite fixtures install:, (*11)

sudo apt-get install php-sqlite3 

Example Test Cases

Some example in how to use the LUYA Testsuite for different scenarios., (*12)

Testing API and Application

When working with APIs or Customer Websites somtimes you just want to test the Website itself, what is the response, does all the pages still work after my update? Therefore we have luya\testsuite\cases\ServerTestCase., (*13)

This example will run your LUYA application within a PHP Webserver and test the response status codes or contents for a set of given pages. In order to run this example create a MyWebsiteTest.php file inside the tests folder., (*14)

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
  }
}

As the Webserver process may run from a different permission level you have to ensure the assets/runtime folder has the required permissions., (*15)

Controller Function Test

We're using getMockBuilder() as shown in the multiple examples in the PHPUnit to setup the DefaultController and assert the registered module addressbook. To test the the runtime exception (caused by a database error), we use the mock method function:, (*16)

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");
}

The Versions

19/07 2018

dev-master

9999999-dev http://luya.io

TestCases and Data for LUYA Modules and Components. Makes testing less pain.

  Sources   Download

MIT

The Requires

 

The Development Requires

php module luya

18/07 2018

1.0.11

1.0.11.0 http://luya.io

TestCases and Data for LUYA Modules and Components. Makes testing less pain.

  Sources   Download

MIT

The Requires

 

php module luya

09/05 2018

1.0.10

1.0.10.0 http://luya.io

TestCases and Data for LUYA Modules and Components. Makes testing less pain.

  Sources   Download

MIT

The Requires

 

php module luya

20/04 2018

1.0.9

1.0.9.0 http://luya.io

TestCases and Data for LUYA Modules and Components. Makes testing less pain.

  Sources   Download

MIT

The Requires

 

php module luya

20/04 2018

1.1.x-dev

1.1.9999999.9999999-dev http://luya.io

TestCases and Data for LUYA Modules and Components. Makes testing less pain.

  Sources   Download

MIT

The Requires

 

php module luya

20/04 2018

1.0.x-dev

1.0.9999999.9999999-dev http://luya.io

TestCases and Data for LUYA Modules and Components. Makes testing less pain.

  Sources   Download

MIT

The Requires

 

php module luya

26/03 2018

1.1.0

1.1.0.0 http://luya.io

TestCases and Data for LUYA Modules and Components. Makes testing less pain.

  Sources   Download

MIT

The Requires

 

php module luya

31/01 2018

1.0.8

1.0.8.0 http://luya.io

TestCases and Data for LUYA Modules and Components. Makes testing less pain.

  Sources   Download

MIT

The Requires

 

php module luya

12/01 2018

1.0.7

1.0.7.0 http://luya.io

TestCases and Data for LUYA Modules and Components. Makes testing less pain.

  Sources   Download

MIT

The Requires

 

php module luya

13/12 2017

1.0.6

1.0.6.0 http://luya.io

TestCases and Data for LUYA Modules and Components. Makes testing less pain.

  Sources   Download

MIT

The Requires

 

php module luya

09/09 2017

1.0.5

1.0.5.0 http://luya.io

TestCases and Data for LUYA Modules and Components. Makes testing less pain.

  Sources   Download

MIT

The Requires

 

php module luya

28/06 2017

1.0.4

1.0.4.0 http://luya.io

TestCases and Data for LUYA Modules and Components. Makes testing less pain.

  Sources   Download

MIT

The Requires

 

php module luya

19/05 2017

1.0.3

1.0.3.0 http://luya.io

TestCases and Data for LUYA Modules and Components. Makes testing less pain.

  Sources   Download

MIT

The Requires

 

php module luya

17/05 2017

1.0.2

1.0.2.0 http://luya.io

TestCases and Data for LUYA Modules and Components. Makes testing less pain.

  Sources   Download

MIT

The Requires

 

php module luya

17/05 2017

1.0.1

1.0.1.0 http://luya.io

TestCases and Data for LUYA Modules and Components. Makes testing less pain.

  Sources   Download

MIT

The Requires

 

php module luya

04/05 2017

1.0.0

1.0.0.0 http://luya.io

TestCases and Data for LUYA Modules and Components. Makes testing less pain.

  Sources   Download

MIT

The Requires

 

php module luya