0

I am trying to run tests on helper functions, so I created a cron job to test them. I have already verified that the cronjob itself is set up correctly (it is running when I have simple logging statements in it). Now I want to set it up to run functions from my helper file.

In config.xml:

...
<crontab>
    <jobs>
        <testjob>
            <schedule><cron_expr>*/1 * * * *</cron_expr></schedule>
            <run><model>module/crontest::testSuite</model></run>
        </testjob>
    </jobs>
</crontab>
<helpers>
        <module>
            <class>Namespace_Module_Helper</class>
        </module>
    </helpers>
...

Then in my Crontest.php file, under Model:

class Namespace_Module_Model_Crontest
{
protected $helper = Mage::helper('module');
protected $testData = null;


public function testSuite() {
    Mage::log("HELPER FUNCTION TESTS", null, 'test.log', true);

    $testData = $helper->getApiUrl();
    Mage::log("Ran getApiUrl: {$testData}", null, 'test.log', true);
}

When this runs (every minute), nothing appears in any log file. However, I believe I have narrowed down the problem to the first variable declaration: $helper. I think I'm doing that wrong, because when that line was removed, I got errors, and it was evident that the cron job was running. But with the line, it's failing silently and I'm not sure why. What is wrong with how I'm calling the helper functions?

1

I solved my problem. Hopefully this helps some other poor soul. Although if anyone can tell me how to make it so my program doesn't silently fail, that would be lovely because it is less than ideal to comment things out line by line until it works, and then work backwards from there.

The problem was, as I thought, protected $helper = Mage::helper('module');. The issue was, Mage doesn't seem to work outside of functions. So instead, I declared $helper inside my function. Then it worked! I guess Mage needs an actual instance of something first, which makes sense in hindsight.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.