Skip to content

Commit

Permalink
Merge pull request #327 from GrahamCampbell/2.1-tests
Browse files Browse the repository at this point in the history
[2.1] More Testing Improvements
  • Loading branch information
GrahamCampbell committed Sep 18, 2014

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents 3d502c5 + b2d940c commit 91f0adc
Showing 5 changed files with 57 additions and 57 deletions.
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
stopOnFailure="false"
syntaxCheck="true"
strict="true"
verbose="true">
verbose="true"
>
<testsuites>
<testsuite name="Factory Muffin Test Suite">
8 changes: 4 additions & 4 deletions tests/CustomisationTest.php
Original file line number Diff line number Diff line change
@@ -49,8 +49,8 @@ public function testCustomSaverFail()
try {
FactoryMuffin::create($model = 'SaverAndDeleterCustomisationModelStub');
} catch (SaveFailedException $e) {
$this->assertEquals("We could not save the model of type: '$model'.", $e->getMessage());
$this->assertEquals($model, $e->getModel());
$this->assertSame("We could not save the model of type: '$model'.", $e->getMessage());
$this->assertSame($model, $e->getModel());
$this->assertNull($e->getErrors());
$this->reload();
throw $e;
@@ -77,8 +77,8 @@ public function testCustomDeleterFail()
FactoryMuffin::deleteSaved();
} catch (DeletingFailedException $e) {
$exceptions = $e->getExceptions();
$this->assertEquals("We encountered 1 problem(s) while trying to delete the saved models.", $e->getMessage());
$this->assertEquals("We could not delete the model of type: '$model'.", $exceptions[0]->getMessage());
$this->assertSame("We encountered 1 problem(s) while trying to delete the saved models.", $e->getMessage());
$this->assertSame("We could not delete the model of type: '$model'.", $exceptions[0]->getMessage());
$this->reload();
throw $e;
}
24 changes: 12 additions & 12 deletions tests/DefinitionTest.php
Original file line number Diff line number Diff line change
@@ -42,8 +42,8 @@ public function testModelNotFound()
try {
FactoryMuffin::create($model = 'NotAClass');
} catch (ModelNotFoundException $e) {
$this->assertEquals("No class was defined for the model of type: '$model'.", $e->getMessage());
$this->assertEquals($model, $e->getModel());
$this->assertSame("No class was defined for the model of type: '$model'.", $e->getMessage());
$this->assertSame($model, $e->getModel());
throw $e;
}
}
@@ -68,7 +68,7 @@ public function testGroupDefineOverwrite()
$this->assertInternalType('string', $user->address);
$this->assertInternalType('string', $user->name);
$this->assertNotInternalType('boolean', $user->active);
$this->assertEquals('false', $user->active);
$this->assertSame('false', $user->active);
$this->assertContains('@', $user->email);
}

@@ -77,7 +77,7 @@ public function testGroupCallback()
$user = FactoryMuffin::create('callbackgroup:UserModelStub');

$this->assertInstanceOf('UserModelStub', $user);
$this->assertEquals('bar', $user->test);
$this->assertSame('bar', $user->test);
$this->assertInternalType('string', $user->name);
$this->assertInternalType('boolean', $user->active);
$this->assertContains('@', $user->email);
@@ -91,8 +91,8 @@ public function testShouldThrowExceptionWhenLoadingANonExistentGroup()
try {
FactoryMuffin::create('error:UserModelStub');
} catch (NoDefinedFactoryException $e) {
$this->assertEquals("No factory definition(s) were defined for the model of type: 'error:UserModelStub'.", $e->getMessage());
$this->assertEquals('error:UserModelStub', $e->getModel());
$this->assertSame("No factory definition(s) were defined for the model of type: 'error:UserModelStub'.", $e->getMessage());
$this->assertSame('error:UserModelStub', $e->getModel());
throw $e;
}
}
@@ -105,8 +105,8 @@ public function testGroupDefineNoBaseModel()
try {
FactoryMuffin::create('foo:DogModelStub');
} catch (NoDefinedFactoryException $e) {
$this->assertEquals("No factory definition(s) were defined for the model of type: 'DogModelStub'.", $e->getMessage());
$this->assertEquals('DogModelStub', $e->getModel());
$this->assertSame("No factory definition(s) were defined for the model of type: 'DogModelStub'.", $e->getMessage());
$this->assertSame('DogModelStub', $e->getModel());
throw $e;
}
}
@@ -144,14 +144,14 @@ public function testInstance()
public function testInstanceCallback()
{
$obj = FactoryMuffin::instance('ExampleCallbackStub');
$this->assertEquals('yaycalled', $obj->callback);
$this->assertSame('yaycalled', $obj->callback);
$this->assertFalse($obj->saved);
}

public function testCreateCallback()
{
$obj = FactoryMuffin::create('AnotherCallbackStub');
$this->assertEquals('hello there', $obj->foo);
$this->assertSame('hello there', $obj->foo);
$this->assertTrue($obj->saved);
}

@@ -185,8 +185,8 @@ public function testShouldThrowExceptionWhenLoadingANonExistentDirectory()
try {
FactoryMuffin::loadFactories($path = __DIR__.'/thisdirectorydoesntexist');
} catch (DirectoryNotFoundException $e) {
$this->assertEquals("The directory '$path' was not found.", $e->getMessage());
$this->assertEquals($path, $e->getPath());
$this->assertSame("The directory '$path' was not found.", $e->getMessage());
$this->assertSame($path, $e->getPath());
throw $e;
}
}
24 changes: 12 additions & 12 deletions tests/FactoryMuffinTest.php
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ public function testDefaultingToFaker()
$this->assertArrayHasKey('name', $obj->card);
$this->assertArrayHasKey('expirationDate', $obj->card);

$this->assertEquals('http://lorempixel.com/400/600/', $obj->image);
$this->assertSame('http://lorempixel.com/400/600/', $obj->image);
$this->assertNotEquals('unique::text', $obj->unique_text);
$this->assertNotEquals('optional::text', $obj->optional_text);
}
@@ -45,9 +45,9 @@ public function testGetIds()
{
$obj = FactoryMuffin::instance('IdTestModelStub');

$this->assertEquals(1, $obj->modelGetKey);
$this->assertEquals(1, $obj->modelPk);
$this->assertEquals(1, $obj->model_id);
$this->assertSame(1, $obj->modelGetKey);
$this->assertSame(1, $obj->modelPk);
$this->assertSame(1, $obj->model_id);
$this->assertNull($obj->model_null);
}

@@ -57,7 +57,7 @@ public function testShouldMakeSimpleCalls()

$expected = gmdate('Y-m-d', strtotime('+40 days'));

$this->assertEquals($expected, $obj->future);
$this->assertSame($expected, $obj->future);
}

public function testShouldPassSimpleArgumentsToCalls()
@@ -105,23 +105,23 @@ public function testShouldThrowExceptionWhenNoDefinedFactoryException()
try {
FactoryMuffin::instance($model = 'ModelWithNoFactoryClassStub');
} catch (NoDefinedFactoryException $e) {
$this->assertEquals("No factory definition(s) were defined for the model of type: '$model'.", $e->getMessage());
$this->assertEquals($model, $e->getModel());
$this->assertSame("No factory definition(s) were defined for the model of type: '$model'.", $e->getMessage());
$this->assertSame($model, $e->getModel());
throw $e;
}
}

public function testShouldAcceptClosureAsAttributeFactory()
{
$obj = FactoryMuffin::instance('MainModelStub');
$this->assertEquals('just a string', $obj->text_closure);
$this->assertSame('just a string', $obj->text_closure);
}

public function testCanCreateFromStaticMethod()
{
$obj = FactoryMuffin::instance('ModelWithStaticMethodFactory');

$this->assertEquals('just a string', $obj->string);
$this->assertSame('just a string', $obj->string);
$this->assertInstanceOf('ModelWithStaticMethodFactory', $obj->data['object']);
$this->assertFalse($obj->data['saved']);
}
@@ -134,9 +134,9 @@ public function testThrowExceptionWhenInvalidStaticMethod()
try {
FactoryMuffin::create($model = 'ModelWithMissingStaticMethod');
} catch (MethodNotFoundException $e) {
$this->assertEquals("The static method 'doesNotExist' was not found on the model of type: '$model'.", $e->getMessage());
$this->assertEquals($model, $e->getModel());
$this->assertEquals('doesNotExist', $e->getMethod());
$this->assertSame("The static method 'doesNotExist' was not found on the model of type: '$model'.", $e->getMessage());
$this->assertSame($model, $e->getModel());
$this->assertSame('doesNotExist', $e->getMethod());
throw $e;
}
}
56 changes: 28 additions & 28 deletions tests/SaveAndDeleteTest.php
Original file line number Diff line number Diff line change
@@ -41,9 +41,9 @@ public function testShouldThrowExceptionAfterSaveMethodRename()
try {
FactoryMuffin::create($model = 'ModelThatWillSaveStub');
} catch (SaveMethodNotFoundException $e) {
$this->assertEquals("The save method 'foo' was not found on the model of type: '$model'.", $e->getMessage());
$this->assertEquals($model, $e->getModel());
$this->assertEquals('foo', $e->getMethod());
$this->assertSame("The save method 'foo' was not found on the model of type: '$model'.", $e->getMessage());
$this->assertSame($model, $e->getModel());
$this->assertSame('foo', $e->getMethod());
$this->assertInstanceOf($model, $e->getObject());
$this->reload();
throw $e;
@@ -64,10 +64,10 @@ public function testShouldThrowExceptionAfterDeleteMethodRename()
FactoryMuffin::deleteSaved();
} catch (DeletingFailedException $e) {
$exceptions = $e->getExceptions();
$this->assertEquals("We encountered 1 problem(s) while trying to delete the saved models.", $e->getMessage());
$this->assertEquals("The delete method 'bar' was not found on the model of type: '$model'.", $exceptions[0]->getMessage());
$this->assertEquals($model, $exceptions[0]->getModel());
$this->assertEquals('bar', $exceptions[0]->getMethod());
$this->assertSame("We encountered 1 problem(s) while trying to delete the saved models.", $e->getMessage());
$this->assertSame("The delete method 'bar' was not found on the model of type: '$model'.", $exceptions[0]->getMessage());
$this->assertSame($model, $exceptions[0]->getModel());
$this->assertSame('bar', $exceptions[0]->getMethod());
$this->assertInstanceOf($model, $exceptions[0]->getObject());
$this->reload();
throw $e;
@@ -84,8 +84,8 @@ public function testShouldThrowExceptionOnModelSaveFailure()
try {
FactoryMuffin::create($model = 'ModelThatFailsToSaveStub');
} catch (SaveFailedException $e) {
$this->assertEquals("We could not save the model of type: '$model'.", $e->getMessage());
$this->assertEquals($model, $e->getModel());
$this->assertSame("We could not save the model of type: '$model'.", $e->getMessage());
$this->assertSame($model, $e->getModel());
$this->assertNull($e->getErrors());
throw $e;
}
@@ -101,8 +101,8 @@ public function testShouldThrowExceptionOnModelDeleteFailure()
FactoryMuffin::deleteSaved();
} catch (DeletingFailedException $e) {
$exceptions = $e->getExceptions();
$this->assertEquals("We encountered 1 problem(s) while trying to delete the saved models.", $e->getMessage());
$this->assertEquals("We could not delete the model of type: '$model'.", $exceptions[0]->getMessage());
$this->assertSame("We encountered 1 problem(s) while trying to delete the saved models.", $e->getMessage());
$this->assertSame("We could not delete the model of type: '$model'.", $exceptions[0]->getMessage());
throw $e;
}
}
@@ -117,8 +117,8 @@ public function testShouldAlsoThrowExceptionOnModelDeleteFailure()
FactoryMuffin::deleteSaved();
} catch (DeletingFailedException $e) {
$exceptions = $e->getExceptions();
$this->assertEquals("We encountered 1 problem(s) while trying to delete the saved models.", $e->getMessage());
$this->assertEquals("OH NOES!", $exceptions[0]->getMessage());
$this->assertSame("We encountered 1 problem(s) while trying to delete the saved models.", $e->getMessage());
$this->assertSame("OH NOES!", $exceptions[0]->getMessage());
throw $e;
}
}
@@ -131,9 +131,9 @@ public function testShouldThrowExceptionWithoutSaveMethod()
try {
FactoryMuffin::create($model = 'ModelWithNoSaveMethodStub');
} catch (SaveMethodNotFoundException $e) {
$this->assertEquals("The save method 'save' was not found on the model of type: '$model'.", $e->getMessage());
$this->assertEquals($model, $e->getModel());
$this->assertEquals('save', $e->getMethod());
$this->assertSame("The save method 'save' was not found on the model of type: '$model'.", $e->getMessage());
$this->assertSame($model, $e->getModel());
$this->assertSame('save', $e->getMethod());
$this->assertInstanceOf($model, $e->getObject());
throw $e;
}
@@ -149,10 +149,10 @@ public function testShouldThrowExceptionWithoutDeleteMethod()
FactoryMuffin::deleteSaved();
} catch (DeletingFailedException $e) {
$exceptions = $e->getExceptions();
$this->assertEquals("We encountered 1 problem(s) while trying to delete the saved models.", $e->getMessage());
$this->assertEquals("The delete method 'delete' was not found on the model of type: '$model'.", $exceptions[0]->getMessage());
$this->assertEquals($model, $exceptions[0]->getModel());
$this->assertEquals('delete', $exceptions[0]->getMethod());
$this->assertSame("We encountered 1 problem(s) while trying to delete the saved models.", $e->getMessage());
$this->assertSame("The delete method 'delete' was not found on the model of type: '$model'.", $exceptions[0]->getMessage());
$this->assertSame($model, $exceptions[0]->getModel());
$this->assertSame('delete', $exceptions[0]->getMethod());
$this->assertInstanceOf($model, $exceptions[0]->getObject());
throw $e;
}
@@ -166,9 +166,9 @@ public function testShouldThrowExceptionWithValidationErrors()
try {
FactoryMuffin::create($model = 'ModelWithValidationErrorsStub');
} catch (SaveFailedException $e) {
$this->assertEquals("Failed to save. We could not save the model of type: '$model'.", $e->getMessage());
$this->assertEquals($model, $e->getModel());
$this->assertEquals('Failed to save.', $e->getErrors());
$this->assertSame("Failed to save. We could not save the model of type: '$model'.", $e->getMessage());
$this->assertSame($model, $e->getModel());
$this->assertSame('Failed to save.', $e->getErrors());
throw $e;
}
}
@@ -184,11 +184,11 @@ public function testShouldThrowMultipleDeletionExceptions()
FactoryMuffin::deleteSaved();
} catch (DeletingFailedException $e) {
$exceptions = $e->getExceptions();
$this->assertEquals("We encountered 2 problem(s) while trying to delete the saved models.", $e->getMessage());
$this->assertEquals("OH NOES!", $exceptions[0]->getMessage());
$this->assertEquals("The delete method 'delete' was not found on the model of type: '$model'.", $exceptions[1]->getMessage());
$this->assertEquals($model, $exceptions[1]->getModel());
$this->assertEquals('delete', $exceptions[1]->getMethod());
$this->assertSame("We encountered 2 problem(s) while trying to delete the saved models.", $e->getMessage());
$this->assertSame("OH NOES!", $exceptions[0]->getMessage());
$this->assertSame("The delete method 'delete' was not found on the model of type: '$model'.", $exceptions[1]->getMessage());
$this->assertSame($model, $exceptions[1]->getModel());
$this->assertSame('delete', $exceptions[1]->getMethod());
$this->assertInstanceOf($model, $exceptions[1]->getObject());
$this->assertInternalType('array', $e->getExceptions());
$this->assertCount(2, $e->getExceptions());

0 comments on commit 91f0adc

Please sign in to comment.