ConnectionTest.php 2.32 KB
Newer Older
Jens Segers's avatar
Jens Segers committed
1 2
<?php

3
class ConnectionTest extends TestCase {
Jens Segers's avatar
Jens Segers committed
4

5
	public function testConnection()
Jens Segers's avatar
Jens Segers committed
6
	{
7 8 9 10 11
		$connection = DB::connection('mongodb');
		$this->assertInstanceOf('Jenssegers\Mongodb\Connection', $connection);

		$c1 = DB::connection('mongodb');
		$c2 = DB::connection('mongodb');
12
		$this->assertEquals(spl_object_hash($c1), spl_object_hash($c2));
13 14 15

		$c1 = DB::connection('mongodb');
		$c2 = DB::reconnect('mongodb');
16
		$this->assertNotEquals(spl_object_hash($c1), spl_object_hash($c2));
Jens Segers's avatar
Jens Segers committed
17 18 19 20
	}

	public function testDb()
	{
21
		$connection = DB::connection('mongodb');
22
		$this->assertInstanceOf('MongoDB', $connection->getMongoDB());
Jens Segers's avatar
Jens Segers committed
23 24 25 26
	}

	public function testCollection()
	{
27
		$collection = DB::connection('mongodb')->getCollection('unittest');
Jens Segers's avatar
Jens Segers committed
28 29
		$this->assertInstanceOf('MongoCollection', $collection);

30
		$collection = DB::connection('mongodb')->collection('unittests');
Jens Segers's avatar
Jens Segers committed
31
		$this->assertInstanceOf('Jenssegers\Mongodb\Query\Builder', $collection);
Jens Segers's avatar
Jens Segers committed
32

33
		$collection = DB::connection('mongodb')->table('unittests');
Jens Segers's avatar
Jens Segers committed
34
		$this->assertInstanceOf('Jenssegers\Mongodb\Query\Builder', $collection);
Jens Segers's avatar
Jens Segers committed
35 36 37 38
	}

	public function testDynamic()
	{
39
		$dbs = DB::connection('mongodb')->listCollections();
Jens Segers's avatar
Jens Segers committed
40
		$this->assertTrue(is_array($dbs));
Jens Segers's avatar
Jens Segers committed
41 42
	}

43
	/*public function testMultipleConnections()
44 45 46 47 48
	{
		global $app;

		# Add fake host
		$db = $app['config']['database.connections']['mongodb'];
49
		$db['host'] = array($db['host'], '1.2.3.4');
50 51 52 53 54 55

		$connection = new Connection($db);
		$mongoclient = $connection->getMongoClient();

		$hosts = $mongoclient->getHosts();
		$this->assertEquals(1, count($hosts));
56
	}*/
57

Jens Segers's avatar
Jens Segers committed
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
	public function testQueryLog()
	{
		$this->assertEquals(0, count(DB::getQueryLog()));

		DB::collection('items')->get();
		$this->assertEquals(1, count(DB::getQueryLog()));

		DB::collection('items')->insert(array('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'));
		$this->assertEquals(4, count(DB::getQueryLog()));

		DB::collection('items')->where('name', 'test')->delete();
		$this->assertEquals(5, count(DB::getQueryLog()));
	}

Jens Segers's avatar
Jens Segers committed
78 79 80 81 82 83
	public function testSchemaBuilder()
	{
		$schema = DB::connection('mongodb')->getSchemaBuilder();
		$this->assertInstanceOf('Jenssegers\Mongodb\Schema\Builder', $schema);
	}

84
}