Abstract Class luya\testsuite\cases\WebApplicationTestCase

Inheritanceluya\testsuite\cases\WebApplicationTestCase » luya\testsuite\cases\BaseTestSuite » Yoast\PHPUnitPolyfills\TestCases\TestCase
Subclassesluya\testsuite\cases\CmsBlockGroupTestCase, luya\testsuite\cases\CmsBlockTestCase, luya\testsuite\cases\NgRestModelTestCase, luya\testsuite\cases\NgRestTestCase
Available since version1.0.0
Source Code https://github.com/luyadev/luya-testsuite/blob/master/src/cases/WebApplicationTestCase.php

Web Application Test Case.

Provdides basic setup for Script paths in order make the urlManager work.

Usage:

class MyTestCase extends WebApplicationTestCase
{
    public function getConfigArray()
    {
        return [
           'id' => 'mytestapp',
           'basePath' => dirname(__DIR__),
        ];
    }
}

Public Methods

Hide inherited methods

Method Description Defined By
afterSetup() Method which is executed after the setUp() method in order to trigger post setup functions. luya\testsuite\cases\BaseTestSuite
assertContainsNoSpace() Assert Contains without spaces but with newlines. luya\testsuite\cases\BaseTestSuite
assertContainsTrimmed() Same as assertContains but trims the needle and haystack content in order to compare. luya\testsuite\cases\BaseTestSuite
assertSameNoSpace() This assert Same option allows you to compare two strings but removing spaces and tabes, so its more easy to work with readable contents but better comparing. luya\testsuite\cases\BaseTestSuite
assertSameTrimmed() Assert Same but trim content (remove, double spaces, tabs and newlines. luya\testsuite\cases\BaseTestSuite
beforeSetup() Method which is executed before the setUp() method in order to inject data on before Setup. luya\testsuite\cases\WebApplicationTestCase
beforeTearDown() This method is triggered before the application test case tearDown() method is running. luya\testsuite\cases\BaseTestSuite
bootApplication() luya\testsuite\cases\WebApplicationTestCase
fixture() Get Fixture Object luya\testsuite\cases\BaseTestSuite
fixtures() Defines a list of fixtures classes which can be loaded. luya\testsuite\cases\BaseTestSuite
getConfigArray() Provide Configurtion Array. luya\testsuite\cases\BaseTestSuite
invokeMethod() Call a private or protected method from an object and return the value. luya\testsuite\cases\BaseTestSuite
setupFixtures() Create all fixtures from fixtures() list. luya\testsuite\cases\BaseTestSuite
tearDownFixtures() Run cleanup() on all loaded fixtures. luya\testsuite\cases\BaseTestSuite

Protected Methods

Hide inherited methods

Method Description Defined By
set_up() luya\testsuite\cases\BaseTestSuite
tear_down() luya\testsuite\cases\BaseTestSuite
trimContent() No Spaces and No Newline Trims the given text. Remove whitespaces, tabs and other chars in order to compare readable formated texts. luya\testsuite\cases\BaseTestSuite
trimSpaces() No Spaces with Newline luya\testsuite\cases\BaseTestSuite

Method Details

Hide inherited methods

afterSetup() public method (available since version 1.0.2)

Defined in: luya\testsuite\cases\BaseTestSuite::afterSetup()

Method which is executed after the setUp() method in order to trigger post setup functions.

Make sure to call the parent afterSetup() method when overwriting this method.

public void afterSetup ( )

                public function afterSetup()
{
}

            
assertContainsNoSpace() public method (available since version 1.0.8)

Defined in: luya\testsuite\cases\BaseTestSuite::assertContainsNoSpace()

Assert Contains without spaces but with newlines.

public boolean assertContainsNoSpace ( $needle, $haystack )
$needle string
$haystack string

                public function assertContainsNoSpace($needle, $haystack)
{
    return $this->assertStringContainsString($this->trimSpaces($needle), $this->trimSpaces($haystack));
}

            
assertContainsTrimmed() public method

Defined in: luya\testsuite\cases\BaseTestSuite::assertContainsTrimmed()

Same as assertContains but trims the needle and haystack content in order to compare.

This will also remove newlines.

public boolean assertContainsTrimmed ( $needle, $haystack )
$needle string
$haystack string

                public function assertContainsTrimmed($needle, $haystack)
{
    return self::assertStringContainsString($this->trimContent($needle), $this->trimContent($haystack));
}

            
assertSameNoSpace() public method (available since version 1.0.8)

Defined in: luya\testsuite\cases\BaseTestSuite::assertSameNoSpace()

This assert Same option allows you to compare two strings but removing spaces and tabes, so its more easy to work with readable contents but better comparing.

This wont remove new lines.

public boolean assertSameNoSpace ( $needle, $haystack )
$needle string
$haystack string

                public function assertSameNoSpace($needle, $haystack)
{
    return $this->assertSame($this->trimSpaces($needle), $this->trimSpaces($haystack));
}

            
assertSameTrimmed() public method (available since version 1.0.8)

Defined in: luya\testsuite\cases\BaseTestSuite::assertSameTrimmed()

Assert Same but trim content (remove, double spaces, tabs and newlines.

public boolean assertSameTrimmed ( $needle, $haystack )
$needle string
$haystack string

                public function assertSameTrimmed($needle, $haystack)
{
    return $this->assertSame($this->trimContent($needle), $this->trimContent($haystack));
}

            
beforeSetup() public method

Method which is executed before the setUp() method in order to inject data on before Setup.

Make sure to call the parent beforeSetup() method when overwriting this method.

See also luya\testsuite\cases\BaseTestSuite::beforeSetup().

public void beforeSetup ( )

                public function beforeSetup()
{
    parent::beforeSetup();
    
    $_SERVER['SCRIPT_FILENAME'] = 'index.php';
    $_SERVER['SCRIPT_NAME'] =  '/index.php';
    $_SERVER['REQUEST_URI'] = '/';
}

            
beforeTearDown() public method (available since version 1.0.2)

Defined in: luya\testsuite\cases\BaseTestSuite::beforeTearDown()

This method is triggered before the application test case tearDown() method is running.

public void beforeTearDown ( )

                public function beforeTearDown()
{
}

            
bootApplication() public method (available since version 1.0.2)
public void bootApplication ( luya\base\Boot $boot )
$boot luya\base\Boot

                public function bootApplication(Boot $boot)
{
    $boot->applicationWeb();
}

            
fixture() public method

Defined in: luya\testsuite\cases\BaseTestSuite::fixture()

Get Fixture Object

public luya\testsuite\fixtures\ActiveRecordFixture fixture ( $fixtureClass )
$fixtureClass string

                public function fixture($fixtureClass)
{
    if (is_array($this->_fixtures)) {
        return array_key_exists($fixtureClass, $this->_fixtures) ? $this->_fixtures[$fixtureClass] : false;
    }
    return false;
}

            
fixtures() public method (available since version 1.1.0)

Defined in: luya\testsuite\cases\BaseTestSuite::fixtures()

Defines a list of fixtures classes which can be loaded.

Example fixtures list:

public function fixtures()
{
   return [
       'app\fixtures\MyTestFixture',
       MySuperFixture::class,
   ];
}
public array fixtures ( )

                public function fixtures()
{
    return [];
}

            
getConfigArray() public abstract method

Defined in: luya\testsuite\cases\BaseTestSuite::getConfigArray()

Provide Configurtion Array.

public abstract void getConfigArray ( )

                abstract public function getConfigArray();

            
invokeMethod() public method (available since version 1.0.8)

Defined in: luya\testsuite\cases\BaseTestSuite::invokeMethod()

Call a private or protected method from an object and return the value.

public function testProtectedMethod()
{
    // assuming MyObject has a protected method like:
    // protected function hello($title)
    // {
    //     return $title;
    // }
    $object = new MyObject();

    $this->assertSame('Hello World', $this->invokeMethod($object, 'hello', ['Hello World']));
}
public mixed invokeMethod ( &$object, $methodName, array $parameters = [] )
$object object

The object the method exists from.

$methodName string

The name of the method which should be called.

$parameters array

An array of paremters which should be passed to the method.

                public function invokeMethod(&$object, $methodName, array $parameters = [])
{
    $reflection = new \ReflectionClass(get_class($object));
    $method = $reflection->getMethod($methodName);
    $method->setAccessible(true);
    return $method->invokeArgs($object, $parameters);
}

            
set_up() protected method

Defined in: luya\testsuite\cases\BaseTestSuite::set_up()

See also \PHPUnit\Framework\TestCase::setUp().

protected void set_up ( )

                protected function set_up() {
    parent::set_up();
    $this->beforeSetup();
    
    $boot = new Boot();
    $boot->setConfigArray($this->getConfigArray());
    $boot->mockOnly = true;
    $boot->setBaseYiiFile('vendor/yiisoft/yii2/Yii.php');
    $this->bootApplication($boot);
    $this->boot = $boot;
    $this->app = $boot->app;
    
    $this->afterSetup();
    $this->setupFixtures();
}

            
setupFixtures() public method (available since version 1.1.0)

Defined in: luya\testsuite\cases\BaseTestSuite::setupFixtures()

Create all fixtures from fixtures() list.

public void setupFixtures ( )

                public function setupFixtures()
{
    if ($this->_fixtures === null) {
        $loadedFixtures = [];
        foreach ($this->fixtures() as $fixtureClass) {
            $loadedFixtures[$fixtureClass] = Yii::createObject($fixtureClass);
        }
        $this->_fixtures = $loadedFixtures;
    }
}

            
tearDownFixtures() public method (available since version 1.1.0)

Defined in: luya\testsuite\cases\BaseTestSuite::tearDownFixtures()

Run cleanup() on all loaded fixtures.

public void tearDownFixtures ( )

                public function tearDownFixtures()
{
    if (is_array($this->_fixtures)) {
        /** @var ActiveRecordFixture $object */
        foreach ($this->_fixtures as $object) {
            $object->cleanup();
        }
    }
}

            
tear_down() protected method

Defined in: luya\testsuite\cases\BaseTestSuite::tear_down()

See also \PHPUnit\Framework\TestCase::tearDown().

protected void tear_down ( )

                protected function tear_down() {
    // Any clean up needed related to `set_up()`.
    parent::tear_down();
    $this->beforeTearDown();
    $this->tearDownFixtures();
    unset($this->app, $this->boot);
}

            
trimContent() protected method

Defined in: luya\testsuite\cases\BaseTestSuite::trimContent()

No Spaces and No Newline Trims the given text. Remove whitespaces, tabs and other chars in order to compare readable formated texts.

protected string trimContent ( $text )
$text string
return string

The trimmed text.

                protected function trimContent($text)
{
    return str_replace(['> ', ' <'], ['>', '<'], trim(preg_replace('/\s+/', ' ', $text)));
}

            
trimSpaces() protected method

Defined in: luya\testsuite\cases\BaseTestSuite::trimSpaces()

No Spaces with Newline

Removes tabs and spaces from a string. But keeps newlines.

protected string trimSpaces ( $text )
$text string

                protected function trimSpaces($text)
{
    $lines = null;
    foreach (preg_split("/((\r?\n)|(\r\n?))/", $text) as $line) {
        if (!empty($line)) {
            $lines .= $this->trimContent($line) . PHP_EOL;
        }
    }
    return $lines;
}