Jump to:

23371 Posts in 18161 Topics by 2865 members

General Questions

SilverStripe Forums » General Questions » Unit Test Help

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 698 Views
  • Ryoken
    Avatar
    Community Member
    18 Posts

    Unit Test Help Link to this post

    I'm writing Unit tests for some of my code, and I'm running into some problems..

    I'll make a basic scenario --

    class Alpha extends page{

    static $belongs_many_many = array('Betas' => 'Beta');
    }

    class Beta extends page{

    static $many_many = array('Alphas' => 'Alpha');
    }

    Now in my yml file I have :

    Alpha:
    a1:
    Title: Alpha 1

    Beta:
    b1:
    Title: Beta 1
    Alphas: =>Alpha.a1

    When I try an run one of my tests I get:
    'Undefined index: Alpha'
    PHPUnit_Util_ErrorHandler::handleError( 8, Undefined index: Alpha, ...path..., 246, Array)
    YamlFixture->parseFixtureVal(=>Alpha.a1)
    ...

    There really aren't many examples of dealing with many_many relations in SS's PHPUnit testing, so I'm clearly doing something wrong, but none of my tests have got me a working result :/

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: Unit Test Help Link to this post

    Have a look at ComponentSetTest. That has a many_many so you should be able to use that (and the yaml) as reference.

  • Ryoken
    Avatar
    Community Member
    18 Posts

    Re: Unit Test Help Link to this post

    Thanks, that helped me try a few things that solved the problem..

    The issue seems to be the order of elements in the YML file..

    Basically, and I guess it wasn't reflected in my sample code, I was defining b1, and it's relation to Alphas a1 before I had defined a1.

    698 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.