0
votes

I have written some unit tests in my Laravel project and trying to execute them through a third party app. I can execute these tests in the command line with phpunit but my requirement is to run them externally(to automate). Is that possible at all? It seems my custom classes/Laravel helper classes are not accessible when running them externally.

use App\ZZZ\Scrape;
use App\ZZZ\Theme1;
use App\ZZZ\Theme2;

class ScrapeTest extends TestCase
{
protected static $scrape;
protected static $sxe;
protected static $theme;
protected static $url;
protected static $section;
protected static $extArray;
protected static $intArray;
protected static $safetyArray;
protected static $perfArray;
protected static $output;

public static function setUpBeforeClass()
{
    Config::set('aws.s3Path', 'zz/test/');
    self::$url = "http://www.testsite.com.au";
    self::$section = "testSection";
    self::$scrape = new Scrape(self::$url, self::$section);
    self::$scrape->html = self::$scrape->getHTML();
    self::$sxe = self::$scrape->getSimpleXmlElement();

    if(self::$scrape->isDarkTheme(self::$sxe))
    {
        self::$theme = new Theme1(self::$url,self::$section);
    }
    else
        self::$theme = new Theme2(self::$url,self::$section);

    self::$output = new stdClass();

    //exterior features
    self::$extArray = self::$theme->getFeatureDetails(self::$sxe, "exterior");
    self::$output->ExteriorFeatures = new stdClass();
    self::$output->ExteriorFeatures->Feature = self::$extArray;

    //interior features
    self::$intArray = self::$theme->getFeatureDetails(self::$sxe, "interior");
    self::$output->InteriorFeatures = new stdClass();
    self::$output->InteriorFeatures->Feature = self::$intArray;


}

public function testGetLeadingText()
{
    $result = self::$scrape->getLeadingText(self::$sxe);
    $this->assertNotNull($result, "No leading text");
}

public function testFetchColours()
{
    $result = self::$scrape->FetchColours();
    $this->assertNotNull($result, "Error with decoding colour API");
    $this->assertInternalType('array', $result->data, "FetchAPI  output is not an array");
    $this->assertNotSame(null, $result->data, "FetchAPI  output is an empty array");
 }  

}

Some of the errors I get:

Class 'TestCase' not found in C:...\ScrapeTest.php

Class 'Config' not found in C:...\ScrapeTest.php

Class 'App\ZZZ\Scrape' not found in C:...\ScrapeTest.php ...

Any help is very much appreciated. Thanks in advance.

1
Could you show us your UnitTest.php contentPaladiN
Thanks for trying to help. One of the errors I get :Fatal error: Class 'App\ZZZ\Scrape' not found in C:\...\ScrapeTest.php. It complains about the TestCase class as well. Please let me know if you need more details.NL10023
I have updated my questionNL10023
Can someone please help?NL10023

1 Answers

0
votes

Your test file seems incomplete.

You need to declare the namespace in which the test class is present and also where test case is present.

Eg. if in your case testcase is in Tests and test file in Tests\ZZZ, then use this in beginning of file.

namespace Tests\ZZZ;

use Tests\TestCase;