Pheasant\Tests\Examples\Hero::createHelper PHP Method

createHelper() public static method

public static createHelper ( $alias, $identity, $powers = [] )
    public static function createHelper($alias, $identity, $powers = array())
    {
        $hero = new Hero(array('alias' => $alias));
        $hero->save();
        $identity = new SecretIdentity(array('realname' => $identity));
        $hero->SecretIdentity = $identity;
        $identity->save();
        foreach ($powers as $power) {
            $power = new Power(array('description' => $power));
            $hero->Powers[] = $power;
            $power->save();
        }
        $hero->save();
        return $hero;
    }

Usage Example

Example #1
0
 public function testFilteringCollectionsReturnedByRelationships()
 {
     $spiderman = Hero::createHelper('Spider Man', 'Peter Parker', array('Super-human Strength', 'Spider Senses'));
     $superman = Hero::createHelper('Super Man', 'Clark Kent', array('Super-human Strength', 'Invulnerability'));
     $batman = Hero::createHelper('Batman', 'Bruce Wayne', array('Richness', 'Super-human Intellect'));
     $this->assertCount(2, $spiderman->Powers);
     $this->assertCount(1, $spiderman->Powers->filter('description LIKE ?', 'Super-human%')->toArray());
 }
All Usage Examples Of Pheasant\Tests\Examples\Hero::createHelper