Skip to content
This repository has been archived by the owner on Jul 11, 2024. It is now read-only.

Commit

Permalink
converted the whole project to namespaced PHP
Browse files Browse the repository at this point in the history
  • Loading branch information
a-musing-moose committed Apr 19, 2011
1 parent 8d5b3b9 commit 380d4cf
Show file tree
Hide file tree
Showing 56 changed files with 598 additions and 629 deletions.
4 changes: 2 additions & 2 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

<fileset dir="integration-tests" id="integration-tests">
<include name="**/Test*.php" />
<exclude name="MongoUnit/*" />
<exclude name="mongoUnit/*" />
<exclude name="IntegrationsTests.php" />
</fileset>

<fileset dir="src/Morph" id="classes">
<fileset dir="src/morph" id="classes">
<include name="**/*.php" />
</fileset>

Expand Down
8 changes: 4 additions & 4 deletions integration-tests/TestComposeMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@
*/

require_once dirname(__FILE__).'/../Morph.phar';
require_once dirname(__FILE__).'/MongoUnit/TestCase.php';
require_once dirname(__FILE__).'/mongoUnit/TestCase.php';
require_once dirname(__FILE__).'/test-objects/ComposeManyParent.php';
require_once dirname(__FILE__).'/test-objects/Child.php';

/**
* @package Morph
*/
class TestComposeMany extends MongoUnit_TestCase
class TestComposeMany extends \mongoUnit\TestCase
{

public function setup()
{
parent::setUp();
Morph_Storage::init($this->getDatabase());
\morph\Storage::init($this->getDatabase());
}

public function tearDown()
{
parent::tearDown();
Morph_Storage::deInit();
\morph\Storage::deInit();
}

public function testStoresParentAndChild()
Expand Down
8 changes: 4 additions & 4 deletions integration-tests/TestComposeOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@
*/

require_once dirname(__FILE__).'/../Morph.phar';
require_once dirname(__FILE__).'/MongoUnit/TestCase.php';
require_once dirname(__FILE__).'/mongoUnit/TestCase.php';
require_once dirname(__FILE__).'/test-objects/ComposeOneParent.php';
require_once dirname(__FILE__).'/test-objects/Child.php';

/**
* @package Morph
*/
class TestComposeOne extends MongoUnit_TestCase
class TestComposeOne extends \mongoUnit\TestCase
{

public function setup()
{
parent::setup();
Morph_Storage::init($this->getDatabase());
\morph\Storage::init($this->getDatabase());
}

public function tearDown()
{
parent::tearDown();
Morph_Storage::deInit();
\morph\Storage::deInit();
}

public function testStoresParentAndChild()
Expand Down
12 changes: 6 additions & 6 deletions integration-tests/TestFileProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@
*/

require_once dirname(__FILE__).'/../Morph.phar';
require_once dirname(__FILE__).'/MongoUnit/TestCase.php';
require_once dirname(__FILE__).'/mongoUnit/TestCase.php';
require_once dirname(__FILE__).'/test-objects/User.php';

/**
* @package Morph
*/
class TestFileProperty extends MongoUnit_TestCase
class TestFileProperty extends \mongoUnit\TestCase
{

public function setup()
{
parent::setup();
Morph_Storage::init($this->getDatabase());
\morph\Storage::init($this->getDatabase());
}

public function tearDown()
{
parent::tearDown();
Morph_Storage::deInit();
\morph\Storage::deInit();
unlink('test.png');
}

Expand All @@ -38,8 +38,8 @@ public function testStoresUserAndFile()
$this->assertDocumentExists('User', $user->id());
$user->Avatar->write("test.png");
$this->assertFileExists('test.png');
$originalFileHash = md5_file(dirname(__FILE__).'/fixtures/flask.png');
$retrievedFileHash = md5_file('test.png');
$originalFileHash = \md5_file(dirname(__FILE__).'/fixtures/flask.png');
$retrievedFileHash = \md5_file('test.png');
$this->assertEquals($originalFileHash, $retrievedFileHash);
}

Expand Down
8 changes: 4 additions & 4 deletions integration-tests/TestHasMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@
*/

require_once dirname(__FILE__).'/../Morph.phar';
require_once dirname(__FILE__).'/MongoUnit/TestCase.php';
require_once dirname(__FILE__).'/mongoUnit/TestCase.php';
require_once dirname(__FILE__).'/test-objects/HasManyParent.php';
require_once dirname(__FILE__).'/test-objects/Child.php';

/**
* @package Morph
*/
class TestHasMany extends MongoUnit_TestCase
class TestHasMany extends \mongoUnit\TestCase
{

public function setup()
{
parent::setup();
Morph_Storage::init($this->getDatabase());
\morph\Storage::init($this->getDatabase());
}

public function tearDown()
{
parent::tearDown();
Morph_Storage::deInit();
\morph\Storage::deInit();
}

public function testStoresParentAndChildren()
Expand Down
8 changes: 4 additions & 4 deletions integration-tests/TestHasOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@
*/

require_once dirname(__FILE__).'/../Morph.phar';
require_once dirname(__FILE__).'/MongoUnit/TestCase.php';
require_once dirname(__FILE__).'/mongoUnit/TestCase.php';
require_once dirname(__FILE__).'/test-objects/HasOneParent.php';
require_once dirname(__FILE__).'/test-objects/Child.php';

/**
* @package Morph
*/
class TestHasOne extends MongoUnit_TestCase
class TestHasOne extends \mongoUnit\TestCase
{

public function setup()
{
parent::setup();
Morph_Storage::init($this->getDatabase());
\morph\Storage::init($this->getDatabase());
}

public function tearDown()
{
parent::tearDown();
Morph_Storage::deInit();
\morph\Storage::deInit();
}

public function testStoresParentAndChild()
Expand Down
22 changes: 11 additions & 11 deletions integration-tests/TestQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,33 @@
*/

require_once dirname(__FILE__).'/../Morph.phar';
require_once dirname(__FILE__).'/MongoUnit/TestCase.php';
require_once dirname(__FILE__).'/mongoUnit/TestCase.php';
require_once dirname(__FILE__).'/test-objects/Child.php';

/**
* @package Morph
*/
class TestQuery extends MongoUnit_TestCase
class TestQuery extends \mongoUnit\TestCase
{

public function setup()
{
parent::setup();
Morph_Storage::init($this->getDatabase());
\morph\Storage::init($this->getDatabase());
//load data from file to query against
$this->loadJsonFileDatasetIntoCollection('Child', dirname(__FILE__). '/fixtures/children.json');
}

public function tearDown()
{
parent::tearDown();
Morph_Storage::deInit();
\morph\Storage::deInit();
}

public function testCanFindByValue()
{
$child = new Child();
$query = new Morph_Query();
$query = new \morph\Query();
$query->property('Name')->equals('a_musing_moose');
$results = $child->findByQuery($query);
$this->assertEquals(1, $results->totalCount());
Expand All @@ -41,7 +41,7 @@ public function testCanFindByValue()
public function testCanFindByRegex()
{
$child = new Child();
$query = new Morph_Query();
$query = new \morph\Query();
$query->property('Name')->regex('/.*moose.*/i');
$results = $child->findByQuery($query);
$this->assertEquals(4, $results->totalCount());
Expand All @@ -50,7 +50,7 @@ public function testCanFindByRegex()
public function testCanFindByLike()
{
$child = new Child();
$query = new Morph_Query();
$query = new \morph\Query();
$query->property('Name')->like('moose');
$results = $child->findByQuery($query);
$this->assertEquals(4, $results->totalCount());
Expand All @@ -59,7 +59,7 @@ public function testCanFindByLike()
public function testCanFindByGreaterThan()
{
$child = new Child();
$query = new Morph_Query();
$query = new \morph\Query();
$query->property('Age')->greaterThan(22);
$results = $child->findByQuery($query);
$this->assertEquals(2, $results->totalCount());
Expand All @@ -68,7 +68,7 @@ public function testCanFindByGreaterThan()
public function testCanFindByLessThan()
{
$child = new Child();
$query = new Morph_Query();
$query = new \morph\Query();
$query->property('Age')->lessThan(22);
$results = $child->findByQuery($query);
$this->assertEquals(2, $results->totalCount());
Expand All @@ -77,7 +77,7 @@ public function testCanFindByLessThan()
public function testCanFindBetween()
{
$child = new Child();
$query = new Morph_Query();
$query = new \morph\Query();
$query->property('Age')->greaterThan(22)->lessThan(40);
$results = $child->findByQuery($query);
$this->assertEquals(1, $results->totalCount());
Expand All @@ -86,7 +86,7 @@ public function testCanFindBetween()
public function testCanFindByNotValue()
{
$child = new Child();
$query = new Morph_Query();
$query = new \morph\Query();
$query->property('Name')->notEqualTo('a_musing_moose');
$results = $child->findByQuery($query);
$this->assertEquals(3, $results->totalCount());
Expand Down
8 changes: 4 additions & 4 deletions integration-tests/TestSingleObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@
*/

require_once dirname(__FILE__).'/../Morph.phar';
require_once dirname(__FILE__).'/MongoUnit/TestCase.php';
require_once dirname(__FILE__).'/mongoUnit/TestCase.php';
require_once dirname(__FILE__).'/test-objects/Child.php';

/**
* @package Morph
*/
class TestSingleObject extends MongoUnit_TestCase
class TestSingleObject extends \mongoUnit\TestCase
{

public function setup()
{
parent::setup();
Morph_Storage::init($this->getDatabase());
\morph\Storage::init($this->getDatabase());
}

public function tearDown()
{
parent::tearDown();
Morph_Storage::deInit();
\morph\Storage::deInit();
}

public function testStoresObject()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,43 @@
* @copyright 2010 Tangent Labs
* @version SVN: $Id$
*/

namespace mongoUnit;
/**
* Loads data into a collection
*
* @package MongoUnit
*/
class MongoUnit_JsonLoader
class JsonLoader
{

private $collection;

public function __construct(MongoCollection $collection)
public function __construct(\MongoCollection $collection)
{
$this->collection = $collection;
}

public function loadFromJsonFile($filePath)
{
if (!file_exists($filePath)) {
if (!\file_exists($filePath)) {
throw new InvalidArgumentException("Could not locate $filePath");
}
$json = file_get_contents($filePath);
$json = \file_get_contents($filePath);
return $this->loadJsonFromString($json);
}

public function loadJsonFromString($json)
{
if (!$this->isValidJson($json)) {
throw new InvalidArgumentException("Invalid Json");
throw new \InvalidArgumentException("Invalid Json");
}
$data = json_decode($json, true);
$data = \json_decode($json, true);
$this->collection->drop();
return $this->collection->batchInsert($data);
}

private function isValidJson($json)
{
return (json_decode($json) !== null) ? true : false;
return (\json_decode($json) !== null) ? true : false;
}
}
Loading

0 comments on commit 380d4cf

Please sign in to comment.