<commit_before><?php
namespace test;
define('EMONCMS_EXEC', TRUE);
include_once dirname(dirname(dirname(dirname(__FILE__)))) . '/process_settings.php';
include_once dirname(dirname(dirname(dirname(__FILE__)))) . '/Lib/EmonLogger.php';
include_once dirname(__FILE__) . '/PHPFina.php';
use \PHPFina as PHPFina;
use \EmonLogger as EmonLogger;

$settings = array('datadir' => '/tmp/');
$options = array('interval'=>10);
$feedid = 0;

class PHPFinaTest extends \PHPUnit\Framework\TestCase {

    // Done once (before & after) for each 
    // public function named "test[METHOD]()"
    public function setUp() {
        global $settings, $options, $feedid;
        $this->options = $options;
        $this->settings = $settings;
        $this->feedid = $feedid;
        $this->start = strtotime("-1 week"); // 2 week interval ( 20160 minutes / 336 hours)
        $this->end = strtotime("+1 week");
        $this->interval = 1500; // 25 mins between points
        $this->outinterval = 1500; //?? not sure if this is good
        $this->usertimezone = 'Europe/London';
        $this->baseUrl = 'http://localhost/emoncms';
        $this->engine = new PHPFina($settings);
        $this->create();
    }
    public function tearDown(){ 
        $this->delete();
    }

    // used in PHPUnit's setUp() and tearDown() above
    public function create() {
        $this->assertTrue($this->engine->create($this->feedid, $this->options));
    }
    public function delete() {
        $this->assertNull($this->engine->delete($this->feedid));
    }


    // Required Engine Methods....

    public function testGet_meta() {
        $meta = $this->engine->get_meta($this->feedid);
        $this->assertInstanceOf(\stdClass::class, $meta);
    }

    public function testUpdate() {
        $value = $this->engine->update($this->feedid,time(),rand(200,1500));
        $this->assertNotFalse($value);
    }

    public function testLastvalue() {
        $array = $this->engine->lastvalue($this->feedid);
        $this->assertNotFalse($array);
    }

    public function testGet_data() {
        $skipmissing = 0;
        $limitinterval = 1;
		$data = $this->engine->get_data($this->feedid,$this->start,$this->end,$this->interval,$skipmissing,$limitinterval);
        $this->assertTrue(!empty($data) && empty($data['success']), 'no blank result or success == false');
    }

    public function testCsv_export() {
        // $this->engine->csv_export($this->feedid,$this->start,$this->end,$this->outinterval,$this->usertimezone);
        $urlToControllerThatGeneratesCsvDownload = $this->baseUrl.'/feed/csvexport';
        $params = array(
            'id'=>$this->feedid,
            'start'=>$this->start,
            'end'=>$this->end,
            'interva'=>$this->outinterval,
            'timeformat'=>$this->usertimezone
        );
        $urlToControllerThatGeneratesCsvDownload.=('?'.http_build_query($params));
        $response = $this->call('GET', $urlToControllerThatGeneratesCsvDownload);
        $this->assertTrue(strpos($response->content(), 'csv') !== false);
	}

    public function testGet_average_DMY() {<commit_msg>minor fix to phpfina test<commit_after><?php
namespace test;
define('EMONCMS_EXEC', TRUE);
include_once dirname(dirname(dirname(dirname(__FILE__)))) . '/process_settings.php';
include_once dirname(dirname(dirname(dirname(__FILE__)))) . '/Lib/EmonLogger.php';
include_once dirname(__FILE__) . '/PHPFina.php';
use \PHPFina as PHPFina;
use \EmonLogger as EmonLogger;

$settings = array('datadir' => '/tmp/');
$options = array('interval'=>10);
$feedid = 0;

class PHPFinaTest extends \PHPUnit\Framework\TestCase {

    // Done once (before & after) for each 
    // public function named "test[METHOD]()"
    public function setUp() {
        global $settings, $options, $feedid;
        $this->options = $options;
        $this->settings = $settings;
        $this->feedid = $feedid;
        $this->start = strtotime("-1 week"); // 2 week interval ( 20160 minutes / 336 hours)
        $this->end = strtotime("+1 week");
        $this->interval = 1500; // 25 mins between points
        $this->average = 0;
        $this->outinterval = 1500; //?? not sure if this is good
        $this->usertimezone = 'Europe/London';
        $this->baseUrl = 'http://localhost/emoncms';
        $this->engine = new PHPFina($settings);
        $this->create();
    }
    public function tearDown(){ 
        $this->delete();
    }

    // used in PHPUnit's setUp() and tearDown() above
    public function create() {
        $this->assertTrue($this->engine->create($this->feedid, $this->options));
    }
    public function delete() {
        $this->assertNull($this->engine->delete($this->feedid));
    }


    // Required Engine Methods....

    public function testGet_meta() {
        $meta = $this->engine->get_meta($this->feedid);
        $this->assertInstanceOf(\stdClass::class, $meta);
    }

    public function testUpdate() {
        $value = $this->engine->update($this->feedid,time(),rand(200,1500));
        $this->assertNotFalse($value);
    }

    public function testLastvalue() {
        $array = $this->engine->lastvalue($this->feedid);
        $this->assertNotFalse($array);
    }

    public function testGet_data() {
        $skipmissing = 0;
        $limitinterval = 1;
		$data = $this->engine->get_data($this->feedid,$this->start,$this->end,$this->interval,$skipmissing,$limitinterval);
        $this->assertTrue(!empty($data) && empty($data['success']), 'no blank result or success == false');
    }

    public function testCsv_export() {
        // $this->engine->csv_export($this->feedid,$this->start,$this->end,$this->outinterval,$this->usertimezone);
        $urlToControllerThatGeneratesCsvDownload = $this->baseUrl.'/feed/csvexport';
        $params = array(
            'id'=>$this->feedid,
            'start'=>$this->start,
            'end'=>$this->end,
            'interval'=>$this->outinterval,
            'average'=>$this->average,
            'timeformat'=>$this->usertimezone
        );
        $urlToControllerThatGeneratesCsvDownload.=('?'.http_build_query($params));
        $response = $this->call('GET', $urlToControllerThatGeneratesCsvDownload);
        $this->assertTrue(strpos($response->content(), 'csv') !== false);
	}

    public function testGet_average_DMY() {
{'fraction_non_alphanumeric': 0.1747465145754119, 'fraction_numerical': 0.010614702154626109, 'mean_word_length': 3.123448726322665, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 132, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4650539', 'n_tokens_mistral': 1976, 'n_tokens_neox': 1882, 'n_words': 353}