开发者

php unit test in silverstripe

Want to know how to start write unit test for this function in siverstripe?

function getAvailableScanners($date){
        $scanners = self::get("Scanner");

        $startDate = date("Y-m-d", strtotime("-".self::$daysNeededAfterLastGig." days", strtotime($date)));
        $endDate = date("Y-m-d", strtotime("+".self::$daysNeededBeforeNextGig." days", strtotime($date)));

        foreach($scanners as $scanner){
            $events = EventProduct::get("EventProduct", "\"ExpiryDate\">='$startDate' AND \"ExpiryDate\"<='$开发者_JAVA技巧endDate'");
            if($events){
                foreach($events as $event){
                    if($scanner->isAssignedToEvent($event)){
                        $scanners->remove($scanner);
                    }
                }
            }
        }

        return $scanners;
    }


The documentation has several good pages on writing tests with SilverStripe

http://doc.silverstripe.org/sapphire/en/topics/testing/

To get started want to make a fixture file with a bunch of those EventProduct products (documentation has an example of this).

Also you can find lots of good testing examples from looking at the built-in tests. I've picked out the BlogHolder tests as this does something very similar to what you're looking for (testing a customer 'getter' with filters)

https://github.com/silverstripe/silverstripe-blog/blob/master/tests/BlogHolderTest.php (and the fixture file is BlogTree.yml in that same folder)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜