|
1 | 1 | <?php |
2 | 2 | require_once('vendor/autoload.php'); |
| 3 | +require_once('tests/app.php'); |
3 | 4 |
|
| 5 | +use Jenssegers\Mongodb\Facades\DB; |
4 | 6 | use Jenssegers\Mongodb\Connection; |
5 | 7 |
|
6 | 8 | class ConnectionTest extends PHPUnit_Framework_TestCase { |
7 | 9 |
|
8 | | - private $connection; |
| 10 | + public function setUp() {} |
9 | 11 |
|
10 | | - public function setUp() |
11 | | - { |
12 | | - include('tests/app.php'); |
13 | | - $this->connection = new Connection($app['config']['database.connections']['mongodb']); |
14 | | - } |
| 12 | + public function tearDown() {} |
15 | 13 |
|
16 | | - public function tearDown() |
| 14 | + public function testConnection() |
17 | 15 | { |
| 16 | + $connection = DB::connection('mongodb'); |
| 17 | + $this->assertInstanceOf('Jenssegers\Mongodb\Connection', $connection); |
| 18 | + |
| 19 | + $c1 = DB::connection('mongodb'); |
| 20 | + $c2 = DB::connection('mongodb'); |
| 21 | + $this->assertEquals($c1, $c2); |
| 22 | + |
| 23 | + $c1 = DB::connection('mongodb'); |
| 24 | + $c2 = DB::reconnect('mongodb'); |
| 25 | + $this->assertNotEquals($c1, $c2); |
18 | 26 | } |
19 | 27 |
|
20 | 28 | public function testDb() |
21 | 29 | { |
22 | | - $db = $this->connection->getDb(); |
23 | | - $this->assertInstanceOf('MongoDB', $db); |
| 30 | + $connection = DB::connection('mongodb'); |
| 31 | + $this->assertInstanceOf('MongoDB', $connection->getDb()); |
24 | 32 | } |
25 | 33 |
|
26 | 34 | public function testCollection() |
27 | 35 | { |
28 | | - $collection = $this->connection->getCollection('unittest'); |
| 36 | + $collection = DB::connection('mongodb')->getCollection('unittest'); |
29 | 37 | $this->assertInstanceOf('MongoCollection', $collection); |
30 | 38 |
|
31 | | - $collection = $this->connection->collection('unittests'); |
| 39 | + $collection = DB::connection('mongodb')->collection('unittests'); |
32 | 40 | $this->assertInstanceOf('Jenssegers\Mongodb\Builder', $collection); |
33 | 41 |
|
34 | | - $collection = $this->connection->table('unittests'); |
| 42 | + $collection = DB::connection('mongodb')->table('unittests'); |
35 | 43 | $this->assertInstanceOf('Jenssegers\Mongodb\Builder', $collection); |
36 | 44 | } |
37 | 45 |
|
38 | 46 | public function testDynamic() |
39 | 47 | { |
40 | | - $dbs = $this->connection->listDBs(); |
| 48 | + $dbs = DB::connection('mongodb')->listCollections(); |
41 | 49 | $this->assertTrue(is_array($dbs)); |
42 | 50 | } |
43 | 51 |
|
|
0 commit comments