Skip to content

Commit

Permalink
Apply PSR2 PHP CS fixer to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bcrowe committed Oct 23, 2014
1 parent 0c8c940 commit 4ee56d0
Show file tree
Hide file tree
Showing 13 changed files with 3,171 additions and 3,176 deletions.
711 changes: 355 additions & 356 deletions tests/CollectionTests.php

Large diffs are not rendered by default.

267 changes: 133 additions & 134 deletions tests/ConnectionTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,137 +4,136 @@

class ConnectionTests extends PHPUnit_Framework_TestCase
{
protected $connection;

public function setUp()
{
if ( ! $this->connection)
{
$this->connection = new Connection(null, array(
'connect' => true,
));
}
}

public function testInjection()
{
$mongo = $this->connection->getConnection();
$mongoHash = spl_object_hash($mongo);
$connection = new Connection($mongo);
$reflection = new ReflectionObject($connection);
$connectionProperty = $reflection->getProperty('connection');
$connectionProperty->setAccessible(true);
$this->assertInstanceOf('MongoClient', $connectionProperty->getValue($connection));
$this->assertEquals($mongoHash, spl_object_hash($connectionProperty->getValue($connection)));
}

public function testDisconnect()
{
$this->connection->disconnect();
$this->assertFalse($this->connection->isConnected());
}


public function testReconnectonnect()
{
$this->connection->disconnect();
$this->assertTrue($this->connection->disconnect());
$this->assertFalse($this->connection->isConnected());
$this->connection->connect();
$this->assertTrue($this->connection->connect());
$this->assertTrue($this->connection->isConnected());
}


public function testHasDatabase()
{
$this->assertFalse($this->connection->hasDatabase('__unknown__database__'));
$this->assertTrue($this->connection->hasDatabase('admin'));
}

public function testDatabaseDefaultServer()
{
$connection = new Connection(null);
$host = (string) $connection->getConnection();
$this->assertEquals('localhost:27017', $host);
}

public function testDatabaseConfig()
{
$connection = new Connection(array('connect' => true));
$host = (string) $connection->getConnection();
$this->assertEquals('localhost:27017', $host);
}

public function testListDatabases()
{
$list = $this->connection->listDatabases();

$this->assertInternalType('array', $list);
$this->assertContains('admin', $list);

$list = $this->connection->listDatabases(true);
$this->assertInternalType('array', $list);
}

public function testGetMongoObject()
{
$mongo = $this->connection->getConnection();

$this->assertInstanceOf('MongoClient', $mongo);
}


public function testDropUnknownDatabase()
{
$result = $this->connection->dropDatabase('_unknown_');

$this->assertTrue($result);
}


public function testDropKnownDatabase()
{
$mongo = $this->connection->getConnection();
$mongo->demo->users->insert(array('test' => true));

$result = $this->connection->dropDatabase('demo');

$this->assertTrue($result);
}


public function testGetDatabase()
{
$database = $this->connection->database('my_db');
$this->assertInstanceOf('League\Monga\Database', $database);
}


public function testGetMongoDatabase()
{
$database = $this->connection->database('my_db', false);
$this->assertInstanceOf('MongoDB', $database);
}


public function testGetConnection()
{
$mongo = $this->connection->getConnection();
$this->assertInstanceOf('MongoClient', $mongo);
}


public function testReplaceConnection()
{
$original = $this->connection->getConnection();
$new = new MongoClient();
$original_hash = spl_object_hash($original);
$new_hash = spl_object_hash($new);
$this->connection->setConnection($new);
$get_hash = spl_object_hash($this->connection->getConnection());
$this->assertEquals($get_hash, $new_hash);
$this->assertNotEquals($get_hash, $original_hash);
$this->connection->setConnection($original);
}
}
protected $connection;

public function setUp()
{
if ( ! $this->connection) {
$this->connection = new Connection(null, array(
'connect' => true,
));
}
}

public function testInjection()
{
$mongo = $this->connection->getConnection();
$mongoHash = spl_object_hash($mongo);
$connection = new Connection($mongo);
$reflection = new ReflectionObject($connection);
$connectionProperty = $reflection->getProperty('connection');
$connectionProperty->setAccessible(true);
$this->assertInstanceOf('MongoClient', $connectionProperty->getValue($connection));
$this->assertEquals($mongoHash, spl_object_hash($connectionProperty->getValue($connection)));
}

public function testDisconnect()
{
$this->connection->disconnect();
$this->assertFalse($this->connection->isConnected());
}


public function testReconnectonnect()
{
$this->connection->disconnect();
$this->assertTrue($this->connection->disconnect());
$this->assertFalse($this->connection->isConnected());
$this->connection->connect();
$this->assertTrue($this->connection->connect());
$this->assertTrue($this->connection->isConnected());
}


public function testHasDatabase()
{
$this->assertFalse($this->connection->hasDatabase('__unknown__database__'));
$this->assertTrue($this->connection->hasDatabase('admin'));
}

public function testDatabaseDefaultServer()
{
$connection = new Connection(null);
$host = (string) $connection->getConnection();
$this->assertEquals('localhost:27017', $host);
}

public function testDatabaseConfig()
{
$connection = new Connection(array('connect' => true));
$host = (string) $connection->getConnection();
$this->assertEquals('localhost:27017', $host);
}

public function testListDatabases()
{
$list = $this->connection->listDatabases();

$this->assertInternalType('array', $list);
$this->assertContains('admin', $list);

$list = $this->connection->listDatabases(true);
$this->assertInternalType('array', $list);
}

public function testGetMongoObject()
{
$mongo = $this->connection->getConnection();

$this->assertInstanceOf('MongoClient', $mongo);
}


public function testDropUnknownDatabase()
{
$result = $this->connection->dropDatabase('_unknown_');

$this->assertTrue($result);
}


public function testDropKnownDatabase()
{
$mongo = $this->connection->getConnection();
$mongo->demo->users->insert(array('test' => true));

$result = $this->connection->dropDatabase('demo');

$this->assertTrue($result);
}


public function testGetDatabase()
{
$database = $this->connection->database('my_db');
$this->assertInstanceOf('League\Monga\Database', $database);
}


public function testGetMongoDatabase()
{
$database = $this->connection->database('my_db', false);
$this->assertInstanceOf('MongoDB', $database);
}


public function testGetConnection()
{
$mongo = $this->connection->getConnection();
$this->assertInstanceOf('MongoClient', $mongo);
}


public function testReplaceConnection()
{
$original = $this->connection->getConnection();
$new = new MongoClient();
$original_hash = spl_object_hash($original);
$new_hash = spl_object_hash($new);
$this->connection->setConnection($new);
$get_hash = spl_object_hash($this->connection->getConnection());
$this->assertEquals($get_hash, $new_hash);
$this->assertNotEquals($get_hash, $original_hash);
$this->connection->setConnection($original);
}
}
98 changes: 48 additions & 50 deletions tests/CursorTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,66 +4,64 @@

class CursorTests extends PHPUnit_Framework_TestCase
{
public function testCursor()
{
$database = Monga::connection()
->database('__database__');
public function testCursor()
{
$database = Monga::connection()
->database('__database__');

$collection = $database->collection('_collection');
$collection->drop();
$values = array(
array('name' => 'Bill'),
array('name' => 'Frank'),
array('name' => 'George'),
);
$collection = $database->collection('_collection');
$collection->drop();
$values = array(
array('name' => 'Bill'),
array('name' => 'Frank'),
array('name' => 'George'),
);

$ids = $collection->insert($values);
$ids = $collection->insert($values);

foreach($values as $index => &$row)
{
$row['_id'] = $ids[$index];
}
foreach($values as $index => &$row) {
$row['_id'] = $ids[$index];
}

$cursor = $collection->find(function($query){
$query->orderBy('name', 'asc');
});
$asArray = array_values($cursor->toArray());
$oldCollection = $cursor->getCollection();
$mongocursor = $cursor->getCursor();
$this->assertInstanceOf('MongoCursor', $mongocursor);
$this->assertEquals(3, $cursor->count());
$this->assertInstanceOf('League\Monga\Collection', $oldCollection);
$cursor = $collection->find(function ($query) {
$query->orderBy('name', 'asc');
});
$asArray = array_values($cursor->toArray());
$oldCollection = $cursor->getCollection();
$mongocursor = $cursor->getCursor();
$this->assertInstanceOf('MongoCursor', $mongocursor);
$this->assertEquals(3, $cursor->count());
$this->assertInstanceOf('League\Monga\Collection', $oldCollection);

foreach($cursor as $row)
{
$this->assertInternalType('array', $row);
}
foreach($cursor as $row) {
$this->assertInternalType('array', $row);
}

$newCollection = $database->collection('_new_collection_');
$newCollection = $database->collection('_new_collection_');

$this->assertEquals($values, $asArray);
$this->assertInternalType('array', $asArray);
$this->assertContainsOnly('array', $asArray);
$this->assertEquals($values, $asArray);
$this->assertInternalType('array', $asArray);
$this->assertContainsOnly('array', $asArray);

$refs = $cursor->toRefArray();
$this->assertInternalType('array', $refs);
$this->assertContainsOnly('array', $refs);
$this->assertInternalType('array', $cursor->explain());
$this->assertInstanceOf('League\Monga\Cursor', $cursor->partial(false));
$collection->drop();
}
$refs = $cursor->toRefArray();
$this->assertInternalType('array', $refs);
$this->assertContainsOnly('array', $refs);
$this->assertInternalType('array', $cursor->explain());
$this->assertInstanceOf('League\Monga\Cursor', $cursor->partial(false));
$collection->drop();
}

/**
/**
* @expectedException BadMethodCallException
*/
public function testBadMethodCall()
{
$mock = $this->getMockBuilder('MongoCursor')
->disableOriginalConstructor()
->getMock();
public function testBadMethodCall()
{
$mock = $this->getMockBuilder('MongoCursor')
->disableOriginalConstructor()
->getMock();

$cursor = new League\Monga\Cursor($mock);
$cursor = new League\Monga\Cursor($mock);

$cursor->badMethodCall();
}
}
$cursor->badMethodCall();
}
}
Loading

0 comments on commit 4ee56d0

Please sign in to comment.