/** * Creates a new ManyMaybe instance from the given collection, * thereby composing each collection item into an Maybe monad. * * @param array $values */ protected function __construct(array $values) { $unit = function ($value) { return Maybe::unit($value); }; parent::__construct(array_map($unit, $values)); }
public function test_belongs_to_has_many() { $this->installAndIncludeModels('Many,Belong'); $hasMany = new Many(); $belongsTo = new Belong(); $many = $hasMany->create(array('name' => 'test')); $belongs1 = $belongsTo->create(array('name' => 'belongs1')); $belongs2 = $belongsTo->create(array('name' => 'belongs2')); $array = array($belongs1, $belongs2); $many->belong->set($array); $result = $hasMany->findFirstBy('name', 'test', array('include' => 'belongs')); $this->assertEqual(2, count($result->belongs)); }