Commit 34c7b975 authored by Jeremy Mikola's avatar Jeremy Mikola

Remove Faker test dependency

parent cfcf48f1
...@@ -12,9 +12,6 @@ ...@@ -12,9 +12,6 @@
"require": { "require": {
"ext-mongodb": ">=0.5.1" "ext-mongodb": ">=0.5.1"
}, },
"require-dev": {
"fzaninotto/faker": "~1.0"
},
"autoload": { "autoload": {
"psr-4": { "MongoDB\\": "src/" } "psr-4": { "MongoDB\\": "src/" }
}, },
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
namespace MongoDB\Tests\Collection; namespace MongoDB\Tests\Collection;
use MongoDB\Tests\FixtureGenerator;
/** /**
* Functional tests for the Collection class. * Functional tests for the Collection class.
*/ */
...@@ -18,34 +16,4 @@ class CollectionFunctionalTest extends FunctionalTestCase ...@@ -18,34 +16,4 @@ class CollectionFunctionalTest extends FunctionalTestCase
$this->assertCommandSucceeded($commandResult); $this->assertCommandSucceeded($commandResult);
$this->assertCollectionCount($this->getNamespace(), 0); $this->assertCollectionCount($this->getNamespace(), 0);
} }
function testInsertAndRetrieve()
{
$generator = new FixtureGenerator();
for ($i = 0; $i < 10; $i++) {
$user = $generator->createUser();
$result = $this->collection->insertOne($user);
$this->assertInstanceOf('MongoDB\InsertOneResult', $result);
$this->assertInstanceOf('BSON\ObjectId', $result->getInsertedId());
$this->assertEquals(24, strlen($result->getInsertedId()));
$user["_id"] = $result->getInsertedId();
$document = $this->collection->findOne(array("_id" => $result->getInsertedId()));
$this->assertEquals($document, $user, "The inserted and returned objects are the same");
}
$this->assertEquals(10, $i);
$query = array("firstName" => "Ransom");
$count = $this->collection->count($query);
$this->assertEquals(1, $count);
$cursor = $this->collection->find($query);
$this->assertInstanceOf('MongoDB\Driver\Cursor', $cursor);
foreach($cursor as $n => $person) {
$this->assertInternalType("array", $person);
}
$this->assertEquals(0, $n);
}
} }
<?php
namespace MongoDB\Tests;
use Faker\Factory;
class FixtureGenerator
{
private $faker;
public function __construct()
{
$this->faker = Factory::create();
$this->faker->seed(1234);
}
public function createUser()
{
return array(
"username" => $this->faker->unique()->userName,
"password" => $this->faker->sha256,
"email" => $this->faker->unique()->safeEmail,
"firstName" => $this->faker->firstName,
"lastName" => $this->faker->lastName,
"phoneNumber" => $this->faker->phoneNumber,
"altPhoneNumber" => $this->faker->optional(0.1)->phoneNumber,
"company" => $this->faker->company,
"bio" => $this->faker->paragraph,
"createdAt" => $this->faker->dateTimeBetween("2008-01-01T00:00:00+0000", "2014-08-01T00:00:00+0000")->getTimestamp(),
"addresses" => array(
$this->createAddress(),
$this->createAddress(),
$this->createAddress(),
),
);
}
public function createAddress()
{
return (object) array(
"streetAddress" => $this->faker->streetAddress,
"city" => $this->faker->city,
"state" => $this->faker->state,
"postalCode" => $this->faker->postcode,
"loc" => $this->createGeoJsonPoint(),
);
}
public function createGeoJsonPoint()
{
return (object) array(
"type" => "Point",
"coordinates" => (object) array(
$this->faker->longitude,
$this->faker->latitude
),
);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment