#StackBounty: #plugins #php #plugin-development #unit-tests Why is one phpunit test throwing an error on one class when all other class…

Bounty: 50

I’m working on the Liquid Messages plugin. There are some basic PHPUnit tests existing for it and when I run phpunit all pass except for one. It errors out:

There was 1 error:
1) GCS_Async_Test::test_class_access
Exception: Invalid GC_Sermons_Plugin property: async
/long/path/wp-content/plugins/lqd-messages/gc-sermons.php:330
/long/path/wp-content/plugins/lqd-messages/tests/test-async.php:10

The weird thing is that gc-sermons.php contains a number of properties similar to this one. They are initialized like so:

protected $sermons
protected $taxonomies
protected $async

Instances of the classes are attached to the properties:

        public function plugin_classes()
        {
            require_once self::$path . 'functions.php';

            // Attach other plugin classes to the base plugin class.
            $this->sermons = new GCS_Sermons($this);
            $this->taxonomies = new GCS_Taxonomies($this->sermons);
            $this->async = new GCS_Async($this);
            $this->shortcodes = new GCS_Shortcodes($this);
        }

If we look at GCS_Sermons, which is similar to GCS_Async in that it extends another class we see:

class GCS_Sermons extends GCS_Post_Types_Base {

Essentially the same as GCS_Async:

class GCS_Async extends WP_Async_Task {

If we look at the tests we see that the same test is run against GCS_Sermons as GCS_Async, but only fails with GCS_Async:

    function test_class_access() {
        $this->assertTrue( gc_sermons()->sermons instanceof GCS_Sermons );
    }

    function test_class_access() {
        $this->assertTrue( gc_sermons()->async instanceof GCS_Async );
    }

Any ideas why?


Get this bounty!!!

#StackBounty: #magento2 #controllers #unit-tests #framework Class 'MagentoTestFrameworkTestCaseAbstractController' not found…

Bounty: 100

I tried to make a unit test for my custom module like this:

app/code/MyCompany/UnitTest/Test/Unit/Controller/SpinTest.php

namespace MyCompanyUnitTestController;

class SpinTest extends MagentoTestFrameworkTestCaseAbstractController
{
    public function testLogin()
    {
        $params = [
          'customer_id' => '3'
        ];
        $this->getRequest()->setPostValue($params);
        $this->dispatch('spin/run');
        $result = $this->getResponse()->getBody();
        $this->assertEquals('200', $result['status']);
    }
}

And ran the unit from terminal:

vendor/phpunit/phpunit/phpunit -c dev/tests/unit/phpunit.xml.dist app/code/MyCompany/UnitTest/Test/Unit/Controller/

But i got an error like this:

Class ‘MagentoTestFrameworkTestCaseAbstractController’ not found in
/var/www/mage2/app/code/MyCompany/UnitTest/Test/Unit/Controller/SpinTest.php
on line 4


Get this bounty!!!

#StackBounty: #magento2 #controllers #unit-tests #framework Class 'MagentoTestFrameworkTestCaseAbstractController' not found…

Bounty: 100

I tried to make a unit test for my custom module like this:

app/code/MyCompany/UnitTest/Test/Unit/Controller/SpinTest.php

namespace MyCompanyUnitTestController;

class SpinTest extends MagentoTestFrameworkTestCaseAbstractController
{
    public function testLogin()
    {
        $params = [
          'customer_id' => '3'
        ];
        $this->getRequest()->setPostValue($params);
        $this->dispatch('spin/run');
        $result = $this->getResponse()->getBody();
        $this->assertEquals('200', $result['status']);
    }
}

And ran the unit from terminal:

vendor/phpunit/phpunit/phpunit -c dev/tests/unit/phpunit.xml.dist app/code/MyCompany/UnitTest/Test/Unit/Controller/

But i got an error like this:

Class ‘MagentoTestFrameworkTestCaseAbstractController’ not found in
/var/www/mage2/app/code/MyCompany/UnitTest/Test/Unit/Controller/SpinTest.php
on line 4


Get this bounty!!!

#StackBounty: #magento2 #controllers #unit-tests #framework Class 'MagentoTestFrameworkTestCaseAbstractController' not found…

Bounty: 100

I tried to make a unit test for my custom module like this:

app/code/MyCompany/UnitTest/Test/Unit/Controller/SpinTest.php

namespace MyCompanyUnitTestController;

class SpinTest extends MagentoTestFrameworkTestCaseAbstractController
{
    public function testLogin()
    {
        $params = [
          'customer_id' => '3'
        ];
        $this->getRequest()->setPostValue($params);
        $this->dispatch('spin/run');
        $result = $this->getResponse()->getBody();
        $this->assertEquals('200', $result['status']);
    }
}

And ran the unit from terminal:

vendor/phpunit/phpunit/phpunit -c dev/tests/unit/phpunit.xml.dist app/code/MyCompany/UnitTest/Test/Unit/Controller/

But i got an error like this:

Class ‘MagentoTestFrameworkTestCaseAbstractController’ not found in
/var/www/mage2/app/code/MyCompany/UnitTest/Test/Unit/Controller/SpinTest.php
on line 4


Get this bounty!!!

#StackBounty: #magento2 #controllers #unit-tests #framework Class 'MagentoTestFrameworkTestCaseAbstractController' not found…

Bounty: 100

I tried to make a unit test for my custom module like this:

app/code/MyCompany/UnitTest/Test/Unit/Controller/SpinTest.php

namespace MyCompanyUnitTestController;

class SpinTest extends MagentoTestFrameworkTestCaseAbstractController
{
    public function testLogin()
    {
        $params = [
          'customer_id' => '3'
        ];
        $this->getRequest()->setPostValue($params);
        $this->dispatch('spin/run');
        $result = $this->getResponse()->getBody();
        $this->assertEquals('200', $result['status']);
    }
}

And ran the unit from terminal:

vendor/phpunit/phpunit/phpunit -c dev/tests/unit/phpunit.xml.dist app/code/MyCompany/UnitTest/Test/Unit/Controller/

But i got an error like this:

Class ‘MagentoTestFrameworkTestCaseAbstractController’ not found in
/var/www/mage2/app/code/MyCompany/UnitTest/Test/Unit/Controller/SpinTest.php
on line 4


Get this bounty!!!

#StackBounty: #magento2 #controllers #unit-tests #framework Class 'MagentoTestFrameworkTestCaseAbstractController' not found…

Bounty: 100

I tried to make a unit test for my custom module like this:

app/code/MyCompany/UnitTest/Test/Unit/Controller/SpinTest.php

namespace MyCompanyUnitTestController;

class SpinTest extends MagentoTestFrameworkTestCaseAbstractController
{
    public function testLogin()
    {
        $params = [
          'customer_id' => '3'
        ];
        $this->getRequest()->setPostValue($params);
        $this->dispatch('spin/run');
        $result = $this->getResponse()->getBody();
        $this->assertEquals('200', $result['status']);
    }
}

And ran the unit from terminal:

vendor/phpunit/phpunit/phpunit -c dev/tests/unit/phpunit.xml.dist app/code/MyCompany/UnitTest/Test/Unit/Controller/

But i got an error like this:

Class ‘MagentoTestFrameworkTestCaseAbstractController’ not found in
/var/www/mage2/app/code/MyCompany/UnitTest/Test/Unit/Controller/SpinTest.php
on line 4


Get this bounty!!!

#StackBounty: #magento2 #controllers #unit-tests #framework Class 'MagentoTestFrameworkTestCaseAbstractController' not found…

Bounty: 100

I tried to make a unit test for my custom module like this:

app/code/MyCompany/UnitTest/Test/Unit/Controller/SpinTest.php

namespace MyCompanyUnitTestController;

class SpinTest extends MagentoTestFrameworkTestCaseAbstractController
{
    public function testLogin()
    {
        $params = [
          'customer_id' => '3'
        ];
        $this->getRequest()->setPostValue($params);
        $this->dispatch('spin/run');
        $result = $this->getResponse()->getBody();
        $this->assertEquals('200', $result['status']);
    }
}

And ran the unit from terminal:

vendor/phpunit/phpunit/phpunit -c dev/tests/unit/phpunit.xml.dist app/code/MyCompany/UnitTest/Test/Unit/Controller/

But i got an error like this:

Class ‘MagentoTestFrameworkTestCaseAbstractController’ not found in
/var/www/mage2/app/code/MyCompany/UnitTest/Test/Unit/Controller/SpinTest.php
on line 4


Get this bounty!!!

#StackBounty: #magento2 #controllers #unit-tests #framework Class 'MagentoTestFrameworkTestCaseAbstractController' not found…

Bounty: 100

I tried to make a unit test for my custom module like this:

app/code/MyCompany/UnitTest/Test/Unit/Controller/SpinTest.php

namespace MyCompanyUnitTestController;

class SpinTest extends MagentoTestFrameworkTestCaseAbstractController
{
    public function testLogin()
    {
        $params = [
          'customer_id' => '3'
        ];
        $this->getRequest()->setPostValue($params);
        $this->dispatch('spin/run');
        $result = $this->getResponse()->getBody();
        $this->assertEquals('200', $result['status']);
    }
}

And ran the unit from terminal:

vendor/phpunit/phpunit/phpunit -c dev/tests/unit/phpunit.xml.dist app/code/MyCompany/UnitTest/Test/Unit/Controller/

But i got an error like this:

Class ‘MagentoTestFrameworkTestCaseAbstractController’ not found in
/var/www/mage2/app/code/MyCompany/UnitTest/Test/Unit/Controller/SpinTest.php
on line 4


Get this bounty!!!

#StackBounty: #magento2 #controllers #unit-tests #framework Class 'MagentoTestFrameworkTestCaseAbstractController' not found…

Bounty: 100

I tried to make a unit test for my custom module like this:

app/code/MyCompany/UnitTest/Test/Unit/Controller/SpinTest.php

namespace MyCompanyUnitTestController;

class SpinTest extends MagentoTestFrameworkTestCaseAbstractController
{
    public function testLogin()
    {
        $params = [
          'customer_id' => '3'
        ];
        $this->getRequest()->setPostValue($params);
        $this->dispatch('spin/run');
        $result = $this->getResponse()->getBody();
        $this->assertEquals('200', $result['status']);
    }
}

And ran the unit from terminal:

vendor/phpunit/phpunit/phpunit -c dev/tests/unit/phpunit.xml.dist app/code/MyCompany/UnitTest/Test/Unit/Controller/

But i got an error like this:

Class ‘MagentoTestFrameworkTestCaseAbstractController’ not found in
/var/www/mage2/app/code/MyCompany/UnitTest/Test/Unit/Controller/SpinTest.php
on line 4


Get this bounty!!!

#StackBounty: #magento2 #controllers #unit-tests #framework Class 'MagentoTestFrameworkTestCaseAbstractController' not found…

Bounty: 100

I tried to make a unit test for my custom module like this:

app/code/MyCompany/UnitTest/Test/Unit/Controller/SpinTest.php

namespace MyCompanyUnitTestController;

class SpinTest extends MagentoTestFrameworkTestCaseAbstractController
{
    public function testLogin()
    {
        $params = [
          'customer_id' => '3'
        ];
        $this->getRequest()->setPostValue($params);
        $this->dispatch('spin/run');
        $result = $this->getResponse()->getBody();
        $this->assertEquals('200', $result['status']);
    }
}

And ran the unit from terminal:

vendor/phpunit/phpunit/phpunit -c dev/tests/unit/phpunit.xml.dist app/code/MyCompany/UnitTest/Test/Unit/Controller/

But i got an error like this:

Class ‘MagentoTestFrameworkTestCaseAbstractController’ not found in
/var/www/mage2/app/code/MyCompany/UnitTest/Test/Unit/Controller/SpinTest.php
on line 4


Get this bounty!!!