Skip to content

Commit

Permalink
CS fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamCampbell committed Aug 27, 2014
1 parent 14cea41 commit 9e29d00
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 123 deletions.
6 changes: 3 additions & 3 deletions src/Generators/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ public static function detect($kind, $object = null, $faker = null)
return new Closure($kind, $object, $faker);
}

$class = __NAMESPACE__ . '\\Generic';
$class = __NAMESPACE__.'\\Generic';
foreach (self::$generators as $generator) {
if (substr($kind, 0, strlen($generator)) === $generator) {
$class = __NAMESPACE__ . '\\' . ucfirst($generator);
$class = __NAMESPACE__.'\\'.ucfirst($generator);
break;
}
}
Expand Down Expand Up @@ -128,7 +128,7 @@ protected function getGenerator()
protected function getGeneratorWithoutPrefix()
{
if ($prefix = $this->getPrefix()) {
return str_replace($prefix . ':', '', $this->getGenerator());
return str_replace($prefix.':', '', $this->getGenerator());
}

return $this->getGenerator();
Expand Down
2 changes: 1 addition & 1 deletion tests/AbstractTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ abstract class AbstractTestCase extends PHPUnit_Framework_TestCase
{
public static function setupBeforeClass()
{
FactoryMuffin::setFakerLocale('en_GB')->loadFactories(__DIR__ . '/factories');
FactoryMuffin::setFakerLocale('en_GB')->loadFactories(__DIR__.'/factories');
}

public static function tearDownAfterClass()
Expand Down
6 changes: 3 additions & 3 deletions tests/DefinitionTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

use League\FactoryMuffin\Facade as FactoryMuffin;
use League\FactoryMuffin\Exceptions\DirectoryNotFoundException;
use League\FactoryMuffin\Facade as FactoryMuffin;

/**
* @group definition
Expand Down Expand Up @@ -80,7 +80,7 @@ public function testFactoryLoading()
{
$count = count(get_included_files());

$return = FactoryMuffin::loadFactories(__DIR__ . '/stubs');
$return = FactoryMuffin::loadFactories(__DIR__.'/stubs');

$this->assertSame(1, count(get_included_files()) - $count);
$this->assertInstanceOf('League\FactoryMuffin\Factory', $return);
Expand All @@ -92,7 +92,7 @@ public function testFactoryLoading()
public function testShouldThrowExceptionWhenLoadingANonexistentDirectory()
{
try {
FactoryMuffin::loadFactories($path = __DIR__ . '/thisdirectorydoesntexist');
FactoryMuffin::loadFactories($path = __DIR__.'/thisdirectorydoesntexist');
} catch (DirectoryNotFoundException $e) {
$this->assertEquals("The directory '$path' was not found.", $e->getMessage());
$this->assertEquals($path, $e->getPath());
Expand Down
229 changes: 114 additions & 115 deletions tests/EloquentTest.php
Original file line number Diff line number Diff line change
@@ -1,116 +1,115 @@
<?php

use Illuminate\Database\Capsule\Manager as DB;
use Illuminate\Database\Eloquent\Model as Eloquent;
use League\FactoryMuffin\Facade as FactoryMuffin;

/**
* @group eloquent
*/
class EloquentTest extends AbstractTestCase
{
public static function setupBeforeClass()
{
$db = new DB();

$db->addConnection(array(
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => ''
));

$db->setAsGlobal();
$db->bootEloquent();

$db->schema()->create('users', function ($table) {
$table->increments('id');
$table->string('name');
$table->string('email');
$table->timestamps();
});

$db->schema()->create('cats', function ($table) {
$table->increments('id');
$table->string('name');
$table->integer('user_id');
});

parent::setupBeforeClass();

FactoryMuffin::seed(5, 'User');
FactoryMuffin::seed(50, 'Cat');
}

public function testNumberOfCats()
{
$cats = array();
foreach (User::all() as $user) {
foreach ($user->cats as $cat)
{
$cats[] = $cat;
}
}

$this->assertCount(50, $cats);
$this->assertInstanceOf('Cat', $cats[0]);
}

public function testNumberOfCatOwners()
{
$users = array();
foreach (Cat::all() as $cat) {
$users[] = $cat->user;
}

$this->assertCount(50, $users);
$this->assertCount(5, array_unique($users));
$this->assertInstanceOf('User', $users[0]);
}

public function testUserProperties()
{
$user = User::first();

$this->assertGreaterThan(1, strlen($user->name));
$this->assertGreaterThan(5, strlen($user->email));
$this->assertContains('@', $user->email);
$this->assertContains('.', $user->email);
$this->assertInstanceOf('DateTime', $user->created_at);
$this->assertInstanceOf('DateTime', $user->updated_at);
$this->assertSame((string) $user->created_at, (string) $user->updated_at);
$this->assertFalse($user->xyz == true);
}

public function testCatProperties()
{
$cat = Cat::first();

$this->assertGreaterThan(1, strlen($cat->name));
$this->assertTrue($cat->user_id == true);
$this->assertFalse($cat->created_at == true);
$this->assertFalse($cat->updated_at == true);
$this->assertFalse($cat->xyz == true);
}
}

class User extends Eloquent
{
public $table = 'users';

public function cats()
{
return $this->hasMany('Cat');
}
}

class Cat extends Eloquent
{
public $timestamps = false;

public $table = 'cats';

public function user()
{
return $this->belongsTo('User');
}
<?php

use Illuminate\Database\Capsule\Manager as DB;
use Illuminate\Database\Eloquent\Model as Eloquent;
use League\FactoryMuffin\Facade as FactoryMuffin;

/**
* @group eloquent
*/
class EloquentTest extends AbstractTestCase
{
public static function setupBeforeClass()
{
$db = new DB();

$db->addConnection(array(
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => ''
));

$db->setAsGlobal();
$db->bootEloquent();

$db->schema()->create('users', function ($table) {
$table->increments('id');
$table->string('name');
$table->string('email');
$table->timestamps();
});

$db->schema()->create('cats', function ($table) {
$table->increments('id');
$table->string('name');
$table->integer('user_id');
});

parent::setupBeforeClass();

FactoryMuffin::seed(5, 'User');
FactoryMuffin::seed(50, 'Cat');
}

public function testNumberOfCats()
{
$cats = array();
foreach (User::all() as $user) {
foreach ($user->cats as $cat) {
$cats[] = $cat;
}
}

$this->assertCount(50, $cats);
$this->assertInstanceOf('Cat', $cats[0]);
}

public function testNumberOfCatOwners()
{
$users = array();
foreach (Cat::all() as $cat) {
$users[] = $cat->user;
}

$this->assertCount(50, $users);
$this->assertCount(5, array_unique($users));
$this->assertInstanceOf('User', $users[0]);
}

public function testUserProperties()
{
$user = User::first();

$this->assertGreaterThan(1, strlen($user->name));
$this->assertGreaterThan(5, strlen($user->email));
$this->assertContains('@', $user->email);
$this->assertContains('.', $user->email);
$this->assertInstanceOf('DateTime', $user->created_at);
$this->assertInstanceOf('DateTime', $user->updated_at);
$this->assertSame((string) $user->created_at, (string) $user->updated_at);
$this->assertFalse($user->xyz == true);
}

public function testCatProperties()
{
$cat = Cat::first();

$this->assertGreaterThan(1, strlen($cat->name));
$this->assertTrue($cat->user_id == true);
$this->assertFalse($cat->created_at == true);
$this->assertFalse($cat->updated_at == true);
$this->assertFalse($cat->xyz == true);
}
}

class User extends Eloquent
{
public $table = 'users';

public function cats()
{
return $this->hasMany('Cat');
}
}

class Cat extends Eloquent
{
public $timestamps = false;

public $table = 'cats';

public function user()
{
return $this->belongsTo('User');
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/FactoryMuffinTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

use League\FactoryMuffin\Exceptions\NoDefinedFactoryException;
use League\FactoryMuffin\Exceptions\MethodNotFoundException;
use League\FactoryMuffin\Exceptions\NoDefinedFactoryException;
use League\FactoryMuffin\Facade as FactoryMuffin;

/**
Expand Down

0 comments on commit 9e29d00

Please sign in to comment.