Jump to:

3431 Posts in 1058 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Missing tables in Test Database

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 801 Views
  • fab-s
    Avatar
    Community Member
    2 Posts

    Missing tables in Test Database Link to this post

    Hello,

    I have a problem with testing and fixtures. The message says:

    Couldn't run query:
    INSERT INTO "ProductSearchServiceConfigurationItem" ("Name", "Value") VALUES ('user', 'foo123')

    Table 'tmpdb1796961.ProductSearchServiceConfigurationItem' doesn't exist

    ProductSearchServiceConfigurationItem is a custom DataObject introduced in the module I want to test. I ran /dev/build and in the production database the table exists but obviously SaphireTest does not create the corresponding table in the tmp database.

    Is there anything I missed to set up?

    If it helps, here is the code of the class:

    class ProductSearchServiceConfigurationItem extends DataObject
    {
       static $db = array('Name' => 'Varchar',
        'Value' => 'Varchar'
        );
       static $has_one = array('SearchService' => 'ProductSearchService');

       public function getCMSFields()
       {
          $fields = new FieldSet(new TextField('Name', 'Name'),
           new TextField('Value', 'Value')
           );
          return $fields;
       }
    }

    and the relevant part of the fixture file:

    ProductSearchServiceConfigurationItem:
       conf_1:
          Name: user
          Value: foo123

    Edit: It is getting stranger the more i try...

    ?debugmanifest=1 appended to the test case URL shows that the classes are correctly defined in the manifest

    'productsearchservice' => '/var/www/[...]/code/ProductSearchService.php',
    'productsearchserviceconfigurationitem' => '/var/www/[...]/code/ProductSearchServiceConfigurationItem.php',

    but if I try to autoload them with this code at the beginning of the test case file:

    class_exists('ProductSearchService') or die('class ProductSearchService not found');
    class_exists('ProductSearchServiceConfigurationItem') or die('class ProductSearchServiceConfigurationItem not found');

    it fails:

    class ProductSearchService not found

    Edit 2: okay, debugmanifest does not show the manifest actually used by the tests... I added these lines to the test case file:

    global $_CLASS_MANIFEST;
    echo '<pre>';
    var_dump($_CLASS_MANIFEST['productsearchservice']);
    var_dump($_CLASS_MANIFEST['productsearchserviceconfigurationitem']);

    and got

    [Notice] Undefined index: productsearchservice

    The same goes with $_ALL_CLASSES

    now how can I influence the test manifest?

  • apiening
    Avatar
    Community Member
    55 Posts

    Re: Missing tables in Test Database Link to this post

    hi fab-s,

    all you need to do is dev/build?flush=all. to be on the safe side you could empty your cache folder manually. how does your test look like? does that error give you a backtrace?

    cheers

    andy

  • fab-s
    Avatar
    Community Member
    2 Posts

    Re: Missing tables in Test Database Link to this post

    Thank you very much Andy, emptying the cache folder did the trick! Sometimes the solution is just too easy...

    Cheers and Merry Christmas

    Fab

    801 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.