public function testUpdateWithNewArray() { $new = Companies::create(array('name' => 'Acme, Inc.', 'active' => true)); $expected = array('name' => 'Acme, Inc.', 'active' => true); $result = $new->data(); $this->assertEqual($expected, $result); $new->foo = array('bar'); $expected = array('name' => 'Acme, Inc.', 'active' => true, 'foo' => array('bar')); $result = $new->data(); $this->assertEqual($expected, $result); $this->assertTrue($new->save()); $updated = Companies::find((string) $new->_id); $expected = 'bar'; $result = $updated->foo[0]; $this->assertEqual($expected, $result); $updated->foo[1] = 'baz'; $this->assertTrue($updated->save()); $updated = Companies::find((string) $updated->_id); $expected = 'baz'; $result = $updated->foo[1]; $this->assertEqual($expected, $result); }
public function testCrudMulti() { $large = Companies::create(array('name' => 'BigBoxMart', 'active' => true)); $medium = Companies::create(array('name' => 'Acme, Inc.', 'active' => true)); $small = Companies::create(array('name' => 'Ma & Pa\'s', 'active' => true)); foreach (array('large', 'medium', 'small') as $key) { $this->assertFalse(${$key}->exists()); $this->assertTrue(${$key}->save()); $this->assertTrue(${$key}->exists()); } $this->assertEqual(3, Companies::count()); $all = Companies::all(); $this->assertEqual(3, $all->count()); $match = 'BigBoxMart'; $filter = function ($entity) use(&$match) { return $entity->name == $match; }; foreach (array('BigBoxMart', 'Acme, Inc.', 'Ma & Pa\'s') as $match) { $this->assertTrue($all->first($filter)->exists()); } $this->assertEqual(array(true, true, true), array_values($all->delete())); $this->assertEqual(0, Companies::count()); }
public function testAbstractTypeHandling() { $key = Companies::meta('key'); foreach ($this->companiesData as $data) { $companies[] = Companies::create($data); $this->assertTrue(end($companies)->save()); $this->assertTrue(end($companies)->{$key}); } foreach (Companies::all() as $companies) { $this->assertTrue($companies->delete()); } }
protected static function _createCompany() { Companies::create(array('name' => 'Acme, Inc.', 'active' => true))->save(); }