Commit 593b4a52 authored by Jens Segers's avatar Jens Segers

Use short array notations in tests

parent 96039491
......@@ -12,13 +12,13 @@ class AuthTest extends TestCase {
public function testAuthAttempt()
{
$user = User::create(array(
$user = User::create([
'name' => 'John Doe',
'email' => 'john@doe.com',
'password' => Hash::make('foobar')
));
]);
$this->assertTrue(Auth::attempt(array('email' => 'john@doe.com', 'password' => 'foobar'), true));
$this->assertTrue(Auth::attempt(['email' => 'john@doe.com', 'password' => 'foobar'], true));
$this->assertTrue(Auth::check());
}
......@@ -30,14 +30,14 @@ class AuthTest extends TestCase {
$broker = new PasswordBroker($tokens, $users, $mailer, '');
$user = User::create(array(
$user = User::create([
'name' => 'John Doe',
'email' => 'john@doe.com',
'password' => Hash::make('foobar')
));
]);
$mailer->shouldReceive('send')->once();
$broker->sendResetLink(array('email' => 'john@doe.com'));
$broker->sendResetLink(['email' => 'john@doe.com']);
$this->assertEquals(1, DB::collection('password_resets')->count());
$reminder = DB::collection('password_resets')->first();
......@@ -45,12 +45,12 @@ class AuthTest extends TestCase {
$this->assertNotNull($reminder['token']);
$this->assertInstanceOf('MongoDate', $reminder['created_at']);
$credentials = array(
$credentials = [
'email' => 'john@doe.com',
'password' => 'foobar',
'password_confirmation' => 'foobar',
'token' => $reminder['token']
);
];
$response = $broker->reset($credentials, function($user, $password)
{
......
......@@ -71,13 +71,13 @@ class ConnectionTest extends TestCase {
DB::collection('items')->get();
$this->assertEquals(1, count(DB::getQueryLog()));
DB::collection('items')->insert(array('name' => 'test'));
DB::collection('items')->insert(['name' => 'test']);
$this->assertEquals(2, count(DB::getQueryLog()));
DB::collection('items')->count();
$this->assertEquals(3, count(DB::getQueryLog()));
DB::collection('items')->where('name', 'test')->update(array('name' => 'test'));
DB::collection('items')->where('name', 'test')->update(['name' => 'test']);
$this->assertEquals(4, count(DB::getQueryLog()));
DB::collection('items')->where('name', 'test')->delete();
......
......@@ -17,8 +17,8 @@ class EmbeddedRelationsTest extends TestCase {
public function testEmbedsManySave()
{
$user = User::create(array('name' => 'John Doe'));
$address = new Address(array('city' => 'London'));
$user = User::create(['name' => 'John Doe']);
$address = new Address(['city' => 'London']);
$address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
$events->shouldReceive('until')->once()->with('eloquent.saving: '.get_class($address), $address)->andReturn(true);
......@@ -31,7 +31,7 @@ class EmbeddedRelationsTest extends TestCase {
$this->assertNotNull($user->addresses);
$this->assertInstanceOf('Illuminate\Database\Eloquent\Collection', $user->addresses);
$this->assertEquals(array('London'), $user->addresses->lists('city'));
$this->assertEquals(['London'], $user->addresses->lists('city'));
$this->assertInstanceOf('DateTime', $address->created_at);
$this->assertInstanceOf('DateTime', $address->updated_at);
$this->assertNotNull($address->_id);
......@@ -40,10 +40,10 @@ class EmbeddedRelationsTest extends TestCase {
$raw = $address->getAttributes();
$this->assertInstanceOf('MongoId', $raw['_id']);
$address = $user->addresses()->save(new Address(array('city' => 'Paris')));
$address = $user->addresses()->save(new Address(['city' => 'Paris']));
$user = User::find($user->_id);
$this->assertEquals(array('London', 'Paris'), $user->addresses->lists('city'));
$this->assertEquals(['London', 'Paris'], $user->addresses->lists('city'));
$address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
$events->shouldReceive('until')->once()->with('eloquent.saving: '.get_class($address), $address)->andReturn(true);
......@@ -59,10 +59,10 @@ class EmbeddedRelationsTest extends TestCase {
$this->assertEquals(2, count($user->addresses()->get()));
$this->assertEquals(2, $user->addresses->count());
$this->assertEquals(2, $user->addresses()->count());
$this->assertEquals(array('London', 'New York'), $user->addresses->lists('city'));
$this->assertEquals(['London', 'New York'], $user->addresses->lists('city'));
$freshUser = User::find($user->_id);
$this->assertEquals(array('London', 'New York'), $freshUser->addresses->lists('city'));
$this->assertEquals(['London', 'New York'], $freshUser->addresses->lists('city'));
$address = $user->addresses->first();
$this->assertEquals('London', $address->city);
......@@ -72,22 +72,22 @@ class EmbeddedRelationsTest extends TestCase {
$this->assertEmpty($address->relationsToArray()); // prevent infinite loop
$user = User::find($user->_id);
$user->addresses()->save(new Address(array('city' => 'Bruxelles')));
$this->assertEquals(array('London', 'New York', 'Bruxelles'), $user->addresses->lists('city'));
$user->addresses()->save(new Address(['city' => 'Bruxelles']));
$this->assertEquals(['London', 'New York', 'Bruxelles'], $user->addresses->lists('city'));
$address = $user->addresses[1];
$address->city = "Manhattan";
$user->addresses()->save($address);
$this->assertEquals(array('London', 'Manhattan', 'Bruxelles'), $user->addresses->lists('city'));
$this->assertEquals(['London', 'Manhattan', 'Bruxelles'], $user->addresses->lists('city'));
$freshUser = User::find($user->_id);
$this->assertEquals(array('London', 'Manhattan', 'Bruxelles'), $freshUser->addresses->lists('city'));
$this->assertEquals(['London', 'Manhattan', 'Bruxelles'], $freshUser->addresses->lists('city'));
}
public function testEmbedsManySaveModel()
{
$user = User::create(array('name' => 'John Doe'));
$address = new Address(array('city' => 'London'));
$user = User::create(['name' => 'John Doe']);
$address = new Address(['city' => 'London']);
$address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
$events->shouldReceive('until')->once()->with('eloquent.saving: '.get_class($address), $address)->andReturn(true);
......@@ -109,8 +109,8 @@ class EmbeddedRelationsTest extends TestCase {
public function testEmbedsToArray()
{
$user = User::create(array('name' => 'John Doe'));
$user->addresses()->saveMany(array(new Address(array('city' => 'London')), new Address(array('city' => 'Bristol'))));
$user = User::create(['name' => 'John Doe']);
$user->addresses()->saveMany([new Address(['city' => 'London']), new Address(['city' => 'Bristol'])]);
$array = $user->toArray();
$this->assertFalse(array_key_exists('_addresses', $array));
......@@ -119,42 +119,42 @@ class EmbeddedRelationsTest extends TestCase {
public function testEmbedsManyAssociate()
{
$user = User::create(array('name' => 'John Doe'));
$address = new Address(array('city' => 'London'));
$user = User::create(['name' => 'John Doe']);
$address = new Address(['city' => 'London']);
$user->addresses()->associate($address);
$this->assertEquals(array('London'), $user->addresses->lists('city'));
$this->assertEquals(['London'], $user->addresses->lists('city'));
$this->assertNotNull($address->_id);
$freshUser = User::find($user->_id);
$this->assertEquals(array(), $freshUser->addresses->lists('city'));
$this->assertEquals([], $freshUser->addresses->lists('city'));
$address->city = 'Londinium';
$user->addresses()->associate($address);
$this->assertEquals(array('Londinium'), $user->addresses->lists('city'));
$this->assertEquals(['Londinium'], $user->addresses->lists('city'));
$freshUser = User::find($user->_id);
$this->assertEquals(array(), $freshUser->addresses->lists('city'));
$this->assertEquals([], $freshUser->addresses->lists('city'));
}
public function testEmbedsManySaveMany()
{
$user = User::create(array('name' => 'John Doe'));
$user->addresses()->saveMany(array(new Address(array('city' => 'London')), new Address(array('city' => 'Bristol'))));
$this->assertEquals(array('London', 'Bristol'), $user->addresses->lists('city'));
$user = User::create(['name' => 'John Doe']);
$user->addresses()->saveMany([new Address(['city' => 'London']), new Address(['city' => 'Bristol'])]);
$this->assertEquals(['London', 'Bristol'], $user->addresses->lists('city'));
$freshUser = User::find($user->id);
$this->assertEquals(array('London', 'Bristol'), $freshUser->addresses->lists('city'));
$this->assertEquals(['London', 'Bristol'], $freshUser->addresses->lists('city'));
}
public function testEmbedsManyDuplicate()
{
$user = User::create(array('name' => 'John Doe'));
$address = new Address(array('city' => 'London'));
$user = User::create(['name' => 'John Doe']);
$address = new Address(['city' => 'London']);
$user->addresses()->save($address);
$user->addresses()->save($address);
$this->assertEquals(1, $user->addresses->count());
$this->assertEquals(array('London'), $user->addresses->lists('city'));
$this->assertEquals(['London'], $user->addresses->lists('city'));
$user = User::find($user->id);
$this->assertEquals(1, $user->addresses->count());
......@@ -162,29 +162,29 @@ class EmbeddedRelationsTest extends TestCase {
$address->city = 'Paris';
$user->addresses()->save($address);
$this->assertEquals(1, $user->addresses->count());
$this->assertEquals(array('Paris'), $user->addresses->lists('city'));
$this->assertEquals(['Paris'], $user->addresses->lists('city'));
$user->addresses()->create(array('_id' => $address->_id, 'city' => 'Bruxelles'));
$user->addresses()->create(['_id' => $address->_id, 'city' => 'Bruxelles']);
$this->assertEquals(1, $user->addresses->count());
$this->assertEquals(array('Bruxelles'), $user->addresses->lists('city'));
$this->assertEquals(['Bruxelles'], $user->addresses->lists('city'));
}
public function testEmbedsManyCreate()
{
$user = User::create(array());
$address = $user->addresses()->create(array('city' => 'Bruxelles'));
$user = User::create([]);
$address = $user->addresses()->create(['city' => 'Bruxelles']);
$this->assertInstanceOf('Address', $address);
$this->assertTrue(is_string($address->_id));
$this->assertEquals(array('Bruxelles'), $user->addresses->lists('city'));
$this->assertEquals(['Bruxelles'], $user->addresses->lists('city'));
$raw = $address->getAttributes();
$this->assertInstanceOf('MongoId', $raw['_id']);
$freshUser = User::find($user->id);
$this->assertEquals(array('Bruxelles'), $freshUser->addresses->lists('city'));
$this->assertEquals(['Bruxelles'], $freshUser->addresses->lists('city'));
$user = User::create(array());
$address = $user->addresses()->create(array('_id' => '', 'city' => 'Bruxelles'));
$user = User::create([]);
$address = $user->addresses()->create(['_id' => '', 'city' => 'Bruxelles']);
$this->assertTrue(is_string($address->_id));
$raw = $address->getAttributes();
......@@ -193,20 +193,20 @@ class EmbeddedRelationsTest extends TestCase {
public function testEmbedsManyCreateMany()
{
$user = User::create(array());
list($bruxelles, $paris) = $user->addresses()->createMany(array(array('city' => 'Bruxelles'), array('city' => 'Paris')));
$user = User::create([]);
list($bruxelles, $paris) = $user->addresses()->createMany([['city' => 'Bruxelles'], ['city' => 'Paris']]);
$this->assertInstanceOf('Address', $bruxelles);
$this->assertEquals('Bruxelles', $bruxelles->city);
$this->assertEquals(array('Bruxelles', 'Paris'), $user->addresses->lists('city'));
$this->assertEquals(['Bruxelles', 'Paris'], $user->addresses->lists('city'));
$freshUser = User::find($user->id);
$this->assertEquals(array('Bruxelles', 'Paris'), $freshUser->addresses->lists('city'));
$this->assertEquals(['Bruxelles', 'Paris'], $freshUser->addresses->lists('city'));
}
public function testEmbedsManyDestroy()
{
$user = User::create(array('name' => 'John Doe'));
$user->addresses()->saveMany(array(new Address(array('city' => 'London')), new Address(array('city' => 'Bristol')), new Address(array('city' => 'Bruxelles'))));
$user = User::create(['name' => 'John Doe']);
$user->addresses()->saveMany([new Address(['city' => 'London']), new Address(['city' => 'Bristol']), new Address(['city' => 'Bruxelles'])]);
$address = $user->addresses->first();
......@@ -215,36 +215,36 @@ class EmbeddedRelationsTest extends TestCase {
$events->shouldReceive('fire')->once()->with('eloquent.deleted: '.get_class($address), Mockery::type('Address'));
$user->addresses()->destroy($address->_id);
$this->assertEquals(array('Bristol', 'Bruxelles'), $user->addresses->lists('city'));
$this->assertEquals(['Bristol', 'Bruxelles'], $user->addresses->lists('city'));
$address->unsetEventDispatcher();
$address = $user->addresses->first();
$user->addresses()->destroy($address);
$this->assertEquals(array('Bruxelles'), $user->addresses->lists('city'));
$this->assertEquals(['Bruxelles'], $user->addresses->lists('city'));
$user->addresses()->create(array('city' => 'Paris'));
$user->addresses()->create(array('city' => 'San Francisco'));
$user->addresses()->create(['city' => 'Paris']);
$user->addresses()->create(['city' => 'San Francisco']);
$freshUser = User::find($user->id);
$this->assertEquals(array('Bruxelles', 'Paris', 'San Francisco'), $freshUser->addresses->lists('city'));
$this->assertEquals(['Bruxelles', 'Paris', 'San Francisco'], $freshUser->addresses->lists('city'));
$ids = $user->addresses->lists('_id');
$user->addresses()->destroy($ids);
$this->assertEquals(array(), $user->addresses->lists('city'));
$this->assertEquals([], $user->addresses->lists('city'));
$freshUser = User::find($user->id);
$this->assertEquals(array(), $freshUser->addresses->lists('city'));
$this->assertEquals([], $freshUser->addresses->lists('city'));
list($london, $bristol, $bruxelles) = $user->addresses()->saveMany(array(new Address(array('city' => 'London')), new Address(array('city' => 'Bristol')), new Address(array('city' => 'Bruxelles'))));
$user->addresses()->destroy(array($london, $bruxelles));
$this->assertEquals(array('Bristol'), $user->addresses->lists('city'));
list($london, $bristol, $bruxelles) = $user->addresses()->saveMany([new Address(['city' => 'London']), new Address(['city' => 'Bristol']), new Address(['city' => 'Bruxelles'])]);
$user->addresses()->destroy([$london, $bruxelles]);
$this->assertEquals(['Bristol'], $user->addresses->lists('city'));
}
public function testEmbedsManyDelete()
{
$user = User::create(array('name' => 'John Doe'));
$user->addresses()->saveMany(array(new Address(array('city' => 'London')), new Address(array('city' => 'Bristol')), new Address(array('city' => 'Bruxelles'))));
$user = User::create(['name' => 'John Doe']);
$user->addresses()->saveMany([new Address(['city' => 'London']), new Address(['city' => 'Bristol']), new Address(['city' => 'Bruxelles'])]);
$address = $user->addresses->first();
......@@ -269,8 +269,8 @@ class EmbeddedRelationsTest extends TestCase {
public function testEmbedsManyDissociate()
{
$user = User::create(array());
$cordoba = $user->addresses()->create(array('city' => 'Cordoba'));
$user = User::create([]);
$cordoba = $user->addresses()->create(['city' => 'Cordoba']);
$user->addresses()->dissociate($cordoba->id);
......@@ -281,20 +281,20 @@ class EmbeddedRelationsTest extends TestCase {
public function testEmbedsManyAliases()
{
$user = User::create(array('name' => 'John Doe'));
$address = new Address(array('city' => 'London'));
$user = User::create(['name' => 'John Doe']);
$address = new Address(['city' => 'London']);
$address = $user->addresses()->attach($address);
$this->assertEquals(array('London'), $user->addresses->lists('city'));
$this->assertEquals(['London'], $user->addresses->lists('city'));
$user->addresses()->detach($address);
$this->assertEquals(array(), $user->addresses->lists('city'));
$this->assertEquals([], $user->addresses->lists('city'));
}
public function testEmbedsManyCreatingEventReturnsFalse()
{
$user = User::create(array('name' => 'John Doe'));
$address = new Address(array('city' => 'London'));
$user = User::create(['name' => 'John Doe']);
$address = new Address(['city' => 'London']);
$address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
$events->shouldReceive('until')->once()->with('eloquent.saving: '.get_class($address), $address)->andReturn(true);
......@@ -306,8 +306,8 @@ class EmbeddedRelationsTest extends TestCase {
public function testEmbedsManySavingEventReturnsFalse()
{
$user = User::create(array('name' => 'John Doe'));
$address = new Address(array('city' => 'Paris'));
$user = User::create(['name' => 'John Doe']);
$address = new Address(['city' => 'Paris']);
$address->exists = true;
$address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
......@@ -319,8 +319,8 @@ class EmbeddedRelationsTest extends TestCase {
public function testEmbedsManyUpdatingEventReturnsFalse()
{
$user = User::create(array('name' => 'John Doe'));
$address = new Address(array('city' => 'New York'));
$user = User::create(['name' => 'John Doe']);
$address = new Address(['city' => 'New York']);
$user->addresses()->save($address);
$address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
......@@ -335,8 +335,8 @@ class EmbeddedRelationsTest extends TestCase {
public function testEmbedsManyDeletingEventReturnsFalse()
{
$user = User::create(array('name' => 'John Doe'));
$user->addresses()->save(new Address(array('city' => 'New York')));
$user = User::create(['name' => 'John Doe']);
$user->addresses()->save(new Address(['city' => 'New York']));
$address = $user->addresses->first();
......@@ -344,16 +344,16 @@ class EmbeddedRelationsTest extends TestCase {
$events->shouldReceive('until')->once()->with('eloquent.deleting: '.get_class($address), Mockery::mustBe($address))->andReturn(false);
$this->assertEquals(0, $user->addresses()->destroy($address));
$this->assertEquals(array('New York'), $user->addresses->lists('city'));
$this->assertEquals(['New York'], $user->addresses->lists('city'));
$address->unsetEventDispatcher();
}
public function testEmbedsManyFindOrContains()
{
$user = User::create(array('name' => 'John Doe'));
$address1 = $user->addresses()->save(new Address(array('city' => 'New York')));
$address2 = $user->addresses()->save(new Address(array('city' => 'Paris')));
$user = User::create(['name' => 'John Doe']);
$address1 = $user->addresses()->save(new Address(['city' => 'New York']));
$address2 = $user->addresses()->save(new Address(['city' => 'Paris']));
$address = $user->addresses()->find($address1->_id);
$this->assertEquals($address->city, $address1->city);
......@@ -367,13 +367,13 @@ class EmbeddedRelationsTest extends TestCase {
public function testEmbedsManyEagerLoading()
{
$user1 = User::create(array('name' => 'John Doe'));
$user1->addresses()->save(new Address(array('city' => 'New York')));
$user1->addresses()->save(new Address(array('city' => 'Paris')));
$user1 = User::create(['name' => 'John Doe']);
$user1->addresses()->save(new Address(['city' => 'New York']));
$user1->addresses()->save(new Address(['city' => 'Paris']));
$user2 = User::create(array('name' => 'Jane Doe'));
$user2->addresses()->save(new Address(array('city' => 'Berlin')));
$user2->addresses()->save(new Address(array('city' => 'Paris')));
$user2 = User::create(['name' => 'Jane Doe']);
$user2->addresses()->save(new Address(['city' => 'Berlin']));
$user2->addresses()->save(new Address(['city' => 'Paris']));
$user = User::find($user1->id);
$relations = $user->getRelations();
......@@ -391,13 +391,13 @@ class EmbeddedRelationsTest extends TestCase {
public function testEmbedsManyDeleteAll()
{
$user1 = User::create(array('name' => 'John Doe'));
$user1->addresses()->save(new Address(array('city' => 'New York')));
$user1->addresses()->save(new Address(array('city' => 'Paris')));
$user1 = User::create(['name' => 'John Doe']);
$user1->addresses()->save(new Address(['city' => 'New York']));
$user1->addresses()->save(new Address(['city' => 'Paris']));
$user2 = User::create(array('name' => 'Jane Doe'));
$user2->addresses()->save(new Address(array('city' => 'Berlin')));
$user2->addresses()->save(new Address(array('city' => 'Paris')));
$user2 = User::create(['name' => 'Jane Doe']);
$user2->addresses()->save(new Address(['city' => 'Berlin']));
$user2->addresses()->save(new Address(['city' => 'Paris']));
$user1->addresses()->delete();
$this->assertEquals(0, $user1->addresses()->count());
......@@ -415,20 +415,20 @@ class EmbeddedRelationsTest extends TestCase {
public function testEmbedsManyCollectionMethods()
{
$user = User::create(array('name' => 'John Doe'));
$user->addresses()->save(new Address(array('city' => 'Paris', 'country' => 'France', 'visited' => 4, 'created_at' => new DateTime('3 days ago'))));
$user->addresses()->save(new Address(array('city' => 'Bruges', 'country' => 'Belgium', 'visited' => 7, 'created_at' => new DateTime('5 days ago'))));
$user->addresses()->save(new Address(array('city' => 'Brussels', 'country' => 'Belgium', 'visited' => 2, 'created_at' => new DateTime('4 days ago'))));
$user->addresses()->save(new Address(array('city' => 'Ghent', 'country' => 'Belgium', 'visited' => 13, 'created_at' => new DateTime('2 days ago'))));
$user = User::create(['name' => 'John Doe']);
$user->addresses()->save(new Address(['city' => 'Paris', 'country' => 'France', 'visited' => 4, 'created_at' => new DateTime('3 days ago')]));
$user->addresses()->save(new Address(['city' => 'Bruges', 'country' => 'Belgium', 'visited' => 7, 'created_at' => new DateTime('5 days ago')]));
$user->addresses()->save(new Address(['city' => 'Brussels', 'country' => 'Belgium', 'visited' => 2, 'created_at' => new DateTime('4 days ago')]));
$user->addresses()->save(new Address(['city' => 'Ghent', 'country' => 'Belgium', 'visited' => 13, 'created_at' => new DateTime('2 days ago')]));
$this->assertEquals(array('Paris', 'Bruges', 'Brussels', 'Ghent'), $user->addresses()->lists('city'));
$this->assertEquals(array('Bruges', 'Brussels', 'Ghent', 'Paris'), $user->addresses()->sortBy('city')->lists('city'));
$this->assertEquals(array('Bruges', 'Brussels', 'Ghent', 'Paris'), $user->addresses()->orderBy('city')->lists('city'));
$this->assertEquals(array('Paris', 'Ghent', 'Brussels', 'Bruges'), $user->addresses()->orderBy('city', 'desc')->lists('city'));
$this->assertEquals(['Paris', 'Bruges', 'Brussels', 'Ghent'], $user->addresses()->lists('city'));
$this->assertEquals(['Bruges', 'Brussels', 'Ghent', 'Paris'], $user->addresses()->sortBy('city')->lists('city'));
$this->assertEquals(['Bruges', 'Brussels', 'Ghent', 'Paris'], $user->addresses()->orderBy('city')->lists('city'));
$this->assertEquals(['Paris', 'Ghent', 'Brussels', 'Bruges'], $user->addresses()->orderBy('city', 'desc')->lists('city'));
$this->assertEquals(array(), $user->addresses()->where('city', 'New York')->lists('city'));
$this->assertEquals(array('Bruges', 'Brussels', 'Ghent'), $user->addresses()->where('country', 'Belgium')->lists('city'));
$this->assertEquals(array('Ghent', 'Brussels', 'Bruges'), $user->addresses()->where('country', 'Belgium')->orderBy('city', 'desc')->lists('city'));
$this->assertEquals([], $user->addresses()->where('city', 'New York')->lists('city'));
$this->assertEquals(['Bruges', 'Brussels', 'Ghent'], $user->addresses()->where('country', 'Belgium')->lists('city'));
$this->assertEquals(['Ghent', 'Brussels', 'Bruges'], $user->addresses()->where('country', 'Belgium')->orderBy('city', 'desc')->lists('city'));
$results = $user->addresses->get(0);
$this->assertInstanceOf('Address', $results);
......@@ -452,19 +452,19 @@ class EmbeddedRelationsTest extends TestCase {
$results = $user->addresses()->where('visited', '>=', 7)->get();
$this->assertEquals(2, $results->count());
$results = $user->addresses()->where('visited', 'between', array(4, 7))->get();
$results = $user->addresses()->where('visited', 'between', [4, 7])->get();
$this->assertEquals(2, $results->count());
$results = $user->addresses()->whereBetween('visited', array(4, 7))->get();
$results = $user->addresses()->whereBetween('visited', [4, 7])->get();
$this->assertEquals(2, $results->count());
$results = $user->addresses()->whereNotBetween('visited', array(4, 7))->get();
$results = $user->addresses()->whereNotBetween('visited', [4, 7])->get();
$this->assertEquals(2, $results->count());
$results = $user->addresses()->whereIn('visited', array(7, 13))->get();
$results = $user->addresses()->whereIn('visited', [7, 13])->get();
$this->assertEquals(2, $results->count());
$results = $user->addresses()->whereNotIn('visited', array(7))->get();
$results = $user->addresses()->whereNotIn('visited', [7])->get();
$this->assertEquals(3, $results->count());
$results = $user->addresses()->whereNull('something')->get();
......@@ -491,8 +491,8 @@ class EmbeddedRelationsTest extends TestCase {
public function testEmbedsOne()
{
$user = User::create(array('name' => 'John Doe'));
$father = new User(array('name' => 'Mark Doe'));
$user = User::create(['name' => 'John Doe']);
$father = new User(['name' => 'Mark Doe']);
$father->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
$events->shouldReceive('until')->once()->with('eloquent.saving: '.get_class($father), $father)->andReturn(true);
......@@ -526,7 +526,7 @@ class EmbeddedRelationsTest extends TestCase {
$this->assertNotNull($user->father);
$this->assertEquals('Tom Doe', $user->father->name);
$father = new User(array('name' => 'Jim Doe'));
$father = new User(['name' => 'Jim Doe']);
$father->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
$events->shouldReceive('until')->once()->with('eloquent.saving: '.get_class($father), $father)->andReturn(true);
......@@ -543,8 +543,8 @@ class EmbeddedRelationsTest extends TestCase {
public function testEmbedsOneAssociate()
{
$user = User::create(array('name' => 'John Doe'));
$father = new User(array('name' => 'Mark Doe'));
$user = User::create(['name' => 'John Doe']);
$father = new User(['name' => 'Mark Doe']);
$father->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
$events->shouldReceive('until')->times(0)->with('eloquent.saving: '.get_class($father), $father);
......@@ -558,8 +558,8 @@ class EmbeddedRelationsTest extends TestCase {
public function testEmbedsOneDelete()
{
$user = User::create(array('name' => 'John Doe'));
$father = $user->father()->save(new User(array('name' => 'Mark Doe')));
$user = User::create(['name' => 'John Doe']);
$father = $user->father()->save(new User(['name' => 'Mark Doe']));
$user->father()->delete();
$this->assertNull($user->father);
......@@ -567,10 +567,10 @@ class EmbeddedRelationsTest extends TestCase {
public function testEmbedsManyToArray()
{
$user = User::create(array('name' => 'John Doe'));
$user->addresses()->save(new Address(array('city' => 'New York')));
$user->addresses()->save(new Address(array('city' => 'Paris')));
$user->addresses()->save(new Address(array('city' => 'Brussels')));
$user = User::create(['name' => 'John Doe']);
$user->addresses()->save(new Address(['city' => 'New York']));
$user->addresses()->save(new Address(['city' => 'Paris']));
$user->addresses()->save(new Address(['city' => 'Brussels']));
$array = $user->toArray();
$this->assertArrayHasKey('addresses', $array);
......@@ -579,9 +579,9 @@ class EmbeddedRelationsTest extends TestCase {
public function testEmbeddedSave()
{
$user = User::create(array('name' => 'John Doe'));
$address = $user->addresses()->create(array('city' => 'New York'));
$father = $user->father()->create(array('name' => 'Mark Doe'));
$user = User::create(['name' => 'John Doe']);
$address = $user->addresses()->create(['city' => 'New York']);
$father = $user->father()->create(['name' => 'Mark Doe']);
$address->city = 'Paris';
$address->save();
......@@ -615,10 +615,10 @@ class EmbeddedRelationsTest extends TestCase {
public function testNestedEmbedsOne()
{
$user = User::create(array('name' => 'John Doe'));
$father = $user->father()->create(array('name' => 'Mark Doe'));
$grandfather = $father->father()->create(array('name' => 'Steve Doe'));
$greatgrandfather = $grandfather->father()->create(array('name' => 'Tom Doe'));
$user = User::create(['name' => 'John Doe']);
$father = $user->father()->create(['name' => 'Mark Doe']);
$grandfather = $father->father()->create(['name' => 'Steve Doe']);
$greatgrandfather = $grandfather->father()->create(['name' => 'Tom Doe']);
$user->name = 'Tim Doe';
$user->save();
......@@ -643,12 +643,12 @@ class EmbeddedRelationsTest extends TestCase {
public function testNestedEmbedsMany()
{
$user = User::create(array('name' => 'John Doe'));
$country1 = $user->addresses()->create(array('country' => 'France'));
$country2 = $user->addresses()->create(array('country' => 'Belgium'));
$city1 = $country1->addresses()->create(array('city' => 'Paris'));
$city2 = $country2->addresses()->create(array('city' => 'Ghent'));
$city3 = $country2->addresses()->create(array('city' => 'Brussels'));
$user = User::create(['name' => 'John Doe']);
$country1 = $user->addresses()->create(['country' => 'France']);
$country2 = $user->addresses()->create(['country' => 'Belgium']);
$city1 = $country1->addresses()->create(['city' => 'Paris']);
$city2 = $country2->addresses()->create(['city' => 'Ghent']);
$city3 = $country2->addresses()->create(['city' => 'Brussels']);
$city3->city = 'Bruges';
$city3->save();
......@@ -665,10 +665,10 @@ class EmbeddedRelationsTest extends TestCase {
public function testNestedMixedEmbeds()
{
$user = User::create(array('name' => 'John Doe'));
$father = $user->father()->create(array('name' => 'Mark Doe'));
$country1 = $father->addresses()->create(array('country' => 'France'));
$country2 = $father->addresses()->create(array('country' => 'Belgium'));
$user = User::create(['name' => 'John Doe']);
$father = $user->father()->create(['name' => 'Mark Doe']);
$country1 = $father->addresses()->create(['country' => 'France']);
$country2 = $father->addresses()->create(['country' => 'Belgium']);
$country2->country = 'England';
$country2->save();
......@@ -688,8 +688,8 @@ class EmbeddedRelationsTest extends TestCase {
public function testDoubleAssociate()
{
$user = User::create(array('name' => 'John Doe'));
$address = new Address(array('city' => 'Paris'));
$user = User::create(['name' => 'John Doe']);
$address = new Address(['city' => 'Paris']);
$user->addresses()->associate($address);
$user->addresses()->associate($address);
......@@ -708,7 +708,7 @@ class EmbeddedRelationsTest extends TestCase {
public function testSaveEmptyModel()
{
$user = User::create(array('name' => 'John Doe'));
$user = User::create(['name' => 'John Doe']);
$user->addresses()->save(new Address);
$this->assertNotNull($user->addresses);
$this->assertEquals(1, $user->addresses()->count());
......@@ -716,8 +716,8 @@ class EmbeddedRelationsTest extends TestCase {
public function testIncrementEmbedded()
{
$user = User::create(array('name' => 'John Doe'));
$address = $user->addresses()->create(array('city' => 'New York', 'visited' => 5));
$user = User::create(['name' => 'John Doe']);
$address = $user->addresses()->create(['city' => 'New York', 'visited' => 5]);
$address->increment('visited');
$this->assertEquals(6, $address->visited);
......@@ -739,10 +739,10 @@ class EmbeddedRelationsTest extends TestCase {
public function testPaginateEmbedsMany()
{
$user = User::create(array('name' => 'John Doe'));
$user->addresses()->save(new Address(array('city' => 'New York')));
$user->addresses()->save(new Address(array('city' => 'Paris')));
$user->addresses()->save(new Address(array('city' => 'Brussels')));
$user = User::create(['name' => 'John Doe']);
$user->addresses()->save(new Address(['city' => 'New York']));
$user->addresses()->save(new Address(['city' => 'Paris']));
$user->addresses()->save(new Address(['city' => 'Brussels']));
$results = $user->addresses()->paginate(2);
$this->assertEquals(2, $results->count());
......
......@@ -69,7 +69,7 @@ class ModelTest extends TestCase {
$this->assertEquals('John Doe', $check->name);
$this->assertEquals(36, $check->age);
$user->update(array('age' => 20));
$user->update(['age' => 20]);
$raw = $user->getAttributes();
$this->assertInstanceOf('MongoId', $raw['_id']);
......@@ -180,10 +180,10 @@ class ModelTest extends TestCase {
public function testGet()
{
User::insert(array(
array('name' => 'John Doe'),
array('name' => 'Jane Doe')
));
User::insert([
['name' => 'John Doe'],
['name' => 'Jane Doe']
]);
$users = User::get();
$this->assertEquals(2, count($users));
......@@ -193,10 +193,10 @@ class ModelTest extends TestCase {
public function testFirst()
{
User::insert(array(
array('name' => 'John Doe'),
array('name' => 'Jane Doe')
));
User::insert([
['name' => 'John Doe'],
['name' => 'Jane Doe']
]);
$user = User::first();
$this->assertInstanceOf('Jenssegers\Mongodb\Model', $user);
......@@ -224,7 +224,7 @@ class ModelTest extends TestCase {
public function testCreate()
{
$user = User::create(array('name' => 'Jane Poe'));
$user = User::create(['name' => 'Jane Poe']);
$this->assertInstanceOf('Jenssegers\Mongodb\Model', $user);
$this->assertEquals(true, $user->exists);
......@@ -266,8 +266,8 @@ class ModelTest extends TestCase {
public function testSoftDelete()
{
Soft::create(array('name' => 'John Doe'));
Soft::create(array('name' => 'Jane Doe'));
Soft::create(['name' => 'John Doe']);
Soft::create(['name' => 'Jane Doe']);
$this->assertEquals(2, Soft::count());
......@@ -317,10 +317,10 @@ class ModelTest extends TestCase {
public function testScope()
{
Item::insert(array(
array('name' => 'knife', 'type' => 'sharp'),
array('name' => 'spoon', 'type' => 'round')
));
Item::insert([
['name' => 'knife', 'type' => 'sharp'],
['name' => 'spoon', 'type' => 'round']
]);
$sharp = Item::sharp()->get();
$this->assertEquals(1, $sharp->count());
......@@ -328,11 +328,11 @@ class ModelTest extends TestCase {
public function testToArray()
{
$item = Item::create(array('name' => 'fork', 'type' => 'sharp'));
$item = Item::create(['name' => 'fork', 'type' => 'sharp']);
$array = $item->toArray();
$keys = array_keys($array); sort($keys);
$this->assertEquals(array('_id', 'created_at', 'name', 'type', 'updated_at'), $keys);
$this->assertEquals(['_id', 'created_at', 'name', 'type', 'updated_at'], $keys);
$this->assertTrue(is_string($array['created_at']));
$this->assertTrue(is_string($array['updated_at']));
$this->assertTrue(is_string($array['_id']));
......@@ -340,8 +340,8 @@ class ModelTest extends TestCase {
public function testUnset()
{
$user1 = User::create(array('name' => 'John Doe', 'note1' => 'ABC', 'note2' => 'DEF'));
$user2 = User::create(array('name' => 'Jane Doe', 'note1' => 'ABC', 'note2' => 'DEF'));
$user1 = User::create(['name' => 'John Doe', 'note1' => 'ABC', 'note2' => 'DEF']);
$user2 = User::create(['name' => 'Jane Doe', 'note1' => 'ABC', 'note2' => 'DEF']);
$user1->unset('note1');
......@@ -359,7 +359,7 @@ class ModelTest extends TestCase {
$this->assertTrue(isset($user2->note1));
$this->assertTrue(isset($user2->note2));
$user2->unset(array('note1', 'note2'));
$user2->unset(['note1', 'note2']);
$this->assertFalse(isset($user2->note1));
$this->assertFalse(isset($user2->note2));
......@@ -368,7 +368,7 @@ class ModelTest extends TestCase {
public function testDates()
{
$birthday = new DateTime('1980/1/1');
$user = User::create(array('name' => 'John Doe', 'birthday' => $birthday));
$user = User::create(['name' => 'John Doe', 'birthday' => $birthday]);
$this->assertInstanceOf('Carbon\Carbon', $user->birthday);
$check = User::find($user->_id);
......@@ -384,20 +384,20 @@ class ModelTest extends TestCase {
$this->assertEquals((string) $user->created_at, $json['created_at']);
// test default date format for json output
$item = Item::create(array('name' => 'sword'));
$item = Item::create(['name' => 'sword']);
$json = $item->toArray();
$this->assertEquals($item->created_at->format('Y-m-d H:i:s'), $json['created_at']);
$user = User::create(array('name' => 'Jane Doe', 'birthday' => time()));
$user = User::create(['name' => 'Jane Doe', 'birthday' => time()]);
$this->assertInstanceOf('Carbon\Carbon', $user->birthday);
$user = User::create(array('name' => 'Jane Doe', 'birthday' => 'Monday 8th of August 2005 03:12:46 PM'));
$user = User::create(['name' => 'Jane Doe', 'birthday' => 'Monday 8th of August 2005 03:12:46 PM']);
$this->assertInstanceOf('Carbon\Carbon', $user->birthday);
$user = User::create(array('name' => 'Jane Doe', 'birthday' => '2005-08-08'));
$user = User::create(['name' => 'Jane Doe', 'birthday' => '2005-08-08']);
$this->assertInstanceOf('Carbon\Carbon', $user->birthday);
$user = User::create(array('name' => 'Jane Doe', 'entry' => array('date' => '2005-08-08')));
$user = User::create(['name' => 'Jane Doe', 'entry' => ['date' => '2005-08-08']]);
$this->assertInstanceOf('Carbon\Carbon', $user->getAttribute('entry.date'));
$user->setAttribute('entry.date', new DateTime);
......@@ -406,55 +406,55 @@ class ModelTest extends TestCase {
public function testIdAttribute()
{
$user = User::create(array('name' => 'John Doe'));
$user = User::create(['name' => 'John Doe']);
$this->assertEquals($user->id, $user->_id);
$user = User::create(array('id' => 'custom_id', 'name' => 'John Doe'));
$user = User::create(['id' => 'custom_id', 'name' => 'John Doe']);
$this->assertNotEquals($user->id, $user->_id);
}
public function testPushPull()
{
$user = User::create(array('name' => 'John Doe'));
$user = User::create(['name' => 'John Doe']);
$user->push('tags', 'tag1');
$user->push('tags', array('tag1', 'tag2'));
$user->push('tags', ['tag1', 'tag2']);
$user->push('tags', 'tag2', true);
$this->assertEquals(array('tag1', 'tag1', 'tag2'), $user->tags);
$this->assertEquals(['tag1', 'tag1', 'tag2'], $user->tags);
$user = User::where('_id', $user->_id)->first();
$this->assertEquals(array('tag1', 'tag1', 'tag2'), $user->tags);
$this->assertEquals(['tag1', 'tag1', 'tag2'], $user->tags);
$user->pull('tags', 'tag1');
$this->assertEquals(array('tag2'), $user->tags);
$this->assertEquals(['tag2'], $user->tags);
$user = User::where('_id', $user->_id)->first();
$this->assertEquals(array('tag2'), $user->tags);
$this->assertEquals(['tag2'], $user->tags);
$user->push('tags', 'tag3');
$user->pull('tags', array('tag2', 'tag3'));
$user->pull('tags', ['tag2', 'tag3']);
$this->assertEquals(array(), $user->tags);
$this->assertEquals([], $user->tags);
$user = User::where('_id', $user->_id)->first();
$this->assertEquals(array(), $user->tags);
$this->assertEquals([], $user->tags);
}
public function testRaw()
{
User::create(array('name' => 'John Doe', 'age' => 35));
User::create(array('name' => 'Jane Doe', 'age' => 35));
User::create(array('name' => 'Harry Hoe', 'age' => 15));
User::create(['name' => 'John Doe', 'age' => 35]);
User::create(['name' => 'Jane Doe', 'age' => 35]);
User::create(['name' => 'Harry Hoe', 'age' => 15]);
$users = User::raw(function($collection)
{
return $collection->find(array('age' => 35));
return $collection->find(['age' => 35]);
});
$this->assertInstanceOf('Illuminate\Database\Eloquent\Collection', $users);
$this->assertInstanceOf('Jenssegers\Mongodb\Model', $users[0]);
$user = User::raw(function($collection)
{
return $collection->findOne(array('age' => 35));
return $collection->findOne(['age' => 35]);
});
$this->assertInstanceOf('Jenssegers\Mongodb\Model', $user);
......@@ -466,20 +466,20 @@ class ModelTest extends TestCase {
$result = User::raw(function($collection)
{
return $collection->insert(array('name' => 'Yvonne Yoe', 'age' => 35));
return $collection->insert(['name' => 'Yvonne Yoe', 'age' => 35]);
});
$this->assertTrue(is_array($result));
}
public function testDotNotation()
{
$user = User::create(array(
$user = User::create([
'name' => 'John Doe',
'address' => [
'city' => 'Paris',
'country' => 'France',
]
));
]);
$this->assertEquals('Paris', $user->getAttribute('address.city'));
$this->assertEquals('Paris', $user['address.city']);
......
......@@ -30,7 +30,7 @@ class MysqlRelationsTest extends TestCase {
$this->assertTrue(is_int($user->id));
// SQL has many
$book = new Book(array('title' => 'Game of Thrones'));
$book = new Book(['title' => 'Game of Thrones']);
$user->books()->save($book);
$user = MysqlUser::find($user->id); // refetch
$this->assertEquals(1, count($user->books));
......@@ -40,7 +40,7 @@ class MysqlRelationsTest extends TestCase {
$this->assertEquals('John Doe', $book->mysqlAuthor->name);
// SQL has one
$role = new Role(array('type' => 'admin'));
$role = new Role(['type' => 'admin']);
$user->role()->save($role);
$user = MysqlUser::find($user->id); // refetch
$this->assertEquals('admin', $user->role->type);
......@@ -55,7 +55,7 @@ class MysqlRelationsTest extends TestCase {
$user->save();
// MongoDB has many
$book = new MysqlBook(array('title' => 'Game of Thrones'));
$book = new MysqlBook(['title' => 'Game of Thrones']);
$user->mysqlBooks()->save($book);
$user = User::find($user->_id); // refetch
$this->assertEquals(1, count($user->mysqlBooks));
......@@ -65,7 +65,7 @@ class MysqlRelationsTest extends TestCase {
$this->assertEquals('John Doe', $book->author->name);
// MongoDB has one
$role = new MysqlRole(array('type' => 'admin'));
$role = new MysqlRole(['type' => 'admin']);
$user->mysqlRole()->save($role);
$user = User::find($user->_id); // refetch
$this->assertEquals('admin', $user->mysqlRole->type);
......
......@@ -18,7 +18,7 @@ class QueryBuilderTest extends TestCase {
$users = DB::collection('users')->get();
$this->assertEquals(0, count($users));
DB::collection('users')->insert(array('name' => 'John Doe'));
DB::collection('users')->insert(['name' => 'John Doe']);
$users = DB::collection('users')->get();
$this->assertEquals(1, count($users));
......@@ -27,7 +27,7 @@ class QueryBuilderTest extends TestCase {
public function testNoDocument()
{
$items = DB::collection('items')->where('name', 'nothing')->get();
$this->assertEquals(array(), $items);
$this->assertEquals([], $items);
$item = DB::collection('items')->where('name', 'nothing')->first();
$this->assertEquals(null, $item);
......@@ -38,10 +38,10 @@ class QueryBuilderTest extends TestCase {
public function testInsert()
{
DB::collection('users')->insert(array(
'tags' => array('tag1', 'tag2'),
DB::collection('users')->insert([
'tags' => ['tag1', 'tag2'],
'name' => 'John Doe',
));
]);
$users = DB::collection('users')->get();
$this->assertEquals(1, count($users));
......@@ -53,22 +53,22 @@ class QueryBuilderTest extends TestCase {
public function testInsertGetId()
{
$id = DB::collection('users')->insertGetId(array('name' => 'John Doe'));
$id = DB::collection('users')->insertGetId(['name' => 'John Doe']);
$this->assertInstanceOf('MongoId', $id);
}
public function testBatchInsert()
{
DB::collection('users')->insert(array(
array(
'tags' => array('tag1', 'tag2'),
DB::collection('users')->insert([
[
'tags' => ['tag1', 'tag2'],
'name' => 'Jane Doe',
),
array(
'tags' => array('tag3'),
],
[
'tags' => ['tag3'],
'name' => 'John Doe',
),
));
],
]);
$users = DB::collection('users')->get();
$this->assertEquals(2, count($users));
......@@ -77,7 +77,7 @@ class QueryBuilderTest extends TestCase {
public function testFind()
{
$id = DB::collection('users')->insertGetId(array('name' => 'John Doe'));
$id = DB::collection('users')->insertGetId(['name' => 'John Doe']);
$user = DB::collection('users')->find($id);
$this->assertEquals('John Doe', $user['name']);
......@@ -91,22 +91,22 @@ class QueryBuilderTest extends TestCase {
public function testCount()
{
DB::collection('users')->insert(array(
array('name' => 'Jane Doe'),
array('name' => 'John Doe')
));
DB::collection('users')->insert([
['name' => 'Jane Doe'],
['name' => 'John Doe']
]);
$this->assertEquals(2, DB::collection('users')->count());
}
public function testUpdate()
{
DB::collection('users')->insert(array(
array('name' => 'Jane Doe', 'age' => 20),
array('name' => 'John Doe', 'age' => 21)
));
DB::collection('users')->insert([
['name' => 'Jane Doe', 'age' => 20],
['name' => 'John Doe', 'age' => 21]
]);
DB::collection('users')->where('name', 'John Doe')->update(array('age' => 100));
DB::collection('users')->where('name', 'John Doe')->update(['age' => 100]);
$users = DB::collection('users')->get();
$john = DB::collection('users')->where('name', 'John Doe')->first();
......@@ -117,10 +117,10 @@ class QueryBuilderTest extends TestCase {
public function testDelete()
{
DB::collection('users')->insert(array(
array('name' => 'Jane Doe', 'age' => 20),
array('name' => 'John Doe', 'age' => 25)
));
DB::collection('users')->insert([
['name' => 'Jane Doe', 'age' => 20],
['name' => 'John Doe', 'age' => 25]
]);
DB::collection('users')->where('age', '<', 10)->delete();
$this->assertEquals(2, DB::collection('users')->count());
......@@ -131,23 +131,23 @@ class QueryBuilderTest extends TestCase {
public function testTruncate()
{
DB::collection('users')->insert(array('name' => 'John Doe'));
DB::collection('users')->insert(['name' => 'John Doe']);
DB::collection('users')->truncate();
$this->assertEquals(0, DB::collection('users')->count());
}
public function testSubKey()
{
DB::collection('users')->insert(array(
array(
DB::collection('users')->insert([
[
'name' => 'John Doe',
'address' => array('country' => 'Belgium', 'city' => 'Ghent')
),
array(
'address' => ['country' => 'Belgium', 'city' => 'Ghent']
],
[
'name' => 'Jane Doe',
'address' => array('country' => 'France', 'city' => 'Paris')
)
));
'address' => ['country' => 'France', 'city' => 'Paris']
]
]);
$users = DB::collection('users')->where('address.country', 'Belgium')->get();
$this->assertEquals(1, count($users));
......@@ -156,14 +156,14 @@ class QueryBuilderTest extends TestCase {
public function testInArray()
{
DB::collection('items')->insert(array(
array(
'tags' => array('tag1', 'tag2', 'tag3', 'tag4')
),
array(
'tags' => array('tag2')
)
));
DB::collection('items')->insert([
[
'tags' => ['tag1', 'tag2', 'tag3', 'tag4']
],
[
'tags' => ['tag2']
]
]);
$items = DB::collection('items')->where('tags', 'tag2')->get();
$this->assertEquals(2, count($items));
......@@ -174,14 +174,14 @@ class QueryBuilderTest extends TestCase {
public function testRaw()
{
DB::collection('users')->insert(array(
array('name' => 'Jane Doe', 'age' => 20),
array('name' => 'John Doe', 'age' => 25)
));
DB::collection('users')->insert([
['name' => 'Jane Doe', 'age' => 20],
['name' => 'John Doe', 'age' => 25]
]);
$cursor = DB::collection('users')->raw(function($collection)
{
return $collection->find(array('age' => 20));
return $collection->find(['age' => 20]);
});
$this->assertInstanceOf('MongoCursor', $cursor);
......@@ -193,18 +193,18 @@ class QueryBuilderTest extends TestCase {
$collection = User::raw();
$this->assertInstanceOf('Jenssegers\Mongodb\Collection', $collection);
$results = DB::collection('users')->whereRaw(array('age' => 20))->get();
$results = DB::collection('users')->whereRaw(['age' => 20])->get();
$this->assertEquals(1, count($results));
$this->assertEquals('Jane Doe', $results[0]['name']);
}
public function testPush()
{
$id = DB::collection('users')->insertGetId(array(
$id = DB::collection('users')->insertGetId([
'name' => 'John Doe',
'tags' => array(),
'messages' => array(),
));
'tags' => [],
'messages' => [],
]);
DB::collection('users')->where('_id', $id)->push('tags', 'tag1');
......@@ -228,7 +228,7 @@ class QueryBuilderTest extends TestCase {
$user = DB::collection('users')->find($id);
$this->assertEquals(3, count($user['tags']));
$message = array('from' => 'Jane', 'body' => 'Hi John');
$message = ['from' => 'Jane', 'body' => 'Hi John'];
DB::collection('users')->where('_id', $id)->push('messages', $message);
$user = DB::collection('users')->find($id);
$this->assertTrue(is_array($user['messages']));
......@@ -236,26 +236,26 @@ class QueryBuilderTest extends TestCase {
$this->assertEquals($message, $user['messages'][0]);
// Raw
DB::collection('users')->where('_id', $id)->push(array('tags' => 'tag3', 'messages' => array('from' => 'Mark', 'body' => 'Hi John')));
DB::collection('users')->where('_id', $id)->push(['tags' => 'tag3', 'messages' => ['from' => 'Mark', 'body' => 'Hi John']]);
$user = DB::collection('users')->find($id);
$this->assertEquals(4, count($user['tags']));
$this->assertEquals(2, count($user['messages']));
DB::collection('users')->where('_id', $id)->push(array('messages' => array('date' => new MongoDate(), 'body' => 'Hi John')));
DB::collection('users')->where('_id', $id)->push(['messages' => ['date' => new MongoDate(), 'body' => 'Hi John']]);
$user = DB::collection('users')->find($id);
$this->assertEquals(3, count($user['messages']));
}
public function testPull()
{
$message1 = array('from' => 'Jane', 'body' => 'Hi John');
$message2 = array('from' => 'Mark', 'body' => 'Hi John');
$message1 = ['from' => 'Jane', 'body' => 'Hi John'];
$message2 = ['from' => 'Mark', 'body' => 'Hi John'];
$id = DB::collection('users')->insertGetId(array(
$id = DB::collection('users')->insertGetId([
'name' => 'John Doe',
'tags' => array('tag1', 'tag2', 'tag3', 'tag4'),
'messages' => array($message1, $message2)
));
'tags' => ['tag1', 'tag2', 'tag3', 'tag4'],
'messages' => [$message1, $message2]
]);
DB::collection('users')->where('_id', $id)->pull('tags', 'tag3');
......@@ -271,7 +271,7 @@ class QueryBuilderTest extends TestCase {
$this->assertEquals(1, count($user['messages']));
// Raw
DB::collection('users')->where('_id', $id)->pull(array('tags' => 'tag2', 'messages' => $message2));
DB::collection('users')->where('_id', $id)->pull(['tags' => 'tag2', 'messages' => $message2]);
$user = DB::collection('users')->find($id);
$this->assertEquals(2, count($user['tags']));
$this->assertEquals(0, count($user['messages']));
......@@ -279,29 +279,29 @@ class QueryBuilderTest extends TestCase {
public function testDistinct()
{
DB::collection('items')->insert(array(
array('name' => 'knife', 'type' => 'sharp',),
array('name' => 'fork', 'type' => 'sharp'),
array('name' => 'spoon', 'type' => 'round'),
array('name' => 'spoon', 'type' => 'round')
));
DB::collection('items')->insert([
['name' => 'knife', 'type' => 'sharp',],
['name' => 'fork', 'type' => 'sharp'],
['name' => 'spoon', 'type' => 'round'],
['name' => 'spoon', 'type' => 'round']
]);
$items = DB::collection('items')->distinct('name')->get(); sort($items);
$this->assertEquals(3, count($items));
$this->assertEquals(array('fork', 'knife', 'spoon'), $items);
$this->assertEquals(['fork', 'knife', 'spoon'], $items);
$types = DB::collection('items')->distinct('type')->get(); sort($types);
$this->assertEquals(2, count($types));
$this->assertEquals(array('round', 'sharp'), $types);
$this->assertEquals(['round', 'sharp'], $types);
}
public function testCustomId()
{
DB::collection('items')->insert(array(
array('_id' => 'knife', 'type' => 'sharp', 'amount' => 34),
array('_id' => 'fork', 'type' => 'sharp', 'amount' => 20),
array('_id' => 'spoon', 'type' => 'round', 'amount' => 3)
));
DB::collection('items')->insert([
['_id' => 'knife', 'type' => 'sharp', 'amount' => 34],
['_id' => 'fork', 'type' => 'sharp', 'amount' => 20],
['_id' => 'spoon', 'type' => 'round', 'amount' => 3]
]);
$item = DB::collection('items')->find('knife');
$this->assertEquals('knife', $item['_id']);
......@@ -309,10 +309,10 @@ class QueryBuilderTest extends TestCase {
$item = DB::collection('items')->where('_id', 'fork')->first();
$this->assertEquals('fork', $item['_id']);
DB::collection('users')->insert(array(
array('_id' => 1, 'name' => 'Jane Doe'),
array('_id' => 2, 'name' => 'John Doe')
));
DB::collection('users')->insert([
['_id' => 1, 'name' => 'Jane Doe'],
['_id' => 2, 'name' => 'John Doe']
]);
$item = DB::collection('users')->find(1);
$this->assertEquals(1, $item['_id']);
......@@ -320,12 +320,12 @@ class QueryBuilderTest extends TestCase {
public function testTake()
{
DB::collection('items')->insert(array(
array('name' => 'knife', 'type' => 'sharp', 'amount' => 34),
array('name' => 'fork', 'type' => 'sharp', 'amount' => 20),
array('name' => 'spoon', 'type' => 'round', 'amount' => 3),
array('name' => 'spoon', 'type' => 'round', 'amount' => 14)
));
DB::collection('items')->insert([
['name' => 'knife', 'type' => 'sharp', 'amount' => 34],
['name' => 'fork', 'type' => 'sharp', 'amount' => 20],
['name' => 'spoon', 'type' => 'round', 'amount' => 3],
['name' => 'spoon', 'type' => 'round', 'amount' => 14]
]);
$items = DB::collection('items')->orderBy('name')->take(2)->get();
$this->assertEquals(2, count($items));
......@@ -334,12 +334,12 @@ class QueryBuilderTest extends TestCase {
public function testSkip()
{
DB::collection('items')->insert(array(
array('name' => 'knife', 'type' => 'sharp', 'amount' => 34),
array('name' => 'fork', 'type' => 'sharp', 'amount' => 20),
array('name' => 'spoon', 'type' => 'round', 'amount' => 3),
array('name' => 'spoon', 'type' => 'round', 'amount' => 14)
));
DB::collection('items')->insert([
['name' => 'knife', 'type' => 'sharp', 'amount' => 34],
['name' => 'fork', 'type' => 'sharp', 'amount' => 20],
['name' => 'spoon', 'type' => 'round', 'amount' => 3],
['name' => 'spoon', 'type' => 'round', 'amount' => 14]
]);
$items = DB::collection('items')->orderBy('name')->skip(2)->get();
$this->assertEquals(2, count($items));
......@@ -348,10 +348,10 @@ class QueryBuilderTest extends TestCase {
public function testPluck()
{
DB::collection('users')->insert(array(
array('name' => 'Jane Doe', 'age' => 20),
array('name' => 'John Doe', 'age' => 25)
));
DB::collection('users')->insert([
['name' => 'Jane Doe', 'age' => 20],
['name' => 'John Doe', 'age' => 25]
]);
$age = DB::collection('users')->where('name', 'John Doe')->pluck('age');
$this->assertEquals(25, $age);
......@@ -359,21 +359,21 @@ class QueryBuilderTest extends TestCase {
public function testList()
{
DB::collection('items')->insert(array(
array('name' => 'knife', 'type' => 'sharp', 'amount' => 34),
array('name' => 'fork', 'type' => 'sharp', 'amount' => 20),
array('name' => 'spoon', 'type' => 'round', 'amount' => 3),
array('name' => 'spoon', 'type' => 'round', 'amount' => 14)
));
DB::collection('items')->insert([
['name' => 'knife', 'type' => 'sharp', 'amount' => 34],
['name' => 'fork', 'type' => 'sharp', 'amount' => 20],
['name' => 'spoon', 'type' => 'round', 'amount' => 3],
['name' => 'spoon', 'type' => 'round', 'amount' => 14]
]);
$list = DB::collection('items')->lists('name');
sort($list);
$this->assertEquals(4, count($list));
$this->assertEquals(array('fork', 'knife', 'spoon', 'spoon'), $list);
$this->assertEquals(['fork', 'knife', 'spoon', 'spoon'], $list);
$list = DB::collection('items')->lists('type', 'name');
$this->assertEquals(3, count($list));
$this->assertEquals(array('knife' => 'sharp', 'fork' => 'sharp', 'spoon' => 'round'), $list);
$this->assertEquals(['knife' => 'sharp', 'fork' => 'sharp', 'spoon' => 'round'], $list);
$list = DB::collection('items')->lists('name', '_id');
$this->assertEquals(4, count($list));
......@@ -382,12 +382,12 @@ class QueryBuilderTest extends TestCase {
public function testAggregate()
{
DB::collection('items')->insert(array(
array('name' => 'knife', 'type' => 'sharp', 'amount' => 34),
array('name' => 'fork', 'type' => 'sharp', 'amount' => 20),
array('name' => 'spoon', 'type' => 'round', 'amount' => 3),
array('name' => 'spoon', 'type' => 'round', 'amount' => 14)
));
DB::collection('items')->insert([
['name' => 'knife', 'type' => 'sharp', 'amount' => 34],
['name' => 'fork', 'type' => 'sharp', 'amount' => 20],
['name' => 'spoon', 'type' => 'round', 'amount' => 3],
['name' => 'spoon', 'type' => 'round', 'amount' => 14]
]);
$this->assertEquals(71, DB::collection('items')->sum('amount'));
$this->assertEquals(4, DB::collection('items')->count('amount'));
......@@ -401,12 +401,12 @@ class QueryBuilderTest extends TestCase {
public function testSubdocumentAggregate()
{
DB::collection('items')->insert(array(
array('name' => 'knife', 'amount' => array('hidden' => 10, 'found' => 3)),
array('name' => 'fork', 'amount' => array('hidden' => 35, 'found' => 12)),
array('name' => 'spoon', 'amount' => array('hidden' => 14, 'found' => 21)),
array('name' => 'spoon', 'amount' => array('hidden' => 6, 'found' => 4))
));
DB::collection('items')->insert([
['name' => 'knife', 'amount' => ['hidden' => 10, 'found' => 3]],
['name' => 'fork', 'amount' => ['hidden' => 35, 'found' => 12]],
['name' => 'spoon', 'amount' => ['hidden' => 14, 'found' => 21]],
['name' => 'spoon', 'amount' => ['hidden' => 6, 'found' => 4]]
]);
$this->assertEquals(65, DB::collection('items')->sum('amount.hidden'));
$this->assertEquals(4, DB::collection('items')->count('amount.hidden'));
......@@ -419,8 +419,8 @@ class QueryBuilderTest extends TestCase {
{
DB::collection('items')->where('name', 'knife')
->update(
array('amount' => 1),
array('upsert' => true)
['amount' => 1],
['upsert' => true]
);
$this->assertEquals(1, DB::collection('items')->count());
......@@ -428,8 +428,8 @@ class QueryBuilderTest extends TestCase {
public function testUnset()
{
$id1 = DB::collection('users')->insertGetId(array('name' => 'John Doe', 'note1' => 'ABC', 'note2' => 'DEF'));
$id2 = DB::collection('users')->insertGetId(array('name' => 'Jane Doe', 'note1' => 'ABC', 'note2' => 'DEF'));
$id1 = DB::collection('users')->insertGetId(['name' => 'John Doe', 'note1' => 'ABC', 'note2' => 'DEF']);
$id2 = DB::collection('users')->insertGetId(['name' => 'Jane Doe', 'note1' => 'ABC', 'note2' => 'DEF']);
DB::collection('users')->where('name', 'John Doe')->unset('note1');
......@@ -441,7 +441,7 @@ class QueryBuilderTest extends TestCase {
$this->assertTrue(isset($user2['note1']));
$this->assertTrue(isset($user2['note2']));
DB::collection('users')->where('name', 'Jane Doe')->unset(array('note1', 'note2'));
DB::collection('users')->where('name', 'Jane Doe')->unset(['note1', 'note2']);
$user2 = DB::collection('users')->find($id2);
$this->assertFalse(isset($user2['note1']));
......@@ -450,9 +450,9 @@ class QueryBuilderTest extends TestCase {
public function testUpdateSubdocument()
{
$id = DB::collection('users')->insertGetId(array('name' => 'John Doe', 'address' => array('country' => 'Belgium')));
$id = DB::collection('users')->insertGetId(['name' => 'John Doe', 'address' => ['country' => 'Belgium']]);
DB::collection('users')->where('_id', $id)->update(array('address.country' => 'England'));
DB::collection('users')->where('_id', $id)->update(['address.country' => 'England']);
$check = DB::collection('users')->find($id);
$this->assertEquals('England', $check['address']['country']);
......@@ -460,12 +460,12 @@ class QueryBuilderTest extends TestCase {
public function testDates()
{
DB::collection('users')->insert(array(
array('name' => 'John Doe', 'birthday' => new MongoDate(strtotime("1980-01-01 00:00:00"))),
array('name' => 'Jane Doe', 'birthday' => new MongoDate(strtotime("1981-01-01 00:00:00"))),
array('name' => 'Robert Roe', 'birthday' => new MongoDate(strtotime("1982-01-01 00:00:00"))),
array('name' => 'Mark Moe', 'birthday' => new MongoDate(strtotime("1983-01-01 00:00:00"))),
));
DB::collection('users')->insert([
['name' => 'John Doe', 'birthday' => new MongoDate(strtotime("1980-01-01 00:00:00"))],
['name' => 'Jane Doe', 'birthday' => new MongoDate(strtotime("1981-01-01 00:00:00"))],
['name' => 'Robert Roe', 'birthday' => new MongoDate(strtotime("1982-01-01 00:00:00"))],
['name' => 'Mark Moe', 'birthday' => new MongoDate(strtotime("1983-01-01 00:00:00"))],
]);
$user = DB::collection('users')->where('birthday', new MongoDate(strtotime("1980-01-01 00:00:00")))->first();
$this->assertEquals('John Doe', $user['name']);
......@@ -476,21 +476,21 @@ class QueryBuilderTest extends TestCase {
$start = new MongoDate(strtotime("1981-01-01 00:00:00"));
$stop = new MongoDate(strtotime("1982-01-01 00:00:00"));
$users = DB::collection('users')->whereBetween('birthday', array($start, $stop))->get();
$users = DB::collection('users')->whereBetween('birthday', [$start, $stop])->get();
$this->assertEquals(2, count($users));
}
public function testOperators()
{
DB::collection('users')->insert(array(
array('name' => 'John Doe', 'age' => 30),
array('name' => 'Jane Doe'),
array('name' => 'Robert Roe', 'age' => 'thirty-one'),
));
DB::collection('users')->insert([
['name' => 'John Doe', 'age' => 30],
['name' => 'Jane Doe'],
['name' => 'Robert Roe', 'age' => 'thirty-one'],
]);
$results = DB::collection('users')->where('age', 'exists', true)->get();
$this->assertEquals(2, count($results));
$resultsNames = array($results[0]['name'], $results[1]['name']);
$resultsNames = [$results[0]['name'], $results[1]['name']];
$this->assertContains('John Doe', $resultsNames);
$this->assertContains('Robert Roe', $resultsNames);
......@@ -502,27 +502,27 @@ class QueryBuilderTest extends TestCase {
$this->assertEquals(1, count($results));
$this->assertEquals('Robert Roe', $results[0]['name']);
$results = DB::collection('users')->where('age', 'mod', array(15, 0))->get();
$results = DB::collection('users')->where('age', 'mod', [15, 0])->get();
$this->assertEquals(1, count($results));
$this->assertEquals('John Doe', $results[0]['name']);
$results = DB::collection('users')->where('age', 'mod', array(29, 1))->get();
$results = DB::collection('users')->where('age', 'mod', [29, 1])->get();
$this->assertEquals(1, count($results));
$this->assertEquals('John Doe', $results[0]['name']);
$results = DB::collection('users')->where('age', 'mod', array(14, 0))->get();
$results = DB::collection('users')->where('age', 'mod', [14, 0])->get();
$this->assertEquals(0, count($results));
DB::collection('items')->insert(array(
array('name' => 'fork', 'tags' => array('sharp', 'pointy')),
array('name' => 'spork', 'tags' => array('sharp', 'pointy', 'round', 'bowl')),
array('name' => 'spoon', 'tags' => array('round', 'bowl')),
));
DB::collection('items')->insert([
['name' => 'fork', 'tags' => ['sharp', 'pointy']],
['name' => 'spork', 'tags' => ['sharp', 'pointy', 'round', 'bowl']],
['name' => 'spoon', 'tags' => ['round', 'bowl']],
]);
$results = DB::collection('items')->where('tags', 'all', array('sharp', 'pointy'))->get();
$results = DB::collection('items')->where('tags', 'all', ['sharp', 'pointy'])->get();
$this->assertEquals(2, count($results));
$results = DB::collection('items')->where('tags', 'all', array('sharp', 'round'))->get();
$results = DB::collection('items')->where('tags', 'all', ['sharp', 'round'])->get();
$this->assertEquals(1, count($results));
$results = DB::collection('items')->where('tags', 'size', 2)->get();
......@@ -554,36 +554,36 @@ class QueryBuilderTest extends TestCase {
$results = DB::collection('users')->where('name', 'not regexp', '/.*doe/i')->get();
$this->assertEquals(1, count($results));
DB::collection('users')->insert(array(
array(
DB::collection('users')->insert([
[
'name' => 'John Doe',
'addresses' => array(
array('city' => 'Ghent'),
array('city' => 'Paris')
)
),
array(
'addresses' => [
['city' => 'Ghent'],
['city' => 'Paris']
]
],
[
'name' => 'Jane Doe',
'addresses' => array(
array('city' => 'Brussels'),
array('city' => 'Paris')
)
)
));
$users = DB::collection('users')->where('addresses', 'elemMatch', array('city' => 'Brussels'))->get();
'addresses' => [
['city' => 'Brussels'],
['city' => 'Paris']
]
]
]);
$users = DB::collection('users')->where('addresses', 'elemMatch', ['city' => 'Brussels'])->get();
$this->assertEquals(1, count($users));
$this->assertEquals('Jane Doe', $users[0]['name']);
}
public function testIncrement()
{
DB::collection('users')->insert(array(
array('name' => 'John Doe', 'age' => 30, 'note' => 'adult'),
array('name' => 'Jane Doe', 'age' => 10, 'note' => 'minor'),
array('name' => 'Robert Roe', 'age' => null),
array('name' => 'Mark Moe'),
));
DB::collection('users')->insert([
['name' => 'John Doe', 'age' => 30, 'note' => 'adult'],
['name' => 'Jane Doe', 'age' => 10, 'note' => 'minor'],
['name' => 'Robert Roe', 'age' => null],
['name' => 'Mark Moe'],
]);
$user = DB::collection('users')->where('name', 'John Doe')->first();
$this->assertEquals(30, $user['age']);
......@@ -604,12 +604,12 @@ class QueryBuilderTest extends TestCase {
$user = DB::collection('users')->where('name', 'John Doe')->first();
$this->assertEquals(30, $user['age']);
DB::collection('users')->where('name', 'Jane Doe')->increment('age', 10, array('note' => 'adult'));
DB::collection('users')->where('name', 'Jane Doe')->increment('age', 10, ['note' => 'adult']);
$user = DB::collection('users')->where('name', 'Jane Doe')->first();
$this->assertEquals(20, $user['age']);
$this->assertEquals('adult', $user['note']);
DB::collection('users')->where('name', 'John Doe')->decrement('age', 20, array('note' => 'minor'));
DB::collection('users')->where('name', 'John Doe')->decrement('age', 20, ['note' => 'minor']);
$user = DB::collection('users')->where('name', 'John Doe')->first();
$this->assertEquals(10, $user['age']);
$this->assertEquals('minor', $user['note']);
......@@ -627,13 +627,13 @@ class QueryBuilderTest extends TestCase {
public function testProjections()
{
DB::collection('items')->insert(array(
array('name' => 'fork', 'tags' => array('sharp', 'pointy')),
array('name' => 'spork', 'tags' => array('sharp', 'pointy', 'round', 'bowl')),
array('name' => 'spoon', 'tags' => array('round', 'bowl')),
));
DB::collection('items')->insert([
['name' => 'fork', 'tags' => ['sharp', 'pointy']],
['name' => 'spork', 'tags' => ['sharp', 'pointy', 'round', 'bowl']],
['name' => 'spoon', 'tags' => ['round', 'bowl']],
]);
$results = DB::collection('items')->project(array('tags' => array('$slice' => 1)))->get();
$results = DB::collection('items')->project(['tags' => ['$slice' => 1]])->get();
foreach ($results as $result)
{
......
......@@ -7,15 +7,15 @@ class QueryTest extends TestCase {
public function setUp()
{
parent::setUp();
User::create(array('name' => 'John Doe', 'age' => 35, 'title' => 'admin'));
User::create(array('name' => 'Jane Doe', 'age' => 33, 'title' => 'admin'));
User::create(array('name' => 'Harry Hoe', 'age' => 13, 'title' => 'user'));
User::create(array('name' => 'Robert Roe', 'age' => 37, 'title' => 'user'));
User::create(array('name' => 'Mark Moe', 'age' => 23, 'title' => 'user'));
User::create(array('name' => 'Brett Boe', 'age' => 35, 'title' => 'user'));
User::create(array('name' => 'Tommy Toe', 'age' => 33, 'title' => 'user'));
User::create(array('name' => 'Yvonne Yoe', 'age' => 35, 'title' => 'admin'));
User::create(array('name' => 'Error', 'age' => null, 'title' => null));
User::create(['name' => 'John Doe', 'age' => 35, 'title' => 'admin']);
User::create(['name' => 'Jane Doe', 'age' => 33, 'title' => 'admin']);
User::create(['name' => 'Harry Hoe', 'age' => 13, 'title' => 'user']);
User::create(['name' => 'Robert Roe', 'age' => 37, 'title' => 'user']);
User::create(['name' => 'Mark Moe', 'age' => 23, 'title' => 'user']);
User::create(['name' => 'Brett Boe', 'age' => 35, 'title' => 'user']);
User::create(['name' => 'Tommy Toe', 'age' => 33, 'title' => 'user']);
User::create(['name' => 'Yvonne Yoe', 'age' => 35, 'title' => 'admin']);
User::create(['name' => 'Error', 'age' => null, 'title' => null]);
}
public function tearDown()
......@@ -83,13 +83,13 @@ class QueryTest extends TestCase {
$this->assertEquals('admin', $user->title);
$this->assertEquals(null, $user->age);
$user = User::where('name', 'John Doe')->select(array('name', 'title'))->get()->first();
$user = User::where('name', 'John Doe')->select(['name', 'title'])->get()->first();
$this->assertEquals('John Doe', $user->name);
$this->assertEquals('admin', $user->title);
$this->assertEquals(null, $user->age);
$user = User::where('name', 'John Doe')->get(array('name'))->first();
$user = User::where('name', 'John Doe')->get(['name'])->first();
$this->assertEquals('John Doe', $user->name);
$this->assertEquals(null, $user->age);
......@@ -106,30 +106,30 @@ class QueryTest extends TestCase {
public function testBetween()
{
$users = User::whereBetween('age', array(0, 25))->get();
$users = User::whereBetween('age', [0, 25])->get();
$this->assertEquals(2, count($users));
$users = User::whereBetween('age', array(13, 23))->get();
$users = User::whereBetween('age', [13, 23])->get();
$this->assertEquals(2, count($users));
// testing whereNotBetween for version 4.1
$users = User::whereBetween('age', array(0, 25), 'and', true)->get();
$users = User::whereBetween('age', [0, 25], 'and', true)->get();
$this->assertEquals(6, count($users));
}
public function testIn()
{
$users = User::whereIn('age', array(13, 23))->get();
$users = User::whereIn('age', [13, 23])->get();
$this->assertEquals(2, count($users));
$users = User::whereIn('age', array(33, 35, 13))->get();
$users = User::whereIn('age', [33, 35, 13])->get();
$this->assertEquals(6, count($users));
$users = User::whereNotIn('age', array(33, 35))->get();
$users = User::whereNotIn('age', [33, 35])->get();
$this->assertEquals(4, count($users));
$users = User::whereNotNull('age')
->whereNotIn('age', array(33, 35))->get();
->whereNotIn('age', [33, 35])->get();
$this->assertEquals(3, count($users));
}
......@@ -263,13 +263,13 @@ class QueryTest extends TestCase {
public function testWhereRaw()
{
$where = array('age' => array('$gt' => 30, '$lt' => 40));
$where = ['age' => ['$gt' => 30, '$lt' => 40]];
$users = User::whereRaw($where)->get();
$this->assertEquals(6, count($users));
$where1 = array('age' => array('$gt' => 30, '$lte' => 35));
$where2 = array('age' => array('$gt' => 35, '$lt' => 40));
$where1 = ['age' => ['$gt' => 30, '$lte' => 35]];
$where2 = ['age' => ['$gt' => 35, '$lt' => 40]];
$users = User::whereRaw($where1)->orWhereRaw($where2)->get();
$this->assertEquals(6, count($users));
......@@ -307,7 +307,7 @@ class QueryTest extends TestCase {
$this->assertNotNull($results->first()->title);
$this->assertEquals(9, $results->total());
$results = User::paginate(2, array('name', 'age'));
$results = User::paginate(2, ['name', 'age']);
$this->assertEquals(2, $results->count());
$this->assertNull($results->first()->title);
$this->assertEquals(9, $results->total());
......
......@@ -19,18 +19,18 @@ class RelationsTest extends TestCase {
public function testHasMany()
{
$author = User::create(array('name' => 'George R. R. Martin'));
Book::create(array('title' => 'A Game of Thrones', 'author_id' => $author->_id));
Book::create(array('title' => 'A Clash of Kings', 'author_id' => $author->_id));
$author = User::create(['name' => 'George R. R. Martin']);
Book::create(['title' => 'A Game of Thrones', 'author_id' => $author->_id]);
Book::create(['title' => 'A Clash of Kings', 'author_id' => $author->_id]);
$books = $author->books;
$this->assertEquals(2, count($books));
$user = User::create(array('name' => 'John Doe'));
Item::create(array('type' => 'knife', 'user_id' => $user->_id));
Item::create(array('type' => 'shield', 'user_id' => $user->_id));
Item::create(array('type' => 'sword', 'user_id' => $user->_id));
Item::create(array('type' => 'bag', 'user_id' => null));
$user = User::create(['name' => 'John Doe']);
Item::create(['type' => 'knife', 'user_id' => $user->_id]);
Item::create(['type' => 'shield', 'user_id' => $user->_id]);
Item::create(['type' => 'sword', 'user_id' => $user->_id]);
Item::create(['type' => 'bag', 'user_id' => null]);
$items = $user->items;
$this->assertEquals(3, count($items));
......@@ -38,15 +38,15 @@ class RelationsTest extends TestCase {
public function testBelongsTo()
{
$user = User::create(array('name' => 'George R. R. Martin'));
Book::create(array('title' => 'A Game of Thrones', 'author_id' => $user->_id));
$book = Book::create(array('title' => 'A Clash of Kings', 'author_id' => $user->_id));
$user = User::create(['name' => 'George R. R. Martin']);
Book::create(['title' => 'A Game of Thrones', 'author_id' => $user->_id]);
$book = Book::create(['title' => 'A Clash of Kings', 'author_id' => $user->_id]);
$author = $book->author;
$this->assertEquals('George R. R. Martin', $author->name);
$user = User::create(array('name' => 'John Doe'));
$item = Item::create(array('type' => 'sword', 'user_id' => $user->_id));
$user = User::create(['name' => 'John Doe']);
$item = Item::create(['type' => 'sword', 'user_id' => $user->_id]);
$owner = $item->user;
$this->assertEquals('John Doe', $owner->name);
......@@ -54,15 +54,15 @@ class RelationsTest extends TestCase {
public function testHasOne()
{
$user = User::create(array('name' => 'John Doe'));
Role::create(array('type' => 'admin', 'user_id' => $user->_id));
$user = User::create(['name' => 'John Doe']);
Role::create(['type' => 'admin', 'user_id' => $user->_id]);
$role = $user->role;
$this->assertEquals('admin', $role->type);
$this->assertEquals($user->_id, $role->user_id);
$user = User::create(array('name' => 'Jane Doe'));
$role = new Role(array('type' => 'user'));
$user = User::create(['name' => 'Jane Doe']);
$role = new Role(['type' => 'user']);
$user->role()->save($role);
$role = $user->role;
......@@ -77,11 +77,11 @@ class RelationsTest extends TestCase {
public function testWithBelongsTo()
{
$user = User::create(array('name' => 'John Doe'));
Item::create(array('type' => 'knife', 'user_id' => $user->_id));
Item::create(array('type' => 'shield', 'user_id' => $user->_id));
Item::create(array('type' => 'sword', 'user_id' => $user->_id));
Item::create(array('type' => 'bag', 'user_id' => null));
$user = User::create(['name' => 'John Doe']);
Item::create(['type' => 'knife', 'user_id' => $user->_id]);
Item::create(['type' => 'shield', 'user_id' => $user->_id]);
Item::create(['type' => 'sword', 'user_id' => $user->_id]);
Item::create(['type' => 'bag', 'user_id' => null]);
$items = Item::with('user')->orderBy('user_id', 'desc')->get();
......@@ -94,11 +94,11 @@ class RelationsTest extends TestCase {
public function testWithHashMany()
{
$user = User::create(array('name' => 'John Doe'));
Item::create(array('type' => 'knife', 'user_id' => $user->_id));
Item::create(array('type' => 'shield', 'user_id' => $user->_id));
Item::create(array('type' => 'sword', 'user_id' => $user->_id));
Item::create(array('type' => 'bag', 'user_id' => null));
$user = User::create(['name' => 'John Doe']);
Item::create(['type' => 'knife', 'user_id' => $user->_id]);
Item::create(['type' => 'shield', 'user_id' => $user->_id]);
Item::create(['type' => 'sword', 'user_id' => $user->_id]);
Item::create(['type' => 'bag', 'user_id' => null]);
$user = User::with('items')->find($user->_id);
......@@ -109,9 +109,9 @@ class RelationsTest extends TestCase {
public function testWithHasOne()
{
$user = User::create(array('name' => 'John Doe'));
Role::create(array('type' => 'admin', 'user_id' => $user->_id));
Role::create(array('type' => 'guest', 'user_id' => $user->_id));
$user = User::create(['name' => 'John Doe']);
Role::create(['type' => 'admin', 'user_id' => $user->_id]);
Role::create(['type' => 'guest', 'user_id' => $user->_id]);
$user = User::with('role')->find($user->_id);
......@@ -123,8 +123,8 @@ class RelationsTest extends TestCase {
public function testEasyRelation()
{
// Has Many
$user = User::create(array('name' => 'John Doe'));
$item = Item::create(array('type' => 'knife'));
$user = User::create(['name' => 'John Doe']);
$item = Item::create(['type' => 'knife']);
$user->items()->save($item);
$user = User::find($user->_id);
......@@ -134,8 +134,8 @@ class RelationsTest extends TestCase {
$this->assertEquals($user->_id, $items[0]->user_id);
// Has one
$user = User::create(array('name' => 'John Doe'));
$role = Role::create(array('type' => 'admin'));
$user = User::create(['name' => 'John Doe']);
$role = Role::create(['type' => 'admin']);
$user->role()->save($role);
$user = User::find($user->_id);
......@@ -147,11 +147,11 @@ class RelationsTest extends TestCase {
public function testBelongsToMany()
{
$user = User::create(array('name' => 'John Doe'));
$user = User::create(['name' => 'John Doe']);
// Add 2 clients
$user->clients()->save(new Client(array('name' => 'Pork Pies Ltd.')));
$user->clients()->create(array('name' => 'Buffet Bar Inc.'));
$user->clients()->save(new Client(['name' => 'Pork Pies Ltd.']));
$user->clients()->create(['name' => 'Buffet Bar Inc.']);
// Refetch
$user = User::with('clients')->find($user->_id);
......@@ -172,7 +172,7 @@ class RelationsTest extends TestCase {
$this->assertCount(1, $client->users);
// Now create a new user to an existing client
$user = $client->users()->create(array('name' => 'Jane Doe'));
$user = $client->users()->create(['name' => 'Jane Doe']);
$this->assertInstanceOf('Illuminate\Database\Eloquent\Collection', $user->clients);
$this->assertInstanceOf('Client', $user->clients->first());
......@@ -206,7 +206,7 @@ class RelationsTest extends TestCase {
$this->assertCount(2, $client->users);
// Detach clients from user
$user->clients()->sync(array());
$user->clients()->sync([]);
// Get the new user model
$user = User::where('name', '=', 'Jane Doe')->first();
......@@ -221,17 +221,17 @@ class RelationsTest extends TestCase {
public function testBelongsToManyAttachesExistingModels()
{
$user = User::create(array('name' => 'John Doe', 'client_ids' => array('1234523')));
$user = User::create(['name' => 'John Doe', 'client_ids' => ['1234523']]);
$clients = array(
Client::create(array('name' => 'Pork Pies Ltd.'))->_id,
Client::create(array('name' => 'Buffet Bar Inc.'))->_id
);
$clients = [
Client::create(['name' => 'Pork Pies Ltd.'])->_id,
Client::create(['name' => 'Buffet Bar Inc.'])->_id
];
$moreClients = array(
Client::create(array('name' => 'synced Boloni Ltd.'))->_id,
Client::create(array('name' => 'synced Meatballs Inc.'))->_id
);
$moreClients = [
Client::create(['name' => 'synced Boloni Ltd.'])->_id,
Client::create(['name' => 'synced Meatballs Inc.'])->_id
];
// Sync multiple records
$user->clients()->sync($clients);
......@@ -261,27 +261,27 @@ class RelationsTest extends TestCase {
public function testBelongsToManySync()
{
// create test instances
$user = User::create(array('name' => 'John Doe'));
$client1 = Client::create(array('name' => 'Pork Pies Ltd.'))->_id;
$client2 = Client::create(array('name' => 'Buffet Bar Inc.'))->_id;
$user = User::create(['name' => 'John Doe']);
$client1 = Client::create(['name' => 'Pork Pies Ltd.'])->_id;
$client2 = Client::create(['name' => 'Buffet Bar Inc.'])->_id;
// Sync multiple
$user->clients()->sync(array($client1, $client2));
$user->clients()->sync([$client1, $client2]);
$this->assertCount(2, $user->clients);
// Refresh user
$user = User::where('name', '=', 'John Doe')->first();
// Sync single
$user->clients()->sync(array($client1));
$user->clients()->sync([$client1]);
$this->assertCount(1, $user->clients);
}
public function testBelongsToManyAttachArray()
{
$user = User::create(array('name' => 'John Doe'));
$client1 = Client::create(array('name' => 'Test 1'))->_id;
$client2 = Client::create(array('name' => 'Test 2'))->_id;
$user = User::create(['name' => 'John Doe']);
$client1 = Client::create(['name' => 'Test 1'])->_id;
$client2 = Client::create(['name' => 'Test 2'])->_id;
$user = User::where('name', '=', 'John Doe')->first();
$user->clients()->attach([$client1, $client2]);
......@@ -290,9 +290,9 @@ class RelationsTest extends TestCase {
public function testBelongsToManySyncAlreadyPresent()
{
$user = User::create(array('name' => 'John Doe'));
$client1 = Client::create(array('name' => 'Test 1'))->_id;
$client2 = Client::create(array('name' => 'Test 2'))->_id;
$user = User::create(['name' => 'John Doe']);
$client1 = Client::create(['name' => 'Test 1'])->_id;
$client2 = Client::create(['name' => 'Test 2'])->_id;
$user->clients()->sync([$client1, $client2]);
$this->assertCount(2, $user->clients);
......@@ -307,8 +307,8 @@ class RelationsTest extends TestCase {
public function testBelongsToManyCustom()
{
$user = User::create(array('name' => 'John Doe'));
$group = $user->groups()->create(array('name' => 'Admins'));
$user = User::create(['name' => 'John Doe']);
$group = $user->groups()->create(['name' => 'Admins']);
// Refetch
$user = User::find($user->_id);
......@@ -327,10 +327,10 @@ class RelationsTest extends TestCase {
public function testMorph()
{
$user = User::create(array('name' => 'John Doe'));
$client = Client::create(array('name' => 'Jane Doe'));
$user = User::create(['name' => 'John Doe']);
$client = Client::create(['name' => 'Jane Doe']);
$photo = Photo::create(array('url' => 'http://graph.facebook.com/john.doe/picture'));
$photo = Photo::create(['url' => 'http://graph.facebook.com/john.doe/picture']);
$photo = $user->photos()->save($photo);
$this->assertEquals(1, $user->photos->count());
......@@ -340,7 +340,7 @@ class RelationsTest extends TestCase {
$this->assertEquals(1, $user->photos->count());
$this->assertEquals($photo->id, $user->photos->first()->id);
$photo = Photo::create(array('url' => 'http://graph.facebook.com/jane.doe/picture'));
$photo = Photo::create(['url' => 'http://graph.facebook.com/jane.doe/picture']);
$client->photo()->save($photo);
$this->assertNotNull($client->photo);
......@@ -370,13 +370,13 @@ class RelationsTest extends TestCase {
public function testHasManyHas()
{
$author1 = User::create(array('name' => 'George R. R. Martin'));
$author1->books()->create(array('title' => 'A Game of Thrones', 'rating' => 5));
$author1->books()->create(array('title' => 'A Clash of Kings', 'rating' => 5));
$author2 = User::create(array('name' => 'John Doe'));
$author2->books()->create(array('title' => 'My book', 'rating' => 2));
User::create(array('name' => 'Anonymous author'));
Book::create(array('title' => 'Anonymous book', 'rating' => 1));
$author1 = User::create(['name' => 'George R. R. Martin']);
$author1->books()->create(['title' => 'A Game of Thrones', 'rating' => 5]);
$author1->books()->create(['title' => 'A Clash of Kings', 'rating' => 5]);
$author2 = User::create(['name' => 'John Doe']);
$author2->books()->create(['title' => 'My book', 'rating' => 2]);
User::create(['name' => 'Anonymous author']);
Book::create(['title' => 'Anonymous book', 'rating' => 1]);
$authors = User::has('books')->get();
$this->assertCount(2, $authors);
......@@ -424,12 +424,12 @@ class RelationsTest extends TestCase {
public function testHasOneHas()
{
$user1 = User::create(array('name' => 'John Doe'));
$user1->role()->create(array('title' => 'admin'));
$user2 = User::create(array('name' => 'Jane Doe'));
$user2->role()->create(array('title' => 'reseller'));
User::create(array('name' => 'Mark Moe'));
Role::create(array('title' => 'Customer'));
$user1 = User::create(['name' => 'John Doe']);
$user1->role()->create(['title' => 'admin']);
$user2 = User::create(['name' => 'Jane Doe']);
$user2->role()->create(['title' => 'reseller']);
User::create(['name' => 'Mark Moe']);
Role::create(['title' => 'Customer']);
$users = User::has('role')->get();
$this->assertCount(2, $users);
......@@ -445,19 +445,19 @@ class RelationsTest extends TestCase {
public function testNestedKeys()
{
$client = Client::create(array(
'data' => array(
$client = Client::create([
'data' => [
'client_id' => 35298,
'name' => 'John Doe'
)
));
]
]);
$address = $client->addresses()->create(array(
'data' => array(
$address = $client->addresses()->create([
'data' => [
'address_id' => 1432,
'city' => 'Paris'
)
));
]
]);
$client = Client::where('data.client_id', 35298)->first();
$this->assertEquals(1, $client->addresses->count());
......@@ -471,8 +471,8 @@ class RelationsTest extends TestCase {
public function testDoubleSaveOneToMany()
{
$author = User::create(array('name' => 'George R. R. Martin'));
$book = Book::create(array('title' => 'A Game of Thrones'));
$author = User::create(['name' => 'George R. R. Martin']);
$book = Book::create(['title' => 'A Game of Thrones']);
$author->books()->save($book);
$author->books()->save($book);
......@@ -494,29 +494,29 @@ class RelationsTest extends TestCase {
public function testDoubleSaveManyToMany()
{
$user = User::create(array('name' => 'John Doe'));
$client = Client::create(array('name' => 'Admins'));
$user = User::create(['name' => 'John Doe']);
$client = Client::create(['name' => 'Admins']);
$user->clients()->save($client);
$user->clients()->save($client);
$user->save();
$this->assertEquals(1, $user->clients()->count());
$this->assertEquals(array($user->_id), $client->user_ids);
$this->assertEquals(array($client->_id), $user->client_ids);
$this->assertEquals([$user->_id], $client->user_ids);
$this->assertEquals([$client->_id], $user->client_ids);
$user = User::where('name', 'John Doe')->first();
$client = Client::where('name', 'Admins')->first();
$this->assertEquals(1, $user->clients()->count());
$this->assertEquals(array($user->_id), $client->user_ids);
$this->assertEquals(array($client->_id), $user->client_ids);
$this->assertEquals([$user->_id], $client->user_ids);
$this->assertEquals([$client->_id], $user->client_ids);
$user->clients()->save($client);
$user->clients()->save($client);
$user->save();
$this->assertEquals(1, $user->clients()->count());
$this->assertEquals(array($user->_id), $client->user_ids);
$this->assertEquals(array($client->_id), $user->client_ids);
$this->assertEquals([$user->_id], $client->user_ids);
$this->assertEquals([$client->_id], $user->client_ids);
}
}
......@@ -60,7 +60,7 @@ class SchemaTest extends TestCase {
Schema::collection('newcollection', function($collection)
{
$collection->index(array('mykey'));
$collection->index(['mykey']);
});
$index = $this->getIndex('newcollection', 'mykey');
......@@ -92,7 +92,7 @@ class SchemaTest extends TestCase {
Schema::collection('newcollection', function($collection)
{
$collection->unique('uniquekey');
$collection->dropIndex(array('uniquekey'));
$collection->dropIndex(['uniquekey']);
});
$index = $this->getIndex('newcollection', 'uniquekey');
......
......@@ -10,10 +10,10 @@ class TestCase extends Orchestra\Testbench\TestCase {
*/
protected function getPackageProviders($app)
{
return array(
return [
'Jenssegers\Mongodb\MongodbServiceProvider',
'Jenssegers\Mongodb\Auth\PasswordResetServiceProvider',
);
];
}
/**
......
......@@ -10,16 +10,16 @@ class ValidationTest extends TestCase {
public function testUnique()
{
$validator = Validator::make(
array('name' => 'John Doe'),
array('name' => 'required|unique:users')
['name' => 'John Doe'],
['name' => 'required|unique:users']
);
$this->assertFalse($validator->fails());
User::create(array('name' => 'John Doe'));
User::create(['name' => 'John Doe']);
$validator = Validator::make(
array('name' => 'John Doe'),
array('name' => 'required|unique:users')
['name' => 'John Doe'],
['name' => 'required|unique:users']
);
$this->assertTrue($validator->fails());
}
......
<?php
return array(
return [
'connections' => array(
'connections' => [
'mongodb' => array(
'mongodb' => [
'name' => 'mongodb',
'driver' => 'mongodb',
'host' => 'localhost',
'database' => 'unittest',
),
],
'mysql' => array(
'mysql' => [
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'unittest',
......@@ -20,7 +20,7 @@ return array(
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
)
],
]
);
];
......@@ -9,6 +9,6 @@ class Soft extends Eloquent {
protected $collection = 'soft';
protected static $unguarded = true;
protected $dates = array('deleted_at');
protected $dates = ['deleted_at'];
}
......@@ -11,7 +11,7 @@ class User extends Eloquent implements AuthenticatableContract, CanResetPassword
use Authenticatable, CanResetPassword;
protected $dates = array('birthday', 'entry.date');
protected $dates = ['birthday', 'entry.date'];
protected static $unguarded = true;
public function books()
......
......@@ -9,6 +9,6 @@ class UserTableSeeder extends Seeder {
{
DB::collection('users')->delete();
DB::collection('users')->insert(array('name' => 'John Doe', 'seed' => true));
DB::collection('users')->insert(['name' => 'John Doe', 'seed' => true]);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment