Utilizing phpunit testing in elgg to write custom test and test classes just like in bundled plugins

I want to know how to unit test classes. When i attempt to create test case and use any class. This code below doesn't work because my class wasn't found. But that's how other plugins done.

<?php

 

namespace Elgg\HeyloSP;

 

class SampleClassTest extends \Elgg\TestCaseUnitTest {
    public function testHello() {
        $this->assertEquals('Hello'SampleClass::hello());
    }
}

 

But when i do this code, it works.

<?php

 

require_once getcwd() . '\mod\heylo_system_partnership\classes\Elgg\HeyloSP\SampleClass.php';

 

use Elgg\HeyloSP\SampleClass;

 

class SampleClassTest extends \Elgg\TestCaseUnitTest {
    public function testHello() {
        $this->assertEquals('Hello'SampleClass::hello());
    }
}

 

Is there a way to make a testing just like the bundled plugins? 

  • Look at this.

    BTW, TestCaseUnitTest is a legacy class.

  • Thanks for the help! I find it funny that it didn't work my classes when i dont implement PluginTest trait and call

    $this->startPlugin()

    function to work on the classes.

    This is the result of my new testing unit code

    <?php
    namespace Elgg\HeyloSP;

     

    use Elgg\Plugins\PluginTesting;

     

    class SampleClassTest extends \Elgg\UnitTestCase {
        use PluginTesting;

     

        public function up() {

     

        }

     

        public function down() {

     

        }

     

        public function testHello() {
            $this->startPlugin();
            $this->assertEquals('Hello'SampleClass::hello());
        }
    }