Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8650425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:49:07+00:00 2026-06-12T13:49:07+00:00

I am trying to test a plugin model in a CakePHP app. The model

  • 0

I am trying to test a plugin model in a CakePHP app. The model uses a table called ‘cron_jobs’ for which I have set up this fixture:

class CronJobFixture extends CakeTestFixture
{
    public $import = array('table' => 'cron_jobs');
}

My test class works well and looks like this:

<?php

App::uses('CronJob', 'Cron.Model');

class CronJobTest extends CakeTestCase
{

    public $fixtures = array('plugin.cron.CronJob');

    public function setUp()
    {
        parent::setUp();
        $this->CronJob = new CronJob();
    }

    public function testCollectFailsOnMissingComponent()
    {
        $this->setExpectedException('InvalidArgumentException');
        $this->CronJob->collect(null);
    }

    public function testCollectSilentOnMissingComponent()
    {
        $result = $this->CronJob->collect('SomeNonExistingComponent');
        $this->assertEquals(null, $result);
    }

    // Some more tests that will need the fixture ....
}

If I then change the test setup by replacing

$this->CronJob = new CronJob();

with

$this->CronJob = ClassRegistry::init("CronJob");

to load the fixture, I get this error:

CronJobTest::testCollectSilentOnMissingComponent PDOException:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an
error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near ‘collect’ at
line 1

The error can’t be generated by anything in the CronJob class, because the code being covered by the two tests doesn’t access the database. I am sure my test database is configured correctly, because I get a database connection error if I make changes to the test database configuration.

I am using CakePHP 2.2.1, PHPUnit 3.6.12, PHP 5.4

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:49:08+00:00Added an answer on June 12, 2026 at 1:49 pm

    Fixtures prefer the lowercase underscored convention. Do this:

    public $fixtures = array('plugin.cron.cron_job');
    

    Since it’s a plugin; be sure to use the plugin notation with ClassRegistry::init like this:

    $this->CronJob = ClassRegistry::init('Cron.CronJob');
    

    That error happens because CakePHP is lazy loading a non-plugin CronJob model without your collect() method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to mavenize my grails 2.1 app which uses build-test-data-2.0.3, for some
All, I am trying to test my grails app using Hudson. I have in
I'm trying to integration test a class that uses the Mail Plugin. When I
I'm trying to do a little test-plugin using NPAPI for firefox. This is my
I am trying to create a plugin for Screwturn Wiki. I have the test
I am trying to test the jQuery Address Plugin and it seems to not
just trying to test for equality in this piece of code, but getting a
I trying to test an AccountController that uses DotNetOpenAuth but I am running into
I am trying to test a sinatra app using minitest and capybara but get
I'm trying to set up a rails 3.2 app with the new compass-rails gem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.