public function testReadWriteMultiple() { $companies = array(); $key = Companies::meta('key'); foreach ($this->companiesData as $data) { $companies[] = Companies::create($data); $this->assertTrue(end($companies)->save()); $this->assertTrue(end($companies)->{$key}); } $this->assertIdentical(2, Companies::count()); $this->assertIdentical(1, Companies::count(array('active' => true))); $this->assertIdentical(1, Companies::count(array('active' => false))); $this->assertIdentical(0, Companies::count(array('active' => null))); $all = Companies::all(); $this->assertIdentical(2, Companies::count()); $expected = count($this->companiesData); $this->assertEqual($expected, $all->count()); $this->assertEqual($expected, count($all)); $id = (string) $all->first()->{$key}; $this->assertTrue(strlen($id) > 0); $this->assertTrue($all->data()); foreach ($companies as $companies) { $this->assertTrue($companies->delete()); } $this->assertIdentical(0, Companies::count()); }
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()); }