Skip to content

Commit 4ee56d0

Browse files
committed
Apply PSR2 PHP CS fixer to tests
1 parent 0c8c940 commit 4ee56d0

13 files changed

+3171
-3176
lines changed

tests/CollectionTests.php

+355-356
Large diffs are not rendered by default.

tests/ConnectionTests.php

+133-134
Original file line numberDiff line numberDiff line change
@@ -4,137 +4,136 @@
44

55
class ConnectionTests extends PHPUnit_Framework_TestCase
66
{
7-
protected $connection;
8-
9-
public function setUp()
10-
{
11-
if ( ! $this->connection)
12-
{
13-
$this->connection = new Connection(null, array(
14-
'connect' => true,
15-
));
16-
}
17-
}
18-
19-
public function testInjection()
20-
{
21-
$mongo = $this->connection->getConnection();
22-
$mongoHash = spl_object_hash($mongo);
23-
$connection = new Connection($mongo);
24-
$reflection = new ReflectionObject($connection);
25-
$connectionProperty = $reflection->getProperty('connection');
26-
$connectionProperty->setAccessible(true);
27-
$this->assertInstanceOf('MongoClient', $connectionProperty->getValue($connection));
28-
$this->assertEquals($mongoHash, spl_object_hash($connectionProperty->getValue($connection)));
29-
}
30-
31-
public function testDisconnect()
32-
{
33-
$this->connection->disconnect();
34-
$this->assertFalse($this->connection->isConnected());
35-
}
36-
37-
38-
public function testReconnectonnect()
39-
{
40-
$this->connection->disconnect();
41-
$this->assertTrue($this->connection->disconnect());
42-
$this->assertFalse($this->connection->isConnected());
43-
$this->connection->connect();
44-
$this->assertTrue($this->connection->connect());
45-
$this->assertTrue($this->connection->isConnected());
46-
}
47-
48-
49-
public function testHasDatabase()
50-
{
51-
$this->assertFalse($this->connection->hasDatabase('__unknown__database__'));
52-
$this->assertTrue($this->connection->hasDatabase('admin'));
53-
}
54-
55-
public function testDatabaseDefaultServer()
56-
{
57-
$connection = new Connection(null);
58-
$host = (string) $connection->getConnection();
59-
$this->assertEquals('localhost:27017', $host);
60-
}
61-
62-
public function testDatabaseConfig()
63-
{
64-
$connection = new Connection(array('connect' => true));
65-
$host = (string) $connection->getConnection();
66-
$this->assertEquals('localhost:27017', $host);
67-
}
68-
69-
public function testListDatabases()
70-
{
71-
$list = $this->connection->listDatabases();
72-
73-
$this->assertInternalType('array', $list);
74-
$this->assertContains('admin', $list);
75-
76-
$list = $this->connection->listDatabases(true);
77-
$this->assertInternalType('array', $list);
78-
}
79-
80-
public function testGetMongoObject()
81-
{
82-
$mongo = $this->connection->getConnection();
83-
84-
$this->assertInstanceOf('MongoClient', $mongo);
85-
}
86-
87-
88-
public function testDropUnknownDatabase()
89-
{
90-
$result = $this->connection->dropDatabase('_unknown_');
91-
92-
$this->assertTrue($result);
93-
}
94-
95-
96-
public function testDropKnownDatabase()
97-
{
98-
$mongo = $this->connection->getConnection();
99-
$mongo->demo->users->insert(array('test' => true));
100-
101-
$result = $this->connection->dropDatabase('demo');
102-
103-
$this->assertTrue($result);
104-
}
105-
106-
107-
public function testGetDatabase()
108-
{
109-
$database = $this->connection->database('my_db');
110-
$this->assertInstanceOf('League\Monga\Database', $database);
111-
}
112-
113-
114-
public function testGetMongoDatabase()
115-
{
116-
$database = $this->connection->database('my_db', false);
117-
$this->assertInstanceOf('MongoDB', $database);
118-
}
119-
120-
121-
public function testGetConnection()
122-
{
123-
$mongo = $this->connection->getConnection();
124-
$this->assertInstanceOf('MongoClient', $mongo);
125-
}
126-
127-
128-
public function testReplaceConnection()
129-
{
130-
$original = $this->connection->getConnection();
131-
$new = new MongoClient();
132-
$original_hash = spl_object_hash($original);
133-
$new_hash = spl_object_hash($new);
134-
$this->connection->setConnection($new);
135-
$get_hash = spl_object_hash($this->connection->getConnection());
136-
$this->assertEquals($get_hash, $new_hash);
137-
$this->assertNotEquals($get_hash, $original_hash);
138-
$this->connection->setConnection($original);
139-
}
140-
}
7+
protected $connection;
8+
9+
public function setUp()
10+
{
11+
if ( ! $this->connection) {
12+
$this->connection = new Connection(null, array(
13+
'connect' => true,
14+
));
15+
}
16+
}
17+
18+
public function testInjection()
19+
{
20+
$mongo = $this->connection->getConnection();
21+
$mongoHash = spl_object_hash($mongo);
22+
$connection = new Connection($mongo);
23+
$reflection = new ReflectionObject($connection);
24+
$connectionProperty = $reflection->getProperty('connection');
25+
$connectionProperty->setAccessible(true);
26+
$this->assertInstanceOf('MongoClient', $connectionProperty->getValue($connection));
27+
$this->assertEquals($mongoHash, spl_object_hash($connectionProperty->getValue($connection)));
28+
}
29+
30+
public function testDisconnect()
31+
{
32+
$this->connection->disconnect();
33+
$this->assertFalse($this->connection->isConnected());
34+
}
35+
36+
37+
public function testReconnectonnect()
38+
{
39+
$this->connection->disconnect();
40+
$this->assertTrue($this->connection->disconnect());
41+
$this->assertFalse($this->connection->isConnected());
42+
$this->connection->connect();
43+
$this->assertTrue($this->connection->connect());
44+
$this->assertTrue($this->connection->isConnected());
45+
}
46+
47+
48+
public function testHasDatabase()
49+
{
50+
$this->assertFalse($this->connection->hasDatabase('__unknown__database__'));
51+
$this->assertTrue($this->connection->hasDatabase('admin'));
52+
}
53+
54+
public function testDatabaseDefaultServer()
55+
{
56+
$connection = new Connection(null);
57+
$host = (string) $connection->getConnection();
58+
$this->assertEquals('localhost:27017', $host);
59+
}
60+
61+
public function testDatabaseConfig()
62+
{
63+
$connection = new Connection(array('connect' => true));
64+
$host = (string) $connection->getConnection();
65+
$this->assertEquals('localhost:27017', $host);
66+
}
67+
68+
public function testListDatabases()
69+
{
70+
$list = $this->connection->listDatabases();
71+
72+
$this->assertInternalType('array', $list);
73+
$this->assertContains('admin', $list);
74+
75+
$list = $this->connection->listDatabases(true);
76+
$this->assertInternalType('array', $list);
77+
}
78+
79+
public function testGetMongoObject()
80+
{
81+
$mongo = $this->connection->getConnection();
82+
83+
$this->assertInstanceOf('MongoClient', $mongo);
84+
}
85+
86+
87+
public function testDropUnknownDatabase()
88+
{
89+
$result = $this->connection->dropDatabase('_unknown_');
90+
91+
$this->assertTrue($result);
92+
}
93+
94+
95+
public function testDropKnownDatabase()
96+
{
97+
$mongo = $this->connection->getConnection();
98+
$mongo->demo->users->insert(array('test' => true));
99+
100+
$result = $this->connection->dropDatabase('demo');
101+
102+
$this->assertTrue($result);
103+
}
104+
105+
106+
public function testGetDatabase()
107+
{
108+
$database = $this->connection->database('my_db');
109+
$this->assertInstanceOf('League\Monga\Database', $database);
110+
}
111+
112+
113+
public function testGetMongoDatabase()
114+
{
115+
$database = $this->connection->database('my_db', false);
116+
$this->assertInstanceOf('MongoDB', $database);
117+
}
118+
119+
120+
public function testGetConnection()
121+
{
122+
$mongo = $this->connection->getConnection();
123+
$this->assertInstanceOf('MongoClient', $mongo);
124+
}
125+
126+
127+
public function testReplaceConnection()
128+
{
129+
$original = $this->connection->getConnection();
130+
$new = new MongoClient();
131+
$original_hash = spl_object_hash($original);
132+
$new_hash = spl_object_hash($new);
133+
$this->connection->setConnection($new);
134+
$get_hash = spl_object_hash($this->connection->getConnection());
135+
$this->assertEquals($get_hash, $new_hash);
136+
$this->assertNotEquals($get_hash, $original_hash);
137+
$this->connection->setConnection($original);
138+
}
139+
}

tests/CursorTests.php

+48-50
Original file line numberDiff line numberDiff line change
@@ -4,66 +4,64 @@
44

55
class CursorTests extends PHPUnit_Framework_TestCase
66
{
7-
public function testCursor()
8-
{
9-
$database = Monga::connection()
10-
->database('__database__');
7+
public function testCursor()
8+
{
9+
$database = Monga::connection()
10+
->database('__database__');
1111

12-
$collection = $database->collection('_collection');
13-
$collection->drop();
14-
$values = array(
15-
array('name' => 'Bill'),
16-
array('name' => 'Frank'),
17-
array('name' => 'George'),
18-
);
12+
$collection = $database->collection('_collection');
13+
$collection->drop();
14+
$values = array(
15+
array('name' => 'Bill'),
16+
array('name' => 'Frank'),
17+
array('name' => 'George'),
18+
);
1919

20-
$ids = $collection->insert($values);
20+
$ids = $collection->insert($values);
2121

22-
foreach($values as $index => &$row)
23-
{
24-
$row['_id'] = $ids[$index];
25-
}
22+
foreach($values as $index => &$row) {
23+
$row['_id'] = $ids[$index];
24+
}
2625

27-
$cursor = $collection->find(function($query){
28-
$query->orderBy('name', 'asc');
29-
});
30-
$asArray = array_values($cursor->toArray());
31-
$oldCollection = $cursor->getCollection();
32-
$mongocursor = $cursor->getCursor();
33-
$this->assertInstanceOf('MongoCursor', $mongocursor);
34-
$this->assertEquals(3, $cursor->count());
35-
$this->assertInstanceOf('League\Monga\Collection', $oldCollection);
26+
$cursor = $collection->find(function ($query) {
27+
$query->orderBy('name', 'asc');
28+
});
29+
$asArray = array_values($cursor->toArray());
30+
$oldCollection = $cursor->getCollection();
31+
$mongocursor = $cursor->getCursor();
32+
$this->assertInstanceOf('MongoCursor', $mongocursor);
33+
$this->assertEquals(3, $cursor->count());
34+
$this->assertInstanceOf('League\Monga\Collection', $oldCollection);
3635

37-
foreach($cursor as $row)
38-
{
39-
$this->assertInternalType('array', $row);
40-
}
36+
foreach($cursor as $row) {
37+
$this->assertInternalType('array', $row);
38+
}
4139

42-
$newCollection = $database->collection('_new_collection_');
40+
$newCollection = $database->collection('_new_collection_');
4341

44-
$this->assertEquals($values, $asArray);
45-
$this->assertInternalType('array', $asArray);
46-
$this->assertContainsOnly('array', $asArray);
42+
$this->assertEquals($values, $asArray);
43+
$this->assertInternalType('array', $asArray);
44+
$this->assertContainsOnly('array', $asArray);
4745

48-
$refs = $cursor->toRefArray();
49-
$this->assertInternalType('array', $refs);
50-
$this->assertContainsOnly('array', $refs);
51-
$this->assertInternalType('array', $cursor->explain());
52-
$this->assertInstanceOf('League\Monga\Cursor', $cursor->partial(false));
53-
$collection->drop();
54-
}
46+
$refs = $cursor->toRefArray();
47+
$this->assertInternalType('array', $refs);
48+
$this->assertContainsOnly('array', $refs);
49+
$this->assertInternalType('array', $cursor->explain());
50+
$this->assertInstanceOf('League\Monga\Cursor', $cursor->partial(false));
51+
$collection->drop();
52+
}
5553

56-
/**
54+
/**
5755
* @expectedException BadMethodCallException
5856
*/
59-
public function testBadMethodCall()
60-
{
61-
$mock = $this->getMockBuilder('MongoCursor')
62-
->disableOriginalConstructor()
63-
->getMock();
57+
public function testBadMethodCall()
58+
{
59+
$mock = $this->getMockBuilder('MongoCursor')
60+
->disableOriginalConstructor()
61+
->getMock();
6462

65-
$cursor = new League\Monga\Cursor($mock);
63+
$cursor = new League\Monga\Cursor($mock);
6664

67-
$cursor->badMethodCall();
68-
}
69-
}
65+
$cursor->badMethodCall();
66+
}
67+
}

0 commit comments

Comments
 (0)